Fixed issue where querying empty collection returns an empty book record
This commit is contained in:
@@ -14,7 +14,10 @@ func CollectionQueryToCollectionDto(collectionsQueryResult []query.CollectionsQu
|
||||
var collection dto.CollectionGet
|
||||
for _, collectionsDb := range collectionsQueryResult {
|
||||
collection.Name = collectionsDb.Name
|
||||
collection.Books = append(collection.Books, collectionDbToBookItem(&collectionsDb))
|
||||
book := collectionDbToBookItem(&collectionsDb)
|
||||
if book != nil {
|
||||
collection.Books = append(collection.Books, *book)
|
||||
}
|
||||
collection.UserID = collectionsDb.UserID
|
||||
}
|
||||
return collection
|
||||
@@ -32,16 +35,24 @@ func CollectionQueryToCollectionItemDto(collectionsQueryResult []query.Collectio
|
||||
//current collection is the last element
|
||||
i = len(collections) - 1
|
||||
}
|
||||
collections[i].Books = append(collections[i].Books, collectionDbToBookItem(&collectionDb))
|
||||
book := collectionDbToBookItem(&collectionDb)
|
||||
if book != nil {
|
||||
collections[i].Books = append(collections[i].Books, *book)
|
||||
}
|
||||
}
|
||||
return collections
|
||||
}
|
||||
|
||||
func collectionDbToBookItem(collectionDb *query.CollectionsQueryResult) dto.CollectionBookItemGet {
|
||||
return dto.CollectionBookItemGet{
|
||||
ID: collectionDb.BookId,
|
||||
Title: collectionDb.BookTitle,
|
||||
CoverPath: collectionDb.CoverPath,
|
||||
func collectionDbToBookItem(collectionDb *query.CollectionsQueryResult) *dto.CollectionBookItemGet {
|
||||
if collectionDb.BookId > 0 {
|
||||
bookItem := dto.CollectionBookItemGet{
|
||||
ID: collectionDb.BookId,
|
||||
Title: collectionDb.BookTitle,
|
||||
CoverPath: collectionDb.CoverPath,
|
||||
}
|
||||
return &bookItem
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user