Add a view to see all books in a collection

This commit is contained in:
2026-04-03 22:57:45 +02:00
parent a5c4c0bbec
commit 625d2a2af1
20 changed files with 285 additions and 44 deletions

View File

@@ -10,7 +10,17 @@ import (
"gorm.io/gorm"
)
func CollectionQueryToDto(collectionsQueryResult []query.CollectionsQueryResult) []dto.CollectionItemGet {
func CollectionQueryToCollectionDto(collectionsQueryResult []query.CollectionsQueryResult) dto.CollectionGet {
var collection dto.CollectionGet
for _, collectionsDb := range collectionsQueryResult {
collection.Name = collectionsDb.Name
collection.Books = append(collection.Books, collectionDbToBookItem(&collectionsDb))
collection.UserID = collectionsDb.UserID
}
return collection
}
func CollectionQueryToCollectionItemDto(collectionsQueryResult []query.CollectionsQueryResult) []dto.CollectionItemGet {
var collections []dto.CollectionItemGet
for _, collectionDb := range collectionsQueryResult {
i := findIdInCollection(collections, collectionDb.ID)
@@ -22,15 +32,19 @@ func CollectionQueryToDto(collectionsQueryResult []query.CollectionsQueryResult)
//current collection is the last element
i = len(collections) - 1
}
collections[i].Books = append(collections[i].Books, dto.CollectionBookItemGet{
ID: collectionDb.BookId,
Title: collectionDb.BookTitle,
CoverPath: collectionDb.CoverPath,
})
collections[i].Books = append(collections[i].Books, collectionDbToBookItem(&collectionDb))
}
return collections
}
func collectionDbToBookItem(collectionDb *query.CollectionsQueryResult) dto.CollectionBookItemGet {
return dto.CollectionBookItemGet{
ID: collectionDb.BookId,
Title: collectionDb.BookTitle,
CoverPath: collectionDb.CoverPath,
}
}
// returns the position in collections, -1 if not found
func findIdInCollection(collections []dto.CollectionItemGet, collectionId uint) int {
for i, collection := range collections {