From 4b4eb3e58104d12363adba597389544e854cedf4 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 17 Sep 2024 16:46:58 +0800 Subject: [PATCH] :sparkles: New query method on querying realm members --- go.mod | 2 +- go.sum | 2 ++ pkg/internal/grpc/realms.go | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6a9344f..521643c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21.6 toolchain go1.22.1 require ( - git.solsynth.dev/hydrogen/dealer v0.0.0-20240911145828-d734d617bfc8 + git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f github.com/go-playground/validator/v10 v10.17.0 github.com/gofiber/fiber/v2 v2.52.4 github.com/golang-jwt/jwt/v5 v5.2.0 diff --git a/go.sum b/go.sum index 1a03dcb..1833956 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ git.solsynth.dev/hydrogen/dealer v0.0.0-20240911145828-d734d617bfc8 h1:kWheneSdSySG5tz9TAXrtr546JdMpQZTyWDFk4jeGwg= git.solsynth.dev/hydrogen/dealer v0.0.0-20240911145828-d734d617bfc8/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI= +git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f h1:3jLpcws4/zmNUA60w1RtAtGNjcQd5NZCcbW5HQcUcvw= +git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/pkg/internal/grpc/realms.go b/pkg/internal/grpc/realms.go index 1a056a3..fa6006a 100644 --- a/pkg/internal/grpc/realms.go +++ b/pkg/internal/grpc/realms.go @@ -140,7 +140,13 @@ func (v *Server) GetRealm(ctx context.Context, request *proto.LookupRealmRequest func (v *Server) ListRealmMember(ctx context.Context, request *proto.RealmMemberLookupRequest) (*proto.ListRealmMemberResponse, error) { var members []models.RealmMember - tx := database.C.Where("realm_id = ?", request.GetRealmId()) + if request.UserId == nil && request.RealmId == nil { + return nil, fmt.Errorf("either user id or realm id must be provided") + } + tx := database.C + if request.RealmId != nil { + tx = tx.Where("realm_id = ?", request.GetRealmId()) + } if request.UserId != nil { tx = tx.Where("account_id = ?", request.GetUserId()) } @@ -162,7 +168,13 @@ func (v *Server) ListRealmMember(ctx context.Context, request *proto.RealmMember func (v *Server) GetRealmMember(ctx context.Context, request *proto.RealmMemberLookupRequest) (*proto.RealmMemberInfo, error) { var member models.RealmMember - tx := database.C.Where("realm_id = ?", request.GetRealmId()) + if request.UserId == nil && request.RealmId == nil { + return nil, fmt.Errorf("either user id or realm id must be provided") + } + tx := database.C + if request.RealmId != nil { + tx = tx.Where("realm_id = ?", request.GetRealmId()) + } if request.UserId != nil { tx = tx.Where("account_id = ?", request.GetUserId()) }