Some checks failed
continuous-integration/drone/push Build is failing
Creates a GRPC controller for Submissions and Mapfixes. This is intended to be used from the AOR group games via game-rpc running in "maptest" mode. Reviewed-on: #317 Co-authored-by: Rhys Lloyd <krakow20@gmail.com> Co-committed-by: Rhys Lloyd <krakow20@gmail.com>
162 lines
5.1 KiB
Go
162 lines
5.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.itzana.me/strafesnet/go-grpc/submissions"
|
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
)
|
|
|
|
type Submissions struct {
|
|
*submissions.UnimplementedSubmissionsServiceServer
|
|
inner *service.Service
|
|
}
|
|
|
|
func NewSubmissionsController(
|
|
inner *service.Service,
|
|
) Submissions {
|
|
return Submissions{
|
|
inner: inner,
|
|
}
|
|
}
|
|
|
|
func (svc *Submissions) Get(ctx context.Context, request *submissions.SubmissionId) (*submissions.SubmissionResponse, error) {
|
|
item, err := svc.inner.GetSubmission(ctx, request.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var validated_asset_id *uint64
|
|
if item.ValidatedAssetID != 0 {
|
|
validated_asset_id = &item.ValidatedAssetID
|
|
}
|
|
var validated_asset_version *uint64
|
|
if item.ValidatedAssetVersion != 0 {
|
|
validated_asset_version = &item.ValidatedAssetVersion
|
|
}
|
|
var uploaded_asset_id *uint64
|
|
if item.UploadedAssetID != 0 {
|
|
uploaded_asset_id = &item.UploadedAssetID
|
|
}
|
|
return &submissions.SubmissionResponse{
|
|
ID: item.ID,
|
|
DisplayName: item.DisplayName,
|
|
Creator: item.Creator,
|
|
GameID: uint32(item.GameID),
|
|
CreatedAt: item.CreatedAt.Unix(),
|
|
UpdatedAt: item.UpdatedAt.Unix(),
|
|
Submitter: uint64(item.Submitter),
|
|
AssetVersion: uint64(item.AssetVersion),
|
|
AssetID: item.AssetID,
|
|
ValidatedAssetID: validated_asset_id,
|
|
ValidatedAssetVersion: validated_asset_version,
|
|
UploadedAssetID: uploaded_asset_id,
|
|
StatusID: submissions.SubmissionStatus(item.StatusID),
|
|
}, nil
|
|
}
|
|
func (svc *Submissions) GetList(ctx context.Context, request *submissions.SubmissionIdList) (*submissions.SubmissionList, error) {
|
|
items, err := svc.inner.GetSubmissionList(ctx, request.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp := submissions.SubmissionList{}
|
|
resp.Submissions = make([]*submissions.SubmissionResponse, len(items))
|
|
for i, item := range items {
|
|
var validated_asset_id *uint64
|
|
if item.ValidatedAssetID != 0 {
|
|
validated_asset_id = &item.ValidatedAssetID
|
|
}
|
|
var validated_asset_version *uint64
|
|
if item.ValidatedAssetVersion != 0 {
|
|
validated_asset_version = &item.ValidatedAssetVersion
|
|
}
|
|
var uploaded_asset_id *uint64
|
|
if item.UploadedAssetID != 0 {
|
|
uploaded_asset_id = &item.UploadedAssetID
|
|
}
|
|
resp.Submissions[i] = &submissions.SubmissionResponse{
|
|
ID: item.ID,
|
|
DisplayName: item.DisplayName,
|
|
Creator: item.Creator,
|
|
GameID: uint32(item.GameID),
|
|
CreatedAt: item.CreatedAt.Unix(),
|
|
UpdatedAt: item.UpdatedAt.Unix(),
|
|
Submitter: uint64(item.Submitter),
|
|
AssetVersion: uint64(item.AssetVersion),
|
|
AssetID: item.AssetID,
|
|
ValidatedAssetID: validated_asset_id,
|
|
ValidatedAssetVersion: validated_asset_version,
|
|
UploadedAssetID: uploaded_asset_id,
|
|
StatusID: submissions.SubmissionStatus(item.StatusID),
|
|
}
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|
|
func (svc *Submissions) List(ctx context.Context, request *submissions.ListRequest) (*submissions.SubmissionList, error) {
|
|
if request.Page == nil {
|
|
return nil, PageError
|
|
}
|
|
|
|
filter := service.NewSubmissionFilter()
|
|
if request.Filter != nil {
|
|
if request.Filter.DisplayName != nil {
|
|
filter.SetDisplayName(*request.Filter.DisplayName)
|
|
}
|
|
if request.Filter.Creator != nil {
|
|
filter.SetCreator(*request.Filter.Creator)
|
|
}
|
|
if request.Filter.GameID != nil {
|
|
filter.SetGameID(*request.Filter.GameID)
|
|
}
|
|
if request.Filter.Submitter != nil {
|
|
filter.SetSubmitter(*request.Filter.Submitter)
|
|
}
|
|
}
|
|
|
|
items, err := svc.inner.ListSubmissions(ctx, filter, model.Page{
|
|
Number: int32(request.Page.Number),
|
|
Size: int32(request.Page.Size),
|
|
}, datastore.ListSortDateDescending)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp := submissions.SubmissionList{}
|
|
resp.Submissions = make([]*submissions.SubmissionResponse, len(items))
|
|
for i, item := range items {
|
|
var validated_asset_id *uint64
|
|
if item.ValidatedAssetID != 0 {
|
|
validated_asset_id = &item.ValidatedAssetID
|
|
}
|
|
var validated_asset_version *uint64
|
|
if item.ValidatedAssetVersion != 0 {
|
|
validated_asset_version = &item.ValidatedAssetVersion
|
|
}
|
|
var uploaded_asset_id *uint64
|
|
if item.UploadedAssetID != 0 {
|
|
uploaded_asset_id = &item.UploadedAssetID
|
|
}
|
|
resp.Submissions[i] = &submissions.SubmissionResponse{
|
|
ID: item.ID,
|
|
DisplayName: item.DisplayName,
|
|
Creator: item.Creator,
|
|
GameID: uint32(item.GameID),
|
|
CreatedAt: item.CreatedAt.Unix(),
|
|
UpdatedAt: item.UpdatedAt.Unix(),
|
|
Submitter: uint64(item.Submitter),
|
|
AssetVersion: uint64(item.AssetVersion),
|
|
AssetID: item.AssetID,
|
|
ValidatedAssetID: validated_asset_id,
|
|
ValidatedAssetVersion: validated_asset_version,
|
|
UploadedAssetID: uploaded_asset_id,
|
|
StatusID: submissions.SubmissionStatus(item.StatusID),
|
|
}
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|