diff --git a/internal/database/videos.go b/internal/database/videos.go index 4990244f..556f2021 100644 --- a/internal/database/videos.go +++ b/internal/database/videos.go @@ -50,6 +50,7 @@ type Clip struct { CreatedAt string `db:"created_at" json:"created_at"` Duration float64 `db:"duration" json:"duration"` VodOffset int `db:"vod_offset" json:"vod_offset"` + IsFeatured bool `json:"is_featured"` // calculated fields URL string `json:"url"` ThumbnailURL string `json:"thumbnail_url"` diff --git a/internal/mock_api/endpoints/clips/clips.go b/internal/mock_api/endpoints/clips/clips.go index 417d5791..fbe37d52 100644 --- a/internal/mock_api/endpoints/clips/clips.go +++ b/internal/mock_api/endpoints/clips/clips.go @@ -6,6 +6,8 @@ import ( "encoding/json" "fmt" "net/http" + "strconv" + "strings" "time" "github.com/twitchdev/twitch-cli/internal/database" @@ -70,6 +72,8 @@ func getClips(w http.ResponseWriter, r *http.Request) { startedAt := r.URL.Query().Get("started_at") endedAt := r.URL.Query().Get("ended_at") + isFeatured := r.URL.Query().Get("is_featured") + if broadcasterID == "" && gameID == "" && id == "" { mock_errors.WriteBadRequest(w, "one of broadcaster_id, game_id, or id is required") return @@ -80,6 +84,11 @@ func getClips(w http.ResponseWriter, r *http.Request) { return } + if isFeatured != "" && (!strings.EqualFold(isFeatured, "false") && !strings.EqualFold(isFeatured, "true")) { + mock_errors.WriteBadRequest(w, "is_featured must be true or false") + return + } + if startedAt != "" && endedAt == "" { sa, _ := time.Parse(time.RFC3339, startedAt) endedAt = sa.Add(7 * 24 * time.Hour).Format(time.RFC3339) @@ -92,6 +101,18 @@ func getClips(w http.ResponseWriter, r *http.Request) { } clips := dbr.Data.([]database.Clip) + + if isFeatured != "" { + newClips := []database.Clip{} + for _, clip := range clips { + featured, _ := strconv.ParseBool(isFeatured) + if clip.IsFeatured == featured { + newClips = append(newClips, clip) + } + } + clips = newClips + } + apiResponse := models.APIResponse{ Data: clips, }