From 132d7b9f949f2943df526ad9fbc302ba13db2411 Mon Sep 17 00:00:00 2001 From: DraftGo <129143636+draftgo@users.noreply.github.com> Date: Sat, 16 May 2026 14:54:50 +0800 Subject: [PATCH] fix: GetAllChannels ignores group filter parameter (#4847) When users filter channels by group without entering a search keyword, the frontend calls GetAllChannels (GET /api/channel/) instead of SearchChannels. However, GetAllChannels did not process the group query parameter, causing the filter to have no effect. Added group filtering logic to GetAllChannels for both normal mode and tag mode, using the same CONCAT/|| pattern as SearchChannels for cross-database compatibility (MySQL, PostgreSQL, SQLite). --- controller/channel.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/controller/channel.go b/controller/channel.go index eb95ccc3..9eef9f0e 100644 --- a/controller/channel.go +++ b/controller/channel.go @@ -85,6 +85,8 @@ func GetAllChannels(c *gin.Context) { typeFilter = t } } + // group filter + groupFilter := c.Query("group") var total int64 @@ -114,6 +116,11 @@ func GetAllChannels(c *gin.Context) { if typeFilter >= 0 && ch.Type != typeFilter { continue } + if groupFilter != "" && groupFilter != "null" { + if !strings.Contains(","+ch.Group+",", ","+groupFilter+",") { + continue + } + } filtered = append(filtered, ch) } channelData = append(channelData, filtered...) @@ -129,6 +136,14 @@ func GetAllChannels(c *gin.Context) { } else if statusFilter == 0 { baseQuery = baseQuery.Where("status != ?", common.ChannelStatusEnabled) } + if groupFilter != "" && groupFilter != "null" { + if common.UsingMySQL { + baseQuery = baseQuery.Where("CONCAT(',', `group`, ',') LIKE ?", "%,"+groupFilter+",%") + } else { + // SQLite, PostgreSQL + baseQuery = baseQuery.Where("(',' || \"group\" || ',') LIKE ?", "%,"+groupFilter+",%") + } + } baseQuery.Count(&total)