Use the same widget for books everywhere

This commit is contained in:
2026-03-27 22:08:24 +01:00
parent 726c640657
commit e05c9f2b45
17 changed files with 70 additions and 146 deletions

View File

@@ -37,7 +37,7 @@ func GetSearchBooksHandler(ac appcontext.AppContext) {
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
return
}
var returnedBooks dto.BookSearchGet
var returnedBooks dto.BookItemsGet
if !params.Inventaire {
books, err := query.FetchBookSearchGet(ac.Db, user.ID, searchterm, limit, offset)
if err != nil {
@@ -49,7 +49,7 @@ func GetSearchBooksHandler(ac appcontext.AppContext) {
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
return
}
returnedBooks = dto.BookSearchGet{Count: count, Inventaire: false, Books: books}
returnedBooks = dto.BookItemsGet{Count: count, Inventaire: false, Books: books}
}
if params.Inventaire || len(returnedBooks.Books) == 0 {
returnedBooksPtr, err := searchInInventaireAPI(ac.Config.InventaireUrl, searchterm, limit, offset, params)
@@ -62,7 +62,7 @@ func GetSearchBooksHandler(ac appcontext.AppContext) {
ac.C.JSON(http.StatusOK, returnedBooks)
}
func searchInInventaireAPI(inventaireUrl string, searchterm string, limit int, offset int, params dto.BookSearchGetParam) (*dto.BookSearchGet, error) {
func searchInInventaireAPI(inventaireUrl string, searchterm string, limit int, offset int, params dto.BookSearchGetParam) (*dto.BookItemsGet, error) {
isIsbn, err := regexp.Match(`\d{10,13}`, []byte(searchterm))
if err != nil {
@@ -74,11 +74,11 @@ func searchInInventaireAPI(inventaireUrl string, searchterm string, limit int, o
if err != nil {
return nil, err
}
var bookSearchGet dto.BookSearchGet
var bookSearchGet dto.BookItemsGet
if queryResult != nil {
bookSearchGet = inventaireEditionToBookSearchGet(*queryResult)
} else {
bookSearchGet = dto.BookSearchGet{Count: 0, Inventaire: true}
bookSearchGet = dto.BookItemsGet{Count: 0, Inventaire: true}
}
return &bookSearchGet, err
} else {
@@ -91,9 +91,9 @@ func searchInInventaireAPI(inventaireUrl string, searchterm string, limit int, o
}
}
func inventaireEditionToBookSearchGet(result inventaire.InventaireEditionDetailedSingleResult) dto.BookSearchGet {
var books []dto.BookSearchGetBook
bookSearchGetBook := dto.BookSearchGetBook{
func inventaireEditionToBookSearchGet(result inventaire.InventaireEditionDetailedSingleResult) dto.BookItemsGet {
var books []dto.BookItemGet
bookSearchGetBook := dto.BookItemGet{
ID: 0,
Title: result.Title,
Author: result.Author.Name,
@@ -106,17 +106,17 @@ func inventaireEditionToBookSearchGet(result inventaire.InventaireEditionDetaile
CoverPath: result.Image,
}
books = append(books, bookSearchGetBook)
return dto.BookSearchGet{Count: 1, Inventaire: true, Books: books}
return dto.BookItemsGet{Count: 1, Inventaire: true, Books: books}
}
func inventaireBooksToBookSearchGet(inventaireUrl string, results inventaire.InventaireSearchResult) dto.BookSearchGet {
var books []dto.BookSearchGetBook
func inventaireBooksToBookSearchGet(inventaireUrl string, results inventaire.InventaireSearchResult) dto.BookItemsGet {
var books []dto.BookItemGet
for _, b := range results.Results {
coverPath := ""
if b.Image != "" && strings.HasPrefix(b.Image, "/") {
coverPath = inventaireUrl + b.Image
}
bookSearchGetBook := dto.BookSearchGetBook{
bookSearchGetBook := dto.BookItemGet{
ID: 0,
Title: b.Label,
Author: "",
@@ -129,5 +129,5 @@ func inventaireBooksToBookSearchGet(inventaireUrl string, results inventaire.Inv
}
books = append(books, bookSearchGetBook)
}
return dto.BookSearchGet{Count: results.Total, Inventaire: true, Books: books}
return dto.BookItemsGet{Count: results.Total, Inventaire: true, Books: books}
}