Inventaire API: display search image
This commit is contained in:
@@ -15,16 +15,21 @@ type InventaireSearchBook struct {
|
||||
ID string `json:"id"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
Image string `json:"image"`
|
||||
}
|
||||
|
||||
func computeInventaireUrl(paths ...string) (*url.URL, error) {
|
||||
baseUrl := "https://inventaire.io/api"
|
||||
func GetBaseInventaireUrl() string {
|
||||
return "https://inventaire.io"
|
||||
}
|
||||
|
||||
func computeInventaireApiUrl(paths ...string) (*url.URL, error) {
|
||||
baseUrl := GetBaseInventaireUrl() + "/api"
|
||||
return callapiutils.ComputeUrl(baseUrl, paths...)
|
||||
}
|
||||
|
||||
func CallInventaireSearch(searchterm string, limit int, offset int) (InventaireSearchResult, error) {
|
||||
var queryResult InventaireSearchResult
|
||||
u, err := computeInventaireUrl("search")
|
||||
u, err := computeInventaireApiUrl("search")
|
||||
if err != nil {
|
||||
return queryResult, err
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ func findLangageField(multipleMessageFields map[string]json.RawMessage, lang str
|
||||
|
||||
func CallInventaireBook(inventaireId string, lang string) (InventaireBookResult, error) {
|
||||
queryResult := InventaireBookResult{ID: inventaireId, Lang: lang}
|
||||
u, err := computeInventaireUrl("entities")
|
||||
u, err := computeInventaireApiUrl("entities")
|
||||
if err != nil {
|
||||
return queryResult, err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/inventaire"
|
||||
@@ -44,14 +45,18 @@ func GetSearchBooksHandler(ac appcontext.AppContext) {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
returnedBooks = OpenLibraryBooksToBookSearchGet(queryResult.Results)
|
||||
returnedBooks = InventaireBooksToBookSearchGet(queryResult.Results)
|
||||
}
|
||||
ac.C.JSON(http.StatusOK, returnedBooks)
|
||||
}
|
||||
|
||||
func OpenLibraryBooksToBookSearchGet(OLbooks []inventaire.InventaireSearchBook) []query.BookSearchGet {
|
||||
func InventaireBooksToBookSearchGet(inventairebooks []inventaire.InventaireSearchBook) []query.BookSearchGet {
|
||||
var books []query.BookSearchGet
|
||||
for _, b := range OLbooks {
|
||||
for _, b := range inventairebooks {
|
||||
coverPath := ""
|
||||
if b.Image != "" && strings.HasPrefix(b.Image, "/") {
|
||||
coverPath = inventaire.GetBaseInventaireUrl() + b.Image
|
||||
}
|
||||
bookSearchGet := query.BookSearchGet{
|
||||
ID: 0,
|
||||
Title: b.Label,
|
||||
@@ -60,7 +65,7 @@ func OpenLibraryBooksToBookSearchGet(OLbooks []inventaire.InventaireSearchBook)
|
||||
Rating: 0,
|
||||
Read: false,
|
||||
WantRead: false,
|
||||
CoverPath: "",
|
||||
CoverPath: coverPath,
|
||||
}
|
||||
books = append(books, bookSearchGet)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user