From 40ef26f75d9fab53f0d3c049727e61e413189ffc Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 30 Nov 2024 22:45:21 +0800 Subject: [PATCH] :boom: Pagination of channel members --- pkg/internal/http/api/channel_members_api.go | 4 +++- pkg/internal/services/channel_members.go | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/internal/http/api/channel_members_api.go b/pkg/internal/http/api/channel_members_api.go index 719b8e7..5b7766d 100644 --- a/pkg/internal/http/api/channel_members_api.go +++ b/pkg/internal/http/api/channel_members_api.go @@ -17,6 +17,8 @@ import ( func listChannelMembers(c *fiber.Ctx) error { alias := c.Params("channel") + take := c.QueryInt("take", 0) + offset := c.QueryInt("offset", 0) var err error var channel models.Channel @@ -29,7 +31,7 @@ func listChannelMembers(c *fiber.Ctx) 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()) } else { return c.JSON(members) diff --git a/pkg/internal/services/channel_members.go b/pkg/internal/services/channel_members.go index 4127372..6b3cedb 100644 --- a/pkg/internal/services/channel_members.go +++ b/pkg/internal/services/channel_members.go @@ -15,10 +15,11 @@ import ( "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 if err := database.C. + Limit(take).Offset(offset). Where(&models.ChannelMember{ChannelID: channelId}). Find(&members).Error; err != nil { return members, err