2024-12-14 12:06:49 +00:00
|
|
|
package service_internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
internal "git.itzana.me/strafesnet/maps-service/pkg/internal"
|
|
|
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
|
|
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
|
|
)
|
|
|
|
|
2024-12-18 02:26:07 +00:00
|
|
|
// UpdateSubmissionModel implements patchSubmissionModel operation.
|
|
|
|
//
|
|
|
|
// Update model following role restrictions.
|
|
|
|
//
|
|
|
|
// POST /submissions/{SubmissionID}/model
|
|
|
|
func (svc *Service) UpdateSubmissionModel(ctx context.Context, params internal.UpdateSubmissionModelParams) error {
|
|
|
|
// check if Status is ChangesRequested|Submitted|UnderConstruction
|
|
|
|
pmap := datastore.Optional()
|
|
|
|
pmap.AddNotNil("asset_id", params.ModelID)
|
|
|
|
pmap.AddNotNil("asset_version", params.VersionID)
|
|
|
|
//always reset completed when model changes
|
|
|
|
pmap.Add("completed", false)
|
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusValidating}, pmap)
|
|
|
|
}
|
|
|
|
|
2024-12-14 12:06:49 +00:00
|
|
|
// ActionSubmissionValidate invokes actionSubmissionValidate operation.
|
|
|
|
//
|
|
|
|
// Role Validator changes status from Validating -> Validated.
|
|
|
|
//
|
2024-12-18 02:22:40 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/validator-validated
|
2024-12-14 12:06:49 +00:00
|
|
|
func (svc *Service) ActionSubmissionValidated(ctx context.Context, params internal.ActionSubmissionValidatedParams) error {
|
2024-12-18 02:22:40 +00:00
|
|
|
println("[ActionSubmissionValidated] Implicit Validator permission granted!")
|
2024-12-14 12:06:49 +00:00
|
|
|
|
|
|
|
// transaction
|
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id", model.StatusValidated)
|
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusValidating}, smap)
|
|
|
|
}
|
|
|
|
|
2024-12-18 02:22:53 +00:00
|
|
|
// ActionSubmissionAccepted implements actionSubmissionAccepted operation.
|
|
|
|
//
|
|
|
|
// (Internal endpoint) Role Validator changes status from Validating -> Accepted.
|
|
|
|
//
|
|
|
|
// POST /submissions/{SubmissionID}/status/validator-failed
|
|
|
|
func (svc *Service) ActionSubmissionAccepted(ctx context.Context, params internal.ActionSubmissionAcceptedParams) error {
|
|
|
|
println("[ActionSubmissionAccepted] Implicit Validator permission granted!")
|
|
|
|
|
|
|
|
// transaction
|
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id", model.StatusAccepted)
|
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusValidating}, smap)
|
|
|
|
}
|
|
|
|
|
2024-12-14 12:06:49 +00:00
|
|
|
// ActionSubmissionReleased implements actionSubmissionReleased operation.
|
|
|
|
//
|
|
|
|
// (Internal endpoint) Role Releaser changes status from Uploaded -> Released.
|
|
|
|
//
|
|
|
|
// POST /submissions/{SubmissionID}/status/releaser-released
|
|
|
|
func (svc *Service) ActionSubmissionReleased(ctx context.Context, params internal.ActionSubmissionReleasedParams) error {
|
|
|
|
println("[ActionSubmissionReleased] Implicit Validator permission granted!")
|
|
|
|
|
|
|
|
// transaction
|
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id", model.StatusReleased)
|
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusUploaded}, smap)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ActionSubmissionUploaded implements actionSubmissionUploaded operation.
|
|
|
|
//
|
|
|
|
// (Internal endpoint) Role Validator changes status from Uploading -> Uploaded.
|
|
|
|
//
|
|
|
|
// POST /submissions/{SubmissionID}/status/validator-uploaded
|
|
|
|
func (svc *Service) ActionSubmissionUploaded(ctx context.Context, params internal.ActionSubmissionUploadedParams) error {
|
|
|
|
println("[ActionSubmissionUploaded] Implicit Validator permission granted!")
|
|
|
|
|
|
|
|
// transaction
|
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id", model.StatusUploaded)
|
2024-12-15 08:09:37 +00:00
|
|
|
if params.TargetAssetID.IsSet() {
|
|
|
|
smap.AddNotNil("target_asset_id", params.TargetAssetID.Value)
|
|
|
|
}
|
2024-12-14 12:06:49 +00:00
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusUploading}, smap)
|
|
|
|
}
|