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

@@ -22,6 +22,7 @@
data.value.rating = rating * 2; data.value.rating = rating * 2;
if (data.value.rating > 0) { if (data.value.rating > 0) {
data.value.read = true; data.value.read = true;
data.value.wantread = false;
} }
putRateBook(props.id, {rating: data.value.rating}); putRateBook(props.id, {rating: data.value.rating});
} }

View File

@@ -33,6 +33,19 @@ func TestPutRatingUserBooksHandler_RateNewBookMakeItRead(t *testing.T) {
assert.Equal(t, false, book.WantRead) 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) { func TestPutRatingUserBooksHandler_RatingTypeWrong(t *testing.T) {
payload := payload :=
`{ `{

View File

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