From e905d969171ef4b18a018d977728a3e48a3321a3 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 17 Dec 2024 21:03:39 -0800 Subject: [PATCH] submissions: fix list requests --- pkg/service/script_policy.go | 15 +++++++++++---- pkg/service/submissions.go | 13 ++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pkg/service/script_policy.go b/pkg/service/script_policy.go index 55d8733..4023c62 100644 --- a/pkg/service/script_policy.go +++ b/pkg/service/script_policy.go @@ -54,11 +54,18 @@ func (svc *Service) CreateScriptPolicy(ctx context.Context, req *api.ScriptPolic // GET /script-policy func (svc *Service) ListScriptPolicy(ctx context.Context, request *api.ListScriptPolicyReq) ([]api.ScriptPolicy, error) { filter := datastore.Optional() - //fmt.Println(request) + if request.Filter.IsSet() { - filter.AddNotNil("from_script_hash", request.Filter.Value.FromScriptHash) - filter.AddNotNil("to_script_id", request.Filter.Value.ToScriptID) - filter.AddNotNil("policy", request.Filter.Value.Policy) + 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) + } } items, err := svc.DB.ScriptPolicy().List(ctx, filter, model.Page{ diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index 447aa3c..7dccef3 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -71,9 +71,16 @@ func (svc *Service) ListSubmissions(ctx context.Context, request *api.ListSubmis filter := datastore.Optional() //fmt.Println(request) if request.Filter.IsSet() { - filter.AddNotNil("display_name", request.Filter.Value.DisplayName) - filter.AddNotNil("creator", request.Filter.Value.Creator) - filter.AddNotNil("game_id", request.Filter.Value.GameID) + 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) + } } items, err := svc.DB.Submissions().List(ctx, filter, model.Page{