(c *gin.Context)
| 53 | } |
| 54 | |
| 55 | func GetAllChannels(c *gin.Context) { |
| 56 | pageInfo := common.GetPageQuery(c) |
| 57 | channelData := make([]*model.Channel, 0) |
| 58 | idSort, _ := strconv.ParseBool(c.Query("id_sort")) |
| 59 | enableTagMode, _ := strconv.ParseBool(c.Query("tag_mode")) |
| 60 | statusParam := c.Query("status") |
| 61 | // statusFilter: -1 all, 1 enabled, 0 disabled (include auto & manual) |
| 62 | statusFilter := parseStatusFilter(statusParam) |
| 63 | // type filter |
| 64 | typeStr := c.Query("type") |
| 65 | typeFilter := -1 |
| 66 | if typeStr != "" { |
| 67 | if t, err := strconv.Atoi(typeStr); err == nil { |
| 68 | typeFilter = t |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | var total int64 |
| 73 | |
| 74 | if enableTagMode { |
| 75 | tags, err := model.GetPaginatedTags(pageInfo.GetStartIdx(), pageInfo.GetPageSize()) |
| 76 | if err != nil { |
| 77 | c.JSON(http.StatusOK, gin.H{"success": false, "message": err.Error()}) |
| 78 | return |
| 79 | } |
| 80 | for _, tag := range tags { |
| 81 | if tag == nil || *tag == "" { |
| 82 | continue |
| 83 | } |
| 84 | tagChannels, err := model.GetChannelsByTag(*tag, idSort) |
| 85 | if err != nil { |
| 86 | continue |
| 87 | } |
| 88 | filtered := make([]*model.Channel, 0) |
| 89 | for _, ch := range tagChannels { |
| 90 | if statusFilter == common.ChannelStatusEnabled && ch.Status != common.ChannelStatusEnabled { |
| 91 | continue |
| 92 | } |
| 93 | if statusFilter == 0 && ch.Status == common.ChannelStatusEnabled { |
| 94 | continue |
| 95 | } |
| 96 | if typeFilter >= 0 && ch.Type != typeFilter { |
| 97 | continue |
| 98 | } |
| 99 | filtered = append(filtered, ch) |
| 100 | } |
| 101 | channelData = append(channelData, filtered...) |
| 102 | } |
| 103 | total, _ = model.CountAllTags() |
| 104 | } else { |
| 105 | baseQuery := model.DB.Model(&model.Channel{}) |
| 106 | if typeFilter >= 0 { |
| 107 | baseQuery = baseQuery.Where("type = ?", typeFilter) |
| 108 | } |
| 109 | if statusFilter == common.ChannelStatusEnabled { |
| 110 | baseQuery = baseQuery.Where("status = ?", common.ChannelStatusEnabled) |
| 111 | } else if statusFilter == 0 { |
| 112 | baseQuery = baseQuery.Where("status != ?", common.ChannelStatusEnabled) |
nothing calls this directly
no test coverage detected