submissions: flatten list query params
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Quaternions 2024-12-17 21:39:04 -08:00
parent 76d36bea5c
commit a94ae5d61e
2 changed files with 23 additions and 29 deletions

View File

@ -52,25 +52,22 @@ func (svc *Service) CreateScriptPolicy(ctx context.Context, req *api.ScriptPolic
// Get list of script policies.
//
// GET /script-policy
func (svc *Service) ListScriptPolicy(ctx context.Context, request *api.ListScriptPolicyReq) ([]api.ScriptPolicy, error) {
func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptPolicyParams) ([]api.ScriptPolicy, error) {
filter := datastore.Optional()
if request.Filter.IsSet() {
f := request.Filter.Value
if f.FromScriptHash.IsSet(){
filter.AddNotNil("from_script_hash", f.FromScriptHash.Value)
}
if f.ToScriptID.IsSet(){
filter.AddNotNil("to_script_id", f.ToScriptID.Value)
}
if f.Policy.IsSet(){
filter.AddNotNil("policy", f.Policy.Value)
}
if params.FromScriptHash.IsSet(){
filter.AddNotNil("from_script_hash", params.FromScriptHash.Value)
}
if params.ToScriptID.IsSet(){
filter.AddNotNil("to_script_id", params.ToScriptID.Value)
}
if params.Policy.IsSet(){
filter.AddNotNil("policy", params.Policy.Value)
}
items, err := svc.DB.ScriptPolicy().List(ctx, filter, model.Page{
Number: request.Page.Number,
Size: request.Page.Size,
Number: params.Page,
Size: params.Limit,
})
if err != nil {
return nil, err

View File

@ -67,25 +67,22 @@ func (svc *Service) GetSubmission(ctx context.Context, params api.GetSubmissionP
// Get list of submissions.
//
// GET /submissions
func (svc *Service) ListSubmissions(ctx context.Context, request *api.ListSubmissionsReq) ([]api.Submission, error) {
func (svc *Service) ListSubmissions(ctx context.Context, params api.ListSubmissionsParams) ([]api.Submission, error) {
filter := datastore.Optional()
//fmt.Println(request)
if request.Filter.IsSet() {
f := request.Filter.Value
if f.DisplayName.IsSet(){
filter.Add("display_name", f.DisplayName.Value)
}
if f.Creator.IsSet(){
filter.Add("creator", f.Creator.Value)
}
if f.GameID.IsSet(){
filter.Add("game_id", f.GameID.Value)
}
if params.DisplayName.IsSet(){
filter.Add("display_name", params.DisplayName.Value)
}
if params.Creator.IsSet(){
filter.Add("creator", params.Creator.Value)
}
if params.GameID.IsSet(){
filter.Add("game_id", params.GameID.Value)
}
items, err := svc.DB.Submissions().List(ctx, filter, model.Page{
Number: request.Page.Number,
Size: request.Page.Size,
Number: params.Page,
Size: params.Limit,
})
if err != nil {
return nil, err