package service import ( "context" "git.itzana.me/strafesnet/maps-service/pkg/api" ) // GetOperation implements getOperation operation. // // Get the specified operation by ID. // // GET /operations/{OperationID} func (svc *Service) GetOperation(ctx context.Context, params api.GetOperationParams) (*api.Operation, error) { userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle) if !ok { return nil, ErrUserInfo } // You must be the operation owner to read it operation, err := svc.DB.Operations().Get(ctx, params.OperationID) if err != nil { return nil, err } has_role, err := userInfo.IsSubmitter(uint64(operation.Owner)) if err != nil { return nil, err } // check if caller is operation owner if !has_role { return nil, ErrPermissionDeniedNotSubmitter } return &api.Operation{ OperationID: operation.ID, Date: operation.CreatedAt.Unix(), Owner: operation.Owner, Status: int32(operation.StatusID), StatusMessage: operation.StatusMessage, Path: operation.Path, }, nil }