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

@@ -13,19 +13,21 @@ func TestGetReadingBooksHandler_Demo(t *testing.T) {
router := testutils.TestSetup()
token := testutils.ConnectDemoUser(router)
books := testGetReadingBooksHandler(t, router, token, 200, "", "")
assert.Equal(t, 2, len(books))
result := testGetReadingBooksHandler(t, router, token, 200, "", "")
assert.Equal(t, 2, len(result.Books))
assert.Equal(t, int64(2), result.Count)
}
func TestGetReadingBooksHandler_Demo2(t *testing.T) {
router := testutils.TestSetup()
token := testutils.ConnectDemo2User(router)
books := testGetReadingBooksHandler(t, router, token, 200, "", "")
assert.Equal(t, 0, len(books))
result := testGetReadingBooksHandler(t, router, token, 200, "", "")
assert.Equal(t, 0, len(result.Books))
assert.Equal(t, int64(0), result.Count)
}
func testGetReadingBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, limit string, offset string) []bookUserGet {
func testGetReadingBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, limit string, offset string) bookUserGet {
u, err := url.Parse("/mybooks/reading")
if err != nil {
t.Error(err)