parent
a8ccc93dd6
commit
daceac4990
pkg
@ -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
|
||||
|
@ -46,7 +46,7 @@ var (
|
||||
)
|
||||
|
||||
// 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
|
||||
@ -57,59 +57,29 @@ func (svc *Service) CreateMapfix(ctx context.Context, request *api.MapfixCreate)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Check if user's mapfixes in the creation phase exceeds the limit
|
||||
{
|
||||
filter := datastore.Optional()
|
||||
filter.Add("submitter", int64(userId))
|
||||
filter.Add("status_id", CreationPhaseMapfixStatuses)
|
||||
creation_mapfixes, err := svc.DB.Mapfixes().List(ctx, filter, model.Page{
|
||||
Number: 1,
|
||||
Size: int32(CreationPhaseMapfixesLimit),
|
||||
},datastore.ListSortDisabled)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if CreationPhaseMapfixesLimit <= len(creation_mapfixes) {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,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
|
||||
@ -60,58 +60,28 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Check if user's submissions in the creation phase exceeds the limit
|
||||
{
|
||||
filter := datastore.Optional()
|
||||
filter.Add("submitter", int64(userId))
|
||||
filter.Add("status_id", CreationPhaseSubmissionStatuses)
|
||||
creation_submissions, err := svc.DB.Submissions().List(ctx, filter, model.Page{
|
||||
Number: 1,
|
||||
Size: int32(CreationPhaseSubmissionsLimit),
|
||||
},datastore.ListSortDisabled)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if CreationPhaseSubmissionsLimit <= len(creation_submissions) {
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user