submissions: trigger validator to create submissions & mapfixes

This commit is contained in:
Quaternions 2025-04-02 14:13:21 -07:00
parent 4e8c1eddd0
commit e1a4cf1713
Signed by: Quaternions
GPG Key ID: D0DF5964F79AC131
3 changed files with 51 additions and 87 deletions

@ -5,6 +5,18 @@ package model
// Requests are sent from maps-service to validator
type CreateSubmissionRequest struct {
// operation_id is passed back in the response message
OperationID int32
ModelID int64
}
type CreateMapfixRequest struct {
OperationID int32
ModelID int64
TargetAssetID int64
}
type ValidateSubmissionRequest struct {
// submission_id is passed back in the response message
SubmissionID int64

@ -19,16 +19,6 @@ var(
model.MapfixStatusSubmitted,
model.MapfixStatusUnderConstruction,
}
// prevent two mapfixes with same asset id
ActiveMapfixStatuses = []model.MapfixStatus{
model.MapfixStatusUploading,
model.MapfixStatusValidated,
model.MapfixStatusValidating,
model.MapfixStatusAccepted,
model.MapfixStatusChangesRequested,
model.MapfixStatusSubmitted,
model.MapfixStatusUnderConstruction,
}
// limit mapfixes in the pipeline to one per target map
ActiveAcceptedMapfixStatuses = []model.MapfixStatus{
model.MapfixStatusUploading,
@ -40,13 +30,12 @@ var(
var (
ErrCreationPhaseMapfixesLimit = errors.New("Active mapfixes limited to 20")
ErrActiveMapfixSameAssetID = errors.New("There is an active mapfix with the same AssetID")
ErrActiveMapfixSameTargetAssetID = errors.New("There is an active mapfix with the same TargetAssetID")
ErrAcceptOwnMapfix = fmt.Errorf("%w: You cannot accept your own mapfix as the submitter", ErrPermissionDenied)
)
// POST /mapfixes
func (svc *Service) CreateMapfix(ctx context.Context, request *api.MapfixCreate) (*api.ID, error) {
func (svc *Service) CreateMapfix(ctx context.Context, request *api.MapfixTriggerCreate) (*api.OperationID, error) {
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
if !ok {
return nil, ErrUserInfo
@ -74,42 +63,29 @@ func (svc *Service) CreateMapfix(ctx context.Context, request *api.MapfixCreate)
return nil, ErrCreationPhaseMapfixesLimit
}
}
// Check if an active mapfix with the same asset id exists
{
filter := datastore.Optional()
filter.Add("asset_id", request.AssetID)
filter.Add("asset_version", request.AssetVersion)
filter.Add("status_id", ActiveMapfixStatuses)
active_mapfixes, err := svc.DB.Mapfixes().List(ctx, filter, model.Page{
Number: 1,
Size: 1,
},datastore.ListSortDisabled)
if err != nil {
return nil, err
}
if len(active_mapfixes) != 0{
return nil, ErrActiveMapfixSameAssetID
}
}
mapfix, err := svc.DB.Mapfixes().Create(ctx, model.Mapfix{
ID: 0,
DisplayName: request.DisplayName,
Creator: request.Creator,
GameID: request.GameID,
Submitter: int64(userId),
AssetID: request.AssetID,
AssetVersion: request.AssetVersion,
Completed: false,
TargetAssetID: request.TargetAssetID,
StatusID: model.MapfixStatusUnderConstruction,
operation, err := svc.DB.Operations().Create(ctx, model.Operation{
Owner: int64(userId),
StatusID: model.OperationStatusCreated,
})
if err != nil {
return nil, err
}
return &api.ID{
ID: mapfix.ID,
create_request := model.CreateMapfixRequest{
OperationID: operation.ID,
ModelID: request.AssetID,
TargetAssetID: request.TargetAssetID,
}
j, err := json.Marshal(create_request)
if err != nil {
return nil, err
}
svc.Nats.Publish("maptest.mapfixes.create", []byte(j))
return &api.OperationID{
OperationID: operation.ID,
}, nil
}

@ -20,16 +20,6 @@ var(
model.SubmissionStatusSubmitted,
model.SubmissionStatusUnderConstruction,
}
// prevent two mapfixes with same asset id
ActiveSubmissionStatuses = []model.SubmissionStatus{
model.SubmissionStatusUploading,
model.SubmissionStatusValidated,
model.SubmissionStatusValidating,
model.SubmissionStatusAccepted,
model.SubmissionStatusChangesRequested,
model.SubmissionStatusSubmitted,
model.SubmissionStatusUnderConstruction,
}
// limit mapfixes in the pipeline to one per target map
ActiveAcceptedSubmissionStatuses = []model.SubmissionStatus{
model.SubmissionStatusUploading,
@ -41,7 +31,6 @@ var(
var (
ErrCreationPhaseSubmissionsLimit = errors.New("Active submissions limited to 20")
ErrActiveSubmissionSameAssetID = errors.New("There is an active submission with the same AssetID")
ErrUploadedAssetIDAlreadyExists = errors.New("The submission UploadedAssetID is already set")
ErrReleaseInvalidStatus = errors.New("Only submissions with Uploaded status can be released")
ErrReleaseNoUploadedAssetID = errors.New("Only submissions with a UploadedAssetID can be released")
@ -49,7 +38,7 @@ var (
)
// POST /submissions
func (svc *Service) CreateSubmission(ctx context.Context, request *api.SubmissionCreate) (*api.ID, error) {
func (svc *Service) CreateSubmission(ctx context.Context, request *api.SubmissionTriggerCreate) (*api.OperationID, error) {
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
if !ok {
return nil, ErrUserInfo
@ -77,41 +66,28 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio
return nil, ErrCreationPhaseSubmissionsLimit
}
}
// Check if an active submission with the same asset id exists
{
filter := datastore.Optional()
filter.Add("asset_id", request.AssetID)
filter.Add("asset_version", request.AssetVersion)
filter.Add("status_id", ActiveSubmissionStatuses)
active_submissions, err := svc.DB.Submissions().List(ctx, filter, model.Page{
Number: 1,
Size: 1,
},datastore.ListSortDisabled)
if err != nil {
return nil, err
}
if len(active_submissions) != 0{
return nil, ErrActiveSubmissionSameAssetID
}
}
submission, err := svc.DB.Submissions().Create(ctx, model.Submission{
ID: 0,
DisplayName: request.DisplayName,
Creator: request.Creator,
GameID: request.GameID,
Submitter: int64(userId),
AssetID: request.AssetID,
AssetVersion: request.AssetVersion,
Completed: false,
StatusID: model.SubmissionStatusUnderConstruction,
operation, err := svc.DB.Operations().Create(ctx, model.Operation{
Owner: int64(userId),
StatusID: model.OperationStatusCreated,
})
if err != nil {
return nil, err
}
return &api.ID{
ID: submission.ID,
create_request := model.CreateSubmissionRequest{
OperationID: operation.ID,
ModelID: request.AssetID,
}
j, err := json.Marshal(create_request)
if err != nil {
return nil, err
}
svc.Nats.Publish("maptest.submissions.create", []byte(j))
return &api.OperationID{
OperationID: operation.ID,
}, nil
}