Switch from open library API to Inventaire API

This commit is contained in:
2026-01-16 16:12:59 +01:00
parent 1bb841332c
commit a04aff6056
22 changed files with 338 additions and 108 deletions

View File

@@ -4,6 +4,7 @@ import (
"net/http"
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
"git.artlef.fr/PersonalLibraryManager/internal/inventaire"
"git.artlef.fr/PersonalLibraryManager/internal/myvalidator"
"git.artlef.fr/PersonalLibraryManager/internal/openlibrary"
"git.artlef.fr/PersonalLibraryManager/internal/query"
@@ -38,28 +39,28 @@ func GetSearchBooksHandler(ac appcontext.AppContext) {
if len(books) > 0 {
returnedBooks = books
} else {
queryResult, err := openlibrary.CallOpenLibrarySearch(searchterm, limit, offset)
queryResult, err := inventaire.CallInventaireSearch(searchterm, limit, offset)
if err != nil {
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
return
}
returnedBooks = OpenLibraryBooksToBookSearchGet(queryResult.Books)
returnedBooks = OpenLibraryBooksToBookSearchGet(queryResult.Results)
}
ac.C.JSON(http.StatusOK, returnedBooks)
}
func OpenLibraryBooksToBookSearchGet(OLbooks []openlibrary.OpenLibrarySearchBook) []query.BookSearchGet {
func OpenLibraryBooksToBookSearchGet(OLbooks []inventaire.InventaireSearchBook) []query.BookSearchGet {
var books []query.BookSearchGet
for _, b := range OLbooks {
bookSearchGet := query.BookSearchGet{
ID: 0,
Title: b.Title,
Author: b.Authors[0],
OpenLibraryId: b.OpenLibraryId,
Rating: 0,
Read: false,
WantRead: false,
CoverPath: "",
ID: 0,
Title: b.Label,
Author: "",
InventaireID: b.ID,
Rating: 0,
Read: false,
WantRead: false,
CoverPath: "",
}
books = append(books, bookSearchGet)
}