Change gqlgen filename_template from {name}.resolvers.go to
{name}_resolvers.go across all three APIs for consistent Go naming.
Signed-off-by: Émile Ré <emile@getprobo.com>
171 lines
6.1 KiB
Go
171 lines
6.1 KiB
Go
package console_v1
|
|
|
|
// 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.
|
|
// Code generated by github.com/99designs/gqlgen version v0.17.87
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"go.gearno.de/kit/log"
|
|
"go.probo.inc/probo/pkg/coredata"
|
|
"go.probo.inc/probo/pkg/iam"
|
|
"go.probo.inc/probo/pkg/probo"
|
|
"go.probo.inc/probo/pkg/server/api/console/v1/schema"
|
|
"go.probo.inc/probo/pkg/server/api/console/v1/types"
|
|
"go.probo.inc/probo/pkg/server/gqlutils"
|
|
"go.probo.inc/probo/pkg/validator"
|
|
)
|
|
|
|
// CreateRightsRequest is the resolver for the createRightsRequest field.
|
|
func (r *mutationResolver) CreateRightsRequest(ctx context.Context, input types.CreateRightsRequestInput) (*types.CreateRightsRequestPayload, error) {
|
|
if err := r.authorize(ctx, input.OrganizationID, probo.ActionRightsRequestCreate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
|
|
|
req := probo.CreateRightsRequestRequest{
|
|
OrganizationID: input.OrganizationID,
|
|
RequestType: &input.RequestType,
|
|
RequestState: &input.RequestState,
|
|
DataSubject: input.DataSubject,
|
|
Contact: input.Contact,
|
|
Details: input.Details,
|
|
Deadline: input.Deadline,
|
|
ActionTaken: input.ActionTaken,
|
|
}
|
|
|
|
rightsRequest, err := prb.RightsRequests.Create(ctx, &req)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
r.logger.ErrorCtx(ctx, "cannot create rights request", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.CreateRightsRequestPayload{
|
|
RightsRequestEdge: types.NewRightsRequestEdge(rightsRequest, coredata.RightsRequestOrderFieldCreatedAt),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateRightsRequest is the resolver for the updateRightsRequest field.
|
|
func (r *mutationResolver) UpdateRightsRequest(ctx context.Context, input types.UpdateRightsRequestInput) (*types.UpdateRightsRequestPayload, error) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionRightsRequestUpdate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
req := probo.UpdateRightsRequestRequest{
|
|
ID: input.ID,
|
|
RequestType: input.RequestType,
|
|
RequestState: input.RequestState,
|
|
DataSubject: gqlutils.UnwrapOmittable(input.DataSubject),
|
|
Contact: gqlutils.UnwrapOmittable(input.Contact),
|
|
Details: gqlutils.UnwrapOmittable(input.Details),
|
|
Deadline: gqlutils.UnwrapOmittable(input.Deadline),
|
|
ActionTaken: gqlutils.UnwrapOmittable(input.ActionTaken),
|
|
}
|
|
|
|
rightsRequest, err := prb.RightsRequests.Update(ctx, &req)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
r.logger.ErrorCtx(ctx, "cannot update rights request", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UpdateRightsRequestPayload{
|
|
RightsRequest: types.NewRightsRequest(rightsRequest),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteRightsRequest is the resolver for the deleteRightsRequest field.
|
|
func (r *mutationResolver) DeleteRightsRequest(ctx context.Context, input types.DeleteRightsRequestInput) (*types.DeleteRightsRequestPayload, error) {
|
|
if err := r.authorize(ctx, input.RightsRequestID, probo.ActionRightsRequestDelete); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.RightsRequestID.TenantID())
|
|
|
|
err := prb.RightsRequests.Delete(ctx, input.RightsRequestID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot delete rights request", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteRightsRequestPayload{
|
|
DeletedRightsRequestID: input.RightsRequestID,
|
|
}, nil
|
|
}
|
|
|
|
// Organization is the resolver for the organization field.
|
|
func (r *rightsRequestResolver) Organization(ctx context.Context, obj *types.RightsRequest) (*types.Organization, error) {
|
|
if err := r.authorize(ctx, obj.ID, iam.ActionOrganizationGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
rightsRequest, err := prb.RightsRequests.Get(ctx, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get rights request", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
organization, err := prb.Organizations.Get(ctx, rightsRequest.OrganizationID)
|
|
if err != nil {
|
|
if errors.Is(err, coredata.ErrResourceNotFound) {
|
|
return nil, gqlutils.NotFound(ctx, err)
|
|
}
|
|
r.logger.ErrorCtx(ctx, "cannot get organization", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewOrganization(organization), nil
|
|
}
|
|
|
|
// Permission is the resolver for the permission field.
|
|
func (r *rightsRequestResolver) Permission(ctx context.Context, obj *types.RightsRequest, action string) (bool, error) {
|
|
return r.Resolver.Permission(ctx, obj, action)
|
|
}
|
|
|
|
// TotalCount is the resolver for the totalCount field.
|
|
func (r *rightsRequestConnectionResolver) TotalCount(ctx context.Context, obj *types.RightsRequestConnection) (int, error) {
|
|
if err := r.authorize(ctx, obj.ParentID, probo.ActionRightsRequestList); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
|
|
|
switch obj.Resolver.(type) {
|
|
case *organizationResolver:
|
|
count, err := prb.RightsRequests.CountByOrganizationID(ctx, obj.ParentID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot count rights requests", log.Error(err))
|
|
return 0, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return count, nil
|
|
default:
|
|
r.logger.ErrorCtx(ctx, "unsupported resolver type for RightsRequestConnection")
|
|
return 0, gqlutils.Internal(ctx)
|
|
}
|
|
}
|
|
|
|
// RightsRequest returns schema.RightsRequestResolver implementation.
|
|
func (r *Resolver) RightsRequest() schema.RightsRequestResolver { return &rightsRequestResolver{r} }
|
|
|
|
// RightsRequestConnection returns schema.RightsRequestConnectionResolver implementation.
|
|
func (r *Resolver) RightsRequestConnection() schema.RightsRequestConnectionResolver {
|
|
return &rightsRequestConnectionResolver{r}
|
|
}
|
|
|
|
type rightsRequestResolver struct{ *Resolver }
|
|
type rightsRequestConnectionResolver struct{ *Resolver }
|