diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 5c70c25..6fdfaf1 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,8 +4,10 @@
-
+
+
+
@@ -159,7 +161,6 @@
-
@@ -184,7 +185,8 @@
-
+
+
diff --git a/pkg/internal/http/api/index.go b/pkg/internal/http/api/index.go
index 0e2a8be..84beadf 100644
--- a/pkg/internal/http/api/index.go
+++ b/pkg/internal/http/api/index.go
@@ -124,13 +124,13 @@ func MapAPIs(app *fiber.App, baseURL string) {
realms.Get("/me", listOwnedRealm)
realms.Get("/me/available", listAvailableRealm)
realms.Get("/:realm", getRealm)
- realms.Get("/:realm/members/:memberId", listRealmMembers)
+ realms.Get("/:realm/members", listRealmMembers)
realms.Get("/:realm/members/me", getMyRealmMember)
realms.Post("/", createRealm)
realms.Put("/:realmId", editRealm)
realms.Delete("/:realmId", deleteRealm)
realms.Post("/:realm/members", addRealmMember)
- realms.Delete("/:realm/members", removeRealmMember)
+ realms.Delete("/:realm/members/:memberId", removeRealmMember)
realms.Delete("/:realm/members/me", leaveRealm)
}
diff --git a/pkg/internal/http/api/realm_members_api.go b/pkg/internal/http/api/realm_members_api.go
index 787f6c9..50b7c71 100644
--- a/pkg/internal/http/api/realm_members_api.go
+++ b/pkg/internal/http/api/realm_members_api.go
@@ -11,13 +11,20 @@ import (
func listRealmMembers(c *fiber.Ctx) error {
alias := c.Params("realm")
+ take := c.QueryInt("take", 0)
+ offset := c.QueryInt("offset", 0)
if realm, err := services.GetRealmWithAlias(alias); err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
- } else if members, err := services.ListRealmMember(realm.ID); err != nil {
+ } else if count, err := services.CountRealmMember(realm.ID); err != nil {
+ return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+ } else if members, err := services.ListRealmMember(realm.ID, take, offset); err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} else {
- return c.JSON(members)
+ return c.JSON(fiber.Map{
+ "count": count,
+ "data": members,
+ })
}
}
diff --git a/pkg/internal/services/realms.go b/pkg/internal/services/realms.go
index 176927a..75117d2 100644
--- a/pkg/internal/services/realms.go
+++ b/pkg/internal/services/realms.go
@@ -74,10 +74,22 @@ func NewRealm(realm models.Realm, user models.Account) (models.Realm, error) {
return realm, err
}
-func ListRealmMember(realmId uint) ([]models.RealmMember, error) {
+func CountRealmMember(realmId uint) (int64, error) {
+ var count int64
+ if err := database.C.Where(&models.RealmMember{
+ RealmID: realmId,
+ }).Model(&models.RealmMember{}).Count(&count).Error; err != nil {
+ return 0, err
+ } else {
+ return count, nil
+ }
+}
+
+func ListRealmMember(realmId uint, take int, offset int) ([]models.RealmMember, error) {
var members []models.RealmMember
if err := database.C.
+ Limit(take).Offset(offset).
Where(&models.RealmMember{RealmID: realmId}).
Preload("Account").
Find(&members).Error; err != nil {