stufflog graphql server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

78 lines
2.6 KiB

package resolvers
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
import (
"context"
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
)
func (r *projectResolver) Issues(ctx context.Context, obj *models.Project, filter *graphcore.ProjectIssueFilter) ([]*models.Issue, error) {
if filter == nil {
filter = &graphcore.ProjectIssueFilter{}
}
issues, err := r.Database.Issues().List(ctx, models.IssueFilter{
ProjectIDs: []string{obj.ID},
AssigneeIDs: filter.AssigneeIds,
Search: filter.Search,
MinStage: filter.MinStage,
MaxStage: filter.MaxStage,
Limit: filter.Limit,
})
if err != nil {
return nil, err
}
loader := loaders.IssueLoaderFromContext(ctx)
for _, issue := range issues {
loader.Prime(issue.ID, issue)
}
return issues, nil
}
func (r *projectResolver) Permissions(ctx context.Context, obj *models.Project) ([]*models.ProjectPermission, error) {
if perm, err := r.Auth.ProjectPermission(ctx, obj.ID); err != nil || !perm.CanManagePermissions() {
return nil, slerrors.PermissionDenied
}
return r.Database.Projects().ListPermissions(ctx, *obj)
}
func (r *projectResolver) UserPermissions(ctx context.Context, obj *models.Project) (*models.ProjectPermission, error) {
return r.Auth.ProjectPermission(ctx, obj.ID)
}
func (r *projectResolver) Statuses(ctx context.Context, obj *models.Project, filter *models.ProjectStatusFilter) ([]*models.ProjectStatus, error) {
if filter == nil {
filter = &models.ProjectStatusFilter{}
}
filter.ProjectID = &obj.ID
return r.Database.ProjectStatuses().List(ctx, *filter)
}
func (r *projectResolver) Activities(ctx context.Context, obj *models.Project) ([]*models.Activity, error) {
return r.Database.Activities().List(ctx, models.ActivityFilter{ProjectIDs: []string{obj.ID}})
}
func (r *projectPermissionResolver) User(ctx context.Context, obj *models.ProjectPermission) (*models.User, error) {
return loaders.UserLoaderFromContext(ctx).Load(obj.UserID)
}
// Project returns graphcore.ProjectResolver implementation.
func (r *Resolver) Project() graphcore.ProjectResolver { return &projectResolver{r} }
// ProjectPermission returns graphcore.ProjectPermissionResolver implementation.
func (r *Resolver) ProjectPermission() graphcore.ProjectPermissionResolver {
return &projectPermissionResolver{r}
}
type projectResolver struct{ *Resolver }
type projectPermissionResolver struct{ *Resolver }