2024-11-26 23:30:58 +00:00
|
|
|
package service
|
2024-11-26 23:28:48 +00:00
|
|
|
|
|
|
|
import (
|
2024-11-27 23:38:17 +00:00
|
|
|
"time"
|
2024-11-26 23:28:48 +00:00
|
|
|
"context"
|
|
|
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
2024-11-27 23:38:17 +00:00
|
|
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
2024-11-26 23:28:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// POST /submissions
|
2024-11-27 23:38:17 +00:00
|
|
|
func (svc *Service) CreateSubmission(ctx context.Context, request api.OptSubmissionCreate) (*api.ID, error) {
|
|
|
|
//I don't know how to read the http body
|
|
|
|
submission, err := svc.DB.Submissions().Create(ctx, model.Submission{
|
|
|
|
ID: 0,
|
|
|
|
DisplayName: request.Value.DisplayName.Value,
|
|
|
|
Creator: request.Value.Creator.Value,
|
|
|
|
GameID: request.Value.GameID.Value,
|
|
|
|
Date: time.Now(),
|
|
|
|
Submitter: request.Value.Submitter.Value,
|
|
|
|
AssetID: request.Value.AssetID.Value,
|
|
|
|
AssetVersion: request.Value.AssetVersion.Value,
|
|
|
|
Completed: false,
|
|
|
|
TargetAssetID: request.Value.TargetAssetID.Value,
|
|
|
|
StatusID: 0,
|
|
|
|
})
|
|
|
|
if err != nil{
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &api.ID{
|
|
|
|
ID:api.NewOptInt64(submission.ID),
|
|
|
|
}, nil
|
2024-11-26 23:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetSubmission implements getSubmission operation.
|
|
|
|
//
|
|
|
|
// Retrieve map with ID.
|
|
|
|
//
|
|
|
|
// GET /submissions/{SubmissionID}
|
2024-11-26 23:30:58 +00:00
|
|
|
func (svc *Service) GetSubmission(ctx context.Context, params api.GetSubmissionParams) (*api.Submission, error) {
|
2024-11-26 23:55:56 +00:00
|
|
|
submission, err := svc.DB.Submissions().Get(ctx, params.SubmissionID)
|
|
|
|
if err != nil{
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &api.Submission{
|
|
|
|
ID: api.NewOptInt64(submission.ID),
|
|
|
|
DisplayName: api.NewOptString(submission.DisplayName),
|
|
|
|
Creator: api.NewOptString(submission.Creator),
|
|
|
|
GameID: api.NewOptInt32(submission.GameID),
|
|
|
|
Date: api.NewOptInt64(submission.Date.Unix()),
|
|
|
|
Submitter: api.NewOptInt64(submission.Submitter),
|
|
|
|
AssetID: api.NewOptInt64(submission.AssetID),
|
|
|
|
AssetVersion: api.NewOptInt64(submission.AssetVersion),
|
|
|
|
Completed: api.NewOptBool(submission.Completed),
|
|
|
|
TargetAssetID: api.NewOptInt64(submission.TargetAssetID),
|
|
|
|
StatusID: api.NewOptInt32(submission.StatusID),
|
|
|
|
}, nil
|
2024-11-26 23:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListSubmissions implements listSubmissions operation.
|
|
|
|
//
|
|
|
|
// Get list of submissions.
|
|
|
|
//
|
|
|
|
// GET /submissions
|
2024-11-26 23:30:58 +00:00
|
|
|
func (svc *Service) ListSubmissions(ctx context.Context, params api.ListSubmissionsParams) ([]api.Submission, error) {
|
2024-11-26 23:28:48 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PatchSubmissionCompleted implements patchSubmissionCompleted operation.
|
|
|
|
//
|
|
|
|
// Retrieve map with ID.
|
|
|
|
//
|
|
|
|
// PATCH /submissions/{SubmissionID}/completed
|
2024-11-26 23:30:58 +00:00
|
|
|
func (svc *Service) PatchSubmissionCompleted(ctx context.Context, params api.PatchSubmissionCompletedParams) error {
|
2024-11-26 23:28:48 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PatchSubmissionModel implements patchSubmissionModel operation.
|
|
|
|
//
|
|
|
|
// Update model following role restrictions.
|
|
|
|
//
|
|
|
|
// PATCH /submissions/{SubmissionID}/model
|
2024-11-26 23:30:58 +00:00
|
|
|
func (svc *Service) PatchSubmissionModel(ctx context.Context, params api.PatchSubmissionModelParams) error {
|
2024-11-26 23:28:48 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PatchSubmissionStatus implements patchSubmissionStatus operation.
|
|
|
|
//
|
|
|
|
// Update status following role restrictions.
|
|
|
|
//
|
|
|
|
// PATCH /submissions/{SubmissionID}/status
|
2024-11-26 23:30:58 +00:00
|
|
|
func (svc *Service) PatchSubmissionStatus(ctx context.Context, params api.PatchSubmissionStatusParams) error {
|
2024-11-26 23:28:48 +00:00
|
|
|
return nil
|
|
|
|
}
|