User book API: use a single query with result and count

This commit is contained in:
2026-01-25 00:42:50 +01:00
parent cd2b8a93bb
commit 8584e95ef7
15 changed files with 63 additions and 161 deletions

View File

@@ -12,18 +12,20 @@ func TestGetWantReadBooksHandler_Demo(t *testing.T) {
router := testutils.TestSetup()
token := testutils.ConnectDemoUser(router)
books := testGetWantReadBooksHandler(t, router, token, 200)
assert.Equal(t, 2, len(books))
result := testGetWantReadBooksHandler(t, router, token, 200)
assert.Equal(t, 2, len(result.Books))
assert.Equal(t, int64(2), result.Count)
}
func TestGetWantReadBooksHandler_Demo2(t *testing.T) {
router := testutils.TestSetup()
token := testutils.ConnectDemo2User(router)
books := testGetWantReadBooksHandler(t, router, token, 200)
assert.Equal(t, 0, len(books))
result := testGetWantReadBooksHandler(t, router, token, 200)
assert.Equal(t, 0, len(result.Books))
assert.Equal(t, int64(0), result.Count)
}
func testGetWantReadBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int) []bookUserGet {
func testGetWantReadBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int) bookUserGet {
return testGetbooksHandler(t, router, userToken, expectedCode, "/mybooks/wantread")
}