(c *gin.Context)
| 223 | } |
| 224 | |
| 225 | func SearchChannels(c *gin.Context) { |
| 226 | keyword := c.Query("keyword") |
| 227 | group := c.Query("group") |
| 228 | modelKeyword := c.Query("model") |
| 229 | statusParam := c.Query("status") |
| 230 | statusFilter := parseStatusFilter(statusParam) |
| 231 | idSort, _ := strconv.ParseBool(c.Query("id_sort")) |
| 232 | enableTagMode, _ := strconv.ParseBool(c.Query("tag_mode")) |
| 233 | channelData := make([]*model.Channel, 0) |
| 234 | if enableTagMode { |
| 235 | tags, err := model.SearchTags(keyword, group, modelKeyword, idSort) |
| 236 | if err != nil { |
| 237 | c.JSON(http.StatusOK, gin.H{ |
| 238 | "success": false, |
| 239 | "message": err.Error(), |
| 240 | }) |
| 241 | return |
| 242 | } |
| 243 | for _, tag := range tags { |
| 244 | if tag != nil && *tag != "" { |
| 245 | tagChannel, err := model.GetChannelsByTag(*tag, idSort) |
| 246 | if err == nil { |
| 247 | channelData = append(channelData, tagChannel...) |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | } else { |
| 252 | channels, err := model.SearchChannels(keyword, group, modelKeyword, idSort) |
| 253 | if err != nil { |
| 254 | c.JSON(http.StatusOK, gin.H{ |
| 255 | "success": false, |
| 256 | "message": err.Error(), |
| 257 | }) |
| 258 | return |
| 259 | } |
| 260 | channelData = channels |
| 261 | } |
| 262 | |
| 263 | if statusFilter == common.ChannelStatusEnabled || statusFilter == 0 { |
| 264 | filtered := make([]*model.Channel, 0, len(channelData)) |
| 265 | for _, ch := range channelData { |
| 266 | if statusFilter == common.ChannelStatusEnabled && ch.Status != common.ChannelStatusEnabled { |
| 267 | continue |
| 268 | } |
| 269 | if statusFilter == 0 && ch.Status == common.ChannelStatusEnabled { |
| 270 | continue |
| 271 | } |
| 272 | filtered = append(filtered, ch) |
| 273 | } |
| 274 | channelData = filtered |
| 275 | } |
| 276 | |
| 277 | // calculate type counts for search results |
| 278 | typeCounts := make(map[int64]int64) |
| 279 | for _, channel := range channelData { |
| 280 | typeCounts[int64(channel.Type)]++ |
| 281 | } |
| 282 |
nothing calls this directly
no test coverage detected