From bc077f176e0565f9d274dfac22266be2ed96e654 Mon Sep 17 00:00:00 2001 From: Arthur Lefebvre Date: Thu, 26 Mar 2026 20:17:21 +0100 Subject: [PATCH] Start reading cancel read: move logic to backend --- front/src/BookForm.vue | 1 - front/src/BookListElement.vue | 9 ++------- internal/apitest/put_userbook_test.go | 12 ++++++++++++ internal/routes/userbookputupdate.go | 1 + 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/front/src/BookForm.vue b/front/src/BookForm.vue index f9aaf75..e0289c7 100644 --- a/front/src/BookForm.vue +++ b/front/src/BookForm.vue @@ -72,7 +72,6 @@ async function onStartReadIconClick() { } if (data.value.read) { data.value.read = false - putUnreadBook(props.id) } } diff --git a/front/src/BookListElement.vue b/front/src/BookListElement.vue index 6e40156..41e24a0 100644 --- a/front/src/BookListElement.vue +++ b/front/src/BookListElement.vue @@ -86,17 +86,12 @@ async function onUserBookStartRead() { async function userBookStartRead() { const res = await putStartRead(props.id) - if (!res.ok) { - res.json().then((json) => (error.value = json)) - return - } - const resp = await putUnreadBook(props.id) - if (resp.ok) { + if (res.ok) { currentStartReadDate.value = today isRead.value = false isWantRead.value = false } else { - resp.json().then((json) => (error.value = json)) + res.json().then((json) => (error.value = json)) } } diff --git a/internal/apitest/put_userbook_test.go b/internal/apitest/put_userbook_test.go index 854ff19..45da960 100644 --- a/internal/apitest/put_userbook_test.go +++ b/internal/apitest/put_userbook_test.go @@ -153,6 +153,18 @@ func TestPutStartReadUserBooks_UnsetWantReadOk(t *testing.T) { assert.Equal(t, false, book.WantRead) } +func TestPutStartReadUserBooks_UnsetReadOk(t *testing.T) { + payload := + `{ + "startDate": "2025-12-20" + }` + bookId := "13" + testPutUserBooks(t, payload, bookId, http.StatusOK) + book := testGetBook(t, bookId, http.StatusOK) + assert.Equal(t, "2025-12-20", book.StartReadDate) + assert.Equal(t, false, book.Read) +} + func TestPutStartReadUserBooks_Unset(t *testing.T) { payload := `{ diff --git a/internal/routes/userbookputupdate.go b/internal/routes/userbookputupdate.go index 129a420..eb16410 100644 --- a/internal/routes/userbookputupdate.go +++ b/internal/routes/userbookputupdate.go @@ -63,6 +63,7 @@ func PutUserBookHandler(ac appcontext.AppContext) { return } if d != nil { + userbook.Read = false userbook.WantRead = false } userbook.StartReadDate = d