submissions: trigger validator to create submissions & mapfixes
This commit is contained in:
parent
4e8c1eddd0
commit
e1a4cf1713
pkg
@ -5,6 +5,18 @@ package model
|
|||||||
|
|
||||||
// Requests are sent from maps-service to validator
|
// 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 {
|
type ValidateSubmissionRequest struct {
|
||||||
// submission_id is passed back in the response message
|
// submission_id is passed back in the response message
|
||||||
SubmissionID int64
|
SubmissionID int64
|
||||||
|
@ -19,16 +19,6 @@ var(
|
|||||||
model.MapfixStatusSubmitted,
|
model.MapfixStatusSubmitted,
|
||||||
model.MapfixStatusUnderConstruction,
|
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
|
// limit mapfixes in the pipeline to one per target map
|
||||||
ActiveAcceptedMapfixStatuses = []model.MapfixStatus{
|
ActiveAcceptedMapfixStatuses = []model.MapfixStatus{
|
||||||
model.MapfixStatusUploading,
|
model.MapfixStatusUploading,
|
||||||
@ -40,13 +30,12 @@ var(
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ErrCreationPhaseMapfixesLimit = errors.New("Active mapfixes limited to 20")
|
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")
|
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)
|
ErrAcceptOwnMapfix = fmt.Errorf("%w: You cannot accept your own mapfix as the submitter", ErrPermissionDenied)
|
||||||
)
|
)
|
||||||
|
|
||||||
// POST /mapfixes
|
// 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)
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ErrUserInfo
|
return nil, ErrUserInfo
|
||||||
@ -74,42 +63,29 @@ func (svc *Service) CreateMapfix(ctx context.Context, request *api.MapfixCreate)
|
|||||||
return nil, ErrCreationPhaseMapfixesLimit
|
return nil, ErrCreationPhaseMapfixesLimit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
operation, err := svc.DB.Operations().Create(ctx, model.Operation{
|
||||||
// Check if an active mapfix with the same asset id exists
|
Owner: int64(userId),
|
||||||
{
|
StatusID: model.OperationStatusCreated,
|
||||||
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,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,16 +20,6 @@ var(
|
|||||||
model.SubmissionStatusSubmitted,
|
model.SubmissionStatusSubmitted,
|
||||||
model.SubmissionStatusUnderConstruction,
|
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
|
// limit mapfixes in the pipeline to one per target map
|
||||||
ActiveAcceptedSubmissionStatuses = []model.SubmissionStatus{
|
ActiveAcceptedSubmissionStatuses = []model.SubmissionStatus{
|
||||||
model.SubmissionStatusUploading,
|
model.SubmissionStatusUploading,
|
||||||
@ -41,7 +31,6 @@ var(
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ErrCreationPhaseSubmissionsLimit = errors.New("Active submissions limited to 20")
|
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")
|
ErrUploadedAssetIDAlreadyExists = errors.New("The submission UploadedAssetID is already set")
|
||||||
ErrReleaseInvalidStatus = errors.New("Only submissions with Uploaded status can be released")
|
ErrReleaseInvalidStatus = errors.New("Only submissions with Uploaded status can be released")
|
||||||
ErrReleaseNoUploadedAssetID = errors.New("Only submissions with a UploadedAssetID can be released")
|
ErrReleaseNoUploadedAssetID = errors.New("Only submissions with a UploadedAssetID can be released")
|
||||||
@ -49,7 +38,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// POST /submissions
|
// 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)
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ErrUserInfo
|
return nil, ErrUserInfo
|
||||||
@ -77,41 +66,28 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio
|
|||||||
return nil, ErrCreationPhaseSubmissionsLimit
|
return nil, ErrCreationPhaseSubmissionsLimit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
operation, err := svc.DB.Operations().Create(ctx, model.Operation{
|
||||||
// Check if an active submission with the same asset id exists
|
Owner: int64(userId),
|
||||||
{
|
StatusID: model.OperationStatusCreated,
|
||||||
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,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user