46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package inventaire
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"git.artlef.fr/bibliomane/internal/callapiutils"
|
|
)
|
|
|
|
type InventaireSearchResult struct {
|
|
Results []InventaireSearchBook `json:"results"`
|
|
Total int64 `json:"total"`
|
|
}
|
|
|
|
type InventaireSearchBook struct {
|
|
ID string `json:"uri"`
|
|
Label string `json:"label"`
|
|
Description string `json:"description"`
|
|
Image string `json:"image"`
|
|
}
|
|
|
|
func computeInventaireApiUrl(inventaireUrl string, paths ...string) (*url.URL, error) {
|
|
baseUrl := inventaireUrl + "/api"
|
|
return callapiutils.ComputeUrl(baseUrl, paths...)
|
|
}
|
|
|
|
func CallInventaireSearch(inventaireUrl string, searchterm string, lang string, limit int, offset int) (InventaireSearchResult, error) {
|
|
var queryResult InventaireSearchResult
|
|
u, err := computeInventaireApiUrl(inventaireUrl, "search")
|
|
if err != nil {
|
|
return queryResult, err
|
|
}
|
|
if lang != "" {
|
|
callapiutils.AddQueryParam(u, "lang", lang)
|
|
}
|
|
if limit != 0 {
|
|
callapiutils.AddQueryParamInt(u, "limit", limit)
|
|
}
|
|
if offset != 0 {
|
|
callapiutils.AddQueryParamInt(u, "offset", offset)
|
|
}
|
|
callapiutils.AddQueryParam(u, "types", "works")
|
|
callapiutils.AddQueryParam(u, "search", searchterm)
|
|
err = callapiutils.FetchAndParseResult(u, &queryResult)
|
|
return queryResult, err
|
|
}
|