FEAT: Video Search In Discovery
Build, Push and Deploy Discovery / build-push-deploy (push) Successful in 1m57s

This commit is contained in:
FahdShalhoub
2026-08-29 17:56:11 +03:00
parent 6f9e04ee97
commit c3465bedb1
20 changed files with 915 additions and 9 deletions
+49
View File
@@ -139,6 +139,55 @@ type catalogueVideoBody struct {
Categories []string `json:"categories"`
}
// searchRequest is the body of QUERY /api/videos on discovery: what a reader
// is looking for, plus where in the results to carry on from.
//
// Every field is optional. An empty body is the whole catalogue, newest first.
type searchRequest struct {
Title string `json:"title,omitempty"`
Categories []string `json:"categories,omitempty"`
Limit int `json:"limit,omitempty"`
Cursor string `json:"cursor,omitempty"`
}
// searchResultsBody is what that query answers with: the page of videos, and
// the cursor that reaches the page after it. NextCursor is empty on the last
// page, which is how a client knows to stop.
type searchResultsBody struct {
Videos []catalogueVideoBody `json:"videos"`
NextCursor string `json:"nextCursor"`
}
// ids lists the video ids in the page, for asserting on which videos came back
// without caring about the rest of their fields.
func (b searchResultsBody) ids() []string {
found := make([]string, 0, len(b.Videos))
for _, v := range b.Videos {
found = append(found, v.ID)
}
return found
}
func (b searchResultsBody) holds(id string) bool {
for _, v := range b.Videos {
if v.ID == id {
return true
}
}
return false
}
// queryJSON sends a QUERY request — the method the catalogue search is served
// on, chosen because a search is safe and idempotent like a GET but carries a
// structured body no query string would hold comfortably.
func (c *client) queryJSON(path string, payload any) (response, error) {
encoded, err := json.Marshal(payload)
if err != nil {
return response{}, err
}
return c.send("QUERY", c.base+path, "application/json", encoded)
}
// postJSON marshals payload and posts it to a path on the CMS.
func (c *client) postJSON(path string, payload any) (response, error) {
encoded, err := json.Marshal(payload)