From 67651633d8483e5118c3af48c84386920b392ffd Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 17 Dec 2024 18:26:07 -0800 Subject: [PATCH] submissions: UpdateSubmissionModel internal endpoint not quite duplicate code, hooray --- pkg/service/submissions.go | 2 +- pkg/service_internal/submissions.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index 22f44cc..7955131 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -127,7 +127,7 @@ func (svc *Service) SetSubmissionCompleted(ctx context.Context, params api.SetSu return err } -// PatchSubmissionModel implements patchSubmissionModel operation. +// UpdateSubmissionModel implements patchSubmissionModel operation. // // Update model following role restrictions. // diff --git a/pkg/service_internal/submissions.go b/pkg/service_internal/submissions.go index 491939d..8e46735 100644 --- a/pkg/service_internal/submissions.go +++ b/pkg/service_internal/submissions.go @@ -8,6 +8,21 @@ import ( "git.itzana.me/strafesnet/maps-service/pkg/model" ) +// 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) +} + // ActionSubmissionValidate invokes actionSubmissionValidate operation. // // Role Validator changes status from Validating -> Validated.