Rating a book will now remove it from the list

This commit is contained in:
2025-11-18 18:41:47 +01:00
parent 59f6635f1b
commit 4cbddfb15f
3 changed files with 16 additions and 0 deletions

View File

@@ -33,6 +33,19 @@ func TestPutRatingUserBooksHandler_RateNewBookMakeItRead(t *testing.T) {
assert.Equal(t, false, book.WantRead)
}
func TestPutRatingUserBooksHandler_RateWantedBook(t *testing.T) {
payload :=
`{
"rating": 6
}`
bookId := "2"
testPutRateUserBooks(t, payload, bookId, http.StatusOK)
book := testGetBook(t, bookId, http.StatusOK)
assert.Equal(t, 6, book.Rating)
assert.Equal(t, true, book.Read)
assert.Equal(t, false, book.WantRead)
}
func TestPutRatingUserBooksHandler_RatingTypeWrong(t *testing.T) {
payload :=
`{

View File

@@ -85,6 +85,8 @@ func PutRateUserBookHandler(ac appcontext.AppContext) {
//if rated, set to "read" (a rating = 0 means unrated)
if userbook.Rating > 0 {
userbook.Read = true
//if set to read, remove want read
userbook.WantRead = false
}
ac.Db.Save(&userbook)
ac.C.String(http.StatusOK, "Success")