From 442068f2edcbc1407350b87b7be94082a10c6e22 Mon Sep 17 00:00:00 2001 From: Arthur Lefebvre Date: Mon, 3 Nov 2025 18:19:19 +0100 Subject: [PATCH] Added book summary --- demodata.sql | 2 +- front/src/BookForm.vue | 3 +++ internal/apitest/get_book_test.go | 21 +++++++++++++++++---- internal/model/book.go | 1 + internal/query/query.go | 3 ++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/demodata.sql b/demodata.sql index ee9e0de..87c5c25 100644 --- a/demodata.sql +++ b/demodata.sql @@ -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 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 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 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); diff --git a/front/src/BookForm.vue b/front/src/BookForm.vue index 63cfda6..ed44e04 100644 --- a/front/src/BookForm.vue +++ b/front/src/BookForm.vue @@ -43,6 +43,9 @@ active-color="bulma-body-color" /> +
+

{{data.summary}}

+
diff --git a/internal/apitest/get_book_test.go b/internal/apitest/get_book_test.go index 8ea5c5f..4f45401 100644 --- a/internal/apitest/get_book_test.go +++ b/internal/apitest/get_book_test.go @@ -12,10 +12,11 @@ import ( ) type fetchedBook struct { - Title string `json:"title" binding:"required,max=300"` - Author string `json:"author" binding:"max=100"` - Rating int `json:"rating"` - Read bool `json:"read"` + Title string `json:"title" binding:"required,max=300"` + Author string `json:"author" binding:"max=100"` + Summary string `json:"summary"` + Rating int `json:"rating"` + Read bool `json:"read"` } func TestGetBook_Ok(t *testing.T) { @@ -39,6 +40,18 @@ func TestGetBook_NoUserBook(t *testing.T) { }, 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) { testGetBook(t, "46544", http.StatusNotFound) } diff --git a/internal/model/book.go b/internal/model/book.go index a0acbaa..9fb5d43 100644 --- a/internal/model/book.go +++ b/internal/model/book.go @@ -6,6 +6,7 @@ type Book struct { gorm.Model Title string `json:"title" gorm:"not null"` Author string `json:"author"` + Summary string `json:"summary"` AddedBy User AddedByID uint Cover StaticFile diff --git a/internal/query/query.go b/internal/query/query.go index 5956e5b..8c87da6 100644 --- a/internal/query/query.go +++ b/internal/query/query.go @@ -11,6 +11,7 @@ import ( type BookGet struct { Title string `json:"title" binding:"required,max=300"` Author string `json:"author" binding:"max=100"` + Summary string `json:"summary"` Rating int `json:"rating"` Read bool `json:"read"` CoverPath string `json:"coverPath"` @@ -19,7 +20,7 @@ type BookGet struct { func FetchBookGet(db *gorm.DB, userId uint, bookId uint64) (BookGet, error) { var book BookGet 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 static_files on (static_files.id = books.cover_id)") query = query.Where("books.id = ?", bookId)