New query method on querying realm members

This commit is contained in:
LittleSheep 2024-09-17 16:46:58 +08:00
parent 5203234c4a
commit 4b4eb3e581
3 changed files with 17 additions and 3 deletions

2
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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())
}