FEAT: Video Search In Discovery
Build, Push and Deploy Discovery / build-push-deploy (push) Successful in 1m57s
Build, Push and Deploy Discovery / build-push-deploy (push) Successful in 1m57s
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user