💥 Pagination fetching realm member api
🐛 Fix remove realm member has no memberId path param
This commit is contained in:
parent
e0c9646c98
commit
20ff541ab4
8
.idea/workspace.xml
generated
8
.idea/workspace.xml
generated
@ -4,8 +4,10 @@
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Add realm member support both account name and id">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Prevent user adding a user twice into a realm">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/http/api/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/index.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/http/api/realm_members_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/realm_members_api.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/realms.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/realms.go" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@ -159,7 +161,6 @@
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
||||
<MESSAGE value=":sparkles: Authkit can get user" />
|
||||
<MESSAGE value=":bug: Fix auth cache" />
|
||||
<MESSAGE value=":sparkles: Allow get realm by numeric auto increment id" />
|
||||
<MESSAGE value=":sparkles: Allow access user info via numeric id" />
|
||||
@ -184,7 +185,8 @@
|
||||
<MESSAGE value=":boom: Move remove member api arguments from body to querystring just as messaging" />
|
||||
<MESSAGE value=":bug: Hotfix previous commit compile issue" />
|
||||
<MESSAGE value=":sparkles: Add realm member support both account name and id" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Add realm member support both account name and id" />
|
||||
<MESSAGE value=":bug: Prevent user adding a user twice into a realm" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":bug: Prevent user adding a user twice into a realm" />
|
||||
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
|
||||
</component>
|
||||
<component name="VgoProject">
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user