🐛 Fix pagination fetch channel members does not include total count
This commit is contained in:
parent
40ef26f75d
commit
e82f100b67
@ -31,10 +31,18 @@ func listChannelMembers(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
count, err := services.CountChannelMember(channel.ID)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
if members, err := services.ListChannelMember(channel.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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,17 @@ import (
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
||||
)
|
||||
|
||||
func CountChannelMember(channelId uint) (int64, error) {
|
||||
var count int64
|
||||
if err := database.C.Where(&models.ChannelMember{
|
||||
ChannelID: channelId,
|
||||
}).Model(&models.ChannelMember{}).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
return count, nil
|
||||
}
|
||||
}
|
||||
|
||||
func ListChannelMember(channelId uint, take int, offset int) ([]models.ChannelMember, error) {
|
||||
var members []models.ChannelMember
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user