Added book summary

This commit is contained in:
2025-11-03 18:19:19 +01:00
parent 86229dfad8
commit 442068f2ed
5 changed files with 24 additions and 6 deletions

View File

@@ -75,7 +75,7 @@ INSERT INTO books(created_at, title, author, added_by_id, cover_id) VALUES ('NOW
INSERT INTO user_books(created_at, user_id, book_id, read, rating) VALUES ('NOW',(SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM books WHERE title = 'Vers le Phare'),true,6); INSERT INTO user_books(created_at, user_id, book_id, read, rating) VALUES ('NOW',(SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM books WHERE title = 'Vers le Phare'),true,6);
INSERT INTO books(created_at, title, author, added_by_id, cover_id) VALUES ('NOW', 'L''insoutenable légèreté de l''être', 'Milan Kundera', (SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM static_files WHERE name = 'insoutenablelégèretédeletre.jpg')); INSERT INTO books(created_at, title, author, added_by_id, cover_id) VALUES ('NOW', 'L''insoutenable légèreté de l''être', 'Milan Kundera', (SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM static_files WHERE name = 'insoutenablelégèretédeletre.jpg'));
INSERT INTO user_books(created_at, user_id, book_id, read, rating) VALUES ('NOW',(SELECT id FROM users WHERE name = 'demo2'),(SELECT id FROM books WHERE title = 'L''insoutenable légèreté de l''être'), true,8); INSERT INTO user_books(created_at, user_id, book_id, read, rating) VALUES ('NOW',(SELECT id FROM users WHERE name = 'demo2'),(SELECT id FROM books WHERE title = 'L''insoutenable légèreté de l''être'), true,8);
INSERT INTO books(created_at, title, author, added_by_id, cover_id) VALUES ('NOW', 'Le complot contre l''Amérique','Philip Roth', (SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM static_files WHERE name = 'lecomplotcontrelamerique.jpg')); INSERT INTO books(created_at, title, author, summary, added_by_id, cover_id) VALUES ('NOW', 'Le complot contre l''Amérique','Philip Roth', 'Lorsque le célèbre aviateur Charles Lindbergh battit le président Roosevelt aux élections présidentielles de 1940, la peur s''empara des Juifs américains. Non seulement Lindbergh avait, dans son discours radiophonique à la nation, reproché aux Juifs de pousser l''Amérique à entreprendre une guerre inutile avec l''Allemagne nazie, mais, en devenant trente-troisième président des États-Unis, il s''empressa de signer un pacte de non-agression avec Hitler. Alors la terreur pénétra dans les foyers juifs, notamment dans celui de la famille Roth. Ce contexte sert de décor historique au Complot contre l''Amérique, un roman où Philip Roth, qui avait sept ans à l''époque, raconte ce que vécut et ressentit sa famille - et des millions de familles semblables dans tout le pays - lors des lourdes années où s''exerça la présidence de Lindbergh, quand les citoyens américains qui étaient aussi des Juifs avaient de bonnes raisons de craindre le pire. Ce faisant, il nous offre un nouveau chef-d''oeuvre.', (SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM static_files WHERE name = 'lecomplotcontrelamerique.jpg'));
INSERT INTO user_books(created_at, user_id, book_id, read, rating) VALUES ('NOW',(SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM books WHERE title = 'Le complot contre l''Amérique'),true,6); INSERT INTO user_books(created_at, user_id, book_id, read, rating) VALUES ('NOW',(SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM books WHERE title = 'Le complot contre l''Amérique'),true,6);
INSERT INTO books(created_at, title, author, added_by_id, cover_id) VALUES ('NOW', 'Nord','Louis-Ferdinand Céline', (SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM static_files WHERE name = 'Nord.jpg')); INSERT INTO books(created_at, title, author, added_by_id, cover_id) VALUES ('NOW', 'Nord','Louis-Ferdinand Céline', (SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM static_files WHERE name = 'Nord.jpg'));
INSERT INTO user_books(created_at, user_id, book_id, read, rating) VALUES ('NOW',(SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM books WHERE title = 'Nord'),true, 10); INSERT INTO user_books(created_at, user_id, book_id, read, rating) VALUES ('NOW',(SELECT id FROM users WHERE name = 'demo'),(SELECT id FROM books WHERE title = 'Nord'),true, 10);

View File

@@ -43,6 +43,9 @@
active-color="bulma-body-color" active-color="bulma-body-color"
/> />
</div> </div>
<div>
<p>{{data.summary}}</p>
</div>
</div> </div>
</template> </template>

View File

@@ -12,10 +12,11 @@ import (
) )
type fetchedBook struct { type fetchedBook struct {
Title string `json:"title" binding:"required,max=300"` Title string `json:"title" binding:"required,max=300"`
Author string `json:"author" binding:"max=100"` Author string `json:"author" binding:"max=100"`
Rating int `json:"rating"` Summary string `json:"summary"`
Read bool `json:"read"` Rating int `json:"rating"`
Read bool `json:"read"`
} }
func TestGetBook_Ok(t *testing.T) { func TestGetBook_Ok(t *testing.T) {
@@ -39,6 +40,18 @@ func TestGetBook_NoUserBook(t *testing.T) {
}, book) }, book)
} }
func TestGetBook_Description(t *testing.T) {
book := testGetBook(t, "22", http.StatusOK)
assert.Equal(t,
fetchedBook{
Title: "Le complot contre l'Amérique",
Author: "Philip Roth",
Summary: "Lorsque le célèbre aviateur Charles Lindbergh battit le président Roosevelt aux élections présidentielles de 1940, la peur s'empara des Juifs américains. Non seulement Lindbergh avait, dans son discours radiophonique à la nation, reproché aux Juifs de pousser l'Amérique à entreprendre une guerre inutile avec l'Allemagne nazie, mais, en devenant trente-troisième président des États-Unis, il s'empressa de signer un pacte de non-agression avec Hitler. Alors la terreur pénétra dans les foyers juifs, notamment dans celui de la famille Roth. Ce contexte sert de décor historique au Complot contre l'Amérique, un roman où Philip Roth, qui avait sept ans à l'époque, raconte ce que vécut et ressentit sa famille - et des millions de familles semblables dans tout le pays - lors des lourdes années où s'exerça la présidence de Lindbergh, quand les citoyens américains qui étaient aussi des Juifs avaient de bonnes raisons de craindre le pire. Ce faisant, il nous offre un nouveau chef-d'oeuvre.",
Rating: 6,
Read: true,
}, book)
}
func TestGetBook_IdNotFound(t *testing.T) { func TestGetBook_IdNotFound(t *testing.T) {
testGetBook(t, "46544", http.StatusNotFound) testGetBook(t, "46544", http.StatusNotFound)
} }

View File

@@ -6,6 +6,7 @@ type Book struct {
gorm.Model gorm.Model
Title string `json:"title" gorm:"not null"` Title string `json:"title" gorm:"not null"`
Author string `json:"author"` Author string `json:"author"`
Summary string `json:"summary"`
AddedBy User AddedBy User
AddedByID uint AddedByID uint
Cover StaticFile Cover StaticFile

View File

@@ -11,6 +11,7 @@ import (
type BookGet struct { type BookGet struct {
Title string `json:"title" binding:"required,max=300"` Title string `json:"title" binding:"required,max=300"`
Author string `json:"author" binding:"max=100"` Author string `json:"author" binding:"max=100"`
Summary string `json:"summary"`
Rating int `json:"rating"` Rating int `json:"rating"`
Read bool `json:"read"` Read bool `json:"read"`
CoverPath string `json:"coverPath"` CoverPath string `json:"coverPath"`
@@ -19,7 +20,7 @@ type BookGet struct {
func FetchBookGet(db *gorm.DB, userId uint, bookId uint64) (BookGet, error) { func FetchBookGet(db *gorm.DB, userId uint, bookId uint64) (BookGet, error) {
var book BookGet var book BookGet
query := db.Model(&model.Book{}) query := db.Model(&model.Book{})
query = query.Select("books.title, books.author, user_books.rating, user_books.read, " + selectStaticFilesPath()) query = query.Select("books.title, books.author, books.summary, user_books.rating, user_books.read, " + selectStaticFilesPath())
query = query.Joins("left join user_books on (user_books.book_id = books.id and user_books.user_id = ?)", userId) query = query.Joins("left join user_books on (user_books.book_id = books.id and user_books.user_id = ?)", userId)
query = query.Joins("left join static_files on (static_files.id = books.cover_id)") query = query.Joins("left join static_files on (static_files.id = books.cover_id)")
query = query.Where("books.id = ?", bookId) query = query.Where("books.id = ?", bookId)