submissions: ReleaseSubmissions operation
This commit is contained in:
parent
952b77b3db
commit
952ceab014
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"git.itzana.me/strafesnet/go-grpc/maps"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
@ -33,6 +34,8 @@ 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")
|
ErrActiveSubmissionSameAssetID = errors.New("There is an active submission with the same AssetID")
|
||||||
ErrActiveSubmissionSameTargetAssetID = errors.New("There is an active submission with the same TargetAssetID")
|
ErrActiveSubmissionSameTargetAssetID = errors.New("There is an active submission with the same TargetAssetID")
|
||||||
|
ErrReleaseInvalidStatus = errors.New("Only submissions with Uploaded status can be released")
|
||||||
|
ErrReleaseNoTargetAssetID = errors.New("Only submissions with a TargetAssetID can be released")
|
||||||
)
|
)
|
||||||
|
|
||||||
// POST /submissions
|
// POST /submissions
|
||||||
@ -485,5 +488,63 @@ func (svc *Service) ActionSubmissionTriggerValidate(ctx context.Context, params
|
|||||||
//
|
//
|
||||||
// POST /release-submissions
|
// POST /release-submissions
|
||||||
func (svc *Service) ReleaseSubmissions(ctx context.Context, request []api.ReleaseInfo) error {
|
func (svc *Service) ReleaseSubmissions(ctx context.Context, request []api.ReleaseInfo) error {
|
||||||
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
||||||
|
if !ok {
|
||||||
|
return ErrUserInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
has_role, err := userInfo.HasRoleSubmissionRelease()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// check if caller has required role
|
||||||
|
if !has_role {
|
||||||
|
return ErrPermissionDenied
|
||||||
|
}
|
||||||
|
|
||||||
|
idList := make([]int64, len(request))
|
||||||
|
for i, releaseInfo := range request {
|
||||||
|
idList[i] = releaseInfo.SubmissionID
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch submissions
|
||||||
|
submissions, err := svc.DB.Submissions().GetList(ctx, idList)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// check each submission to make sure it is ready to release
|
||||||
|
for _,submission := range submissions{
|
||||||
|
if submission.StatusID != model.StatusUploaded{
|
||||||
|
return ErrReleaseInvalidStatus
|
||||||
|
}
|
||||||
|
if submission.TargetAssetID == 0{
|
||||||
|
return ErrReleaseNoTargetAssetID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i,submission := range submissions{
|
||||||
|
date := request[i].Date.Unix()
|
||||||
|
// create each map with go-grpc
|
||||||
|
_, err := svc.Client.Create(ctx, &maps.MapRequest{
|
||||||
|
ID: submission.TargetAssetID,
|
||||||
|
DisplayName: &submission.DisplayName,
|
||||||
|
Creator: &submission.Creator,
|
||||||
|
GameID: &submission.GameID,
|
||||||
|
Date: &date,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// update each status to Released
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", model.StatusReleased)
|
||||||
|
err = svc.DB.Submissions().IfStatusThenUpdate(ctx, submission.ID, []model.Status{model.StatusUploaded}, smap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user