💥 Pagination of channel members
This commit is contained in:
parent
519d570041
commit
40ef26f75d
@ -17,6 +17,8 @@ import (
|
|||||||
|
|
||||||
func listChannelMembers(c *fiber.Ctx) error {
|
func listChannelMembers(c *fiber.Ctx) error {
|
||||||
alias := c.Params("channel")
|
alias := c.Params("channel")
|
||||||
|
take := c.QueryInt("take", 0)
|
||||||
|
offset := c.QueryInt("offset", 0)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var channel models.Channel
|
var channel models.Channel
|
||||||
@ -29,7 +31,7 @@ func listChannelMembers(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if members, err := services.ListChannelMember(channel.ID); err != nil {
|
if members, err := services.ListChannelMember(channel.ID, take, offset); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
} else {
|
} else {
|
||||||
return c.JSON(members)
|
return c.JSON(members)
|
||||||
|
@ -15,10 +15,11 @@ import (
|
|||||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ListChannelMember(channelId uint) ([]models.ChannelMember, error) {
|
func ListChannelMember(channelId uint, take int, offset int) ([]models.ChannelMember, error) {
|
||||||
var members []models.ChannelMember
|
var members []models.ChannelMember
|
||||||
|
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
|
Limit(take).Offset(offset).
|
||||||
Where(&models.ChannelMember{ChannelID: channelId}).
|
Where(&models.ChannelMember{ChannelID: channelId}).
|
||||||
Find(&members).Error; err != nil {
|
Find(&members).Error; err != nil {
|
||||||
return members, err
|
return members, err
|
||||||
|
Loading…
Reference in New Issue
Block a user