From b0b92f0e647e6200296561794a259ccfc374aeea Mon Sep 17 00:00:00 2001 From: valentinkolb Date: Wed, 13 Nov 2024 02:12:20 +0100 Subject: [PATCH] fix(analyticsApi): fixed last_30_days_data (5) --- analyticsApi/main.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/analyticsApi/main.go b/analyticsApi/main.go index e45ba03..82e2ca3 100644 --- a/analyticsApi/main.go +++ b/analyticsApi/main.go @@ -145,15 +145,20 @@ func initPageViewCount(app *pocketbase.PocketBase, e *core.ServeEvent) { ( SELECT json_group_array( json_object( - 'date', strftime('%Y-%m-%d', created), - 'count', COUNT(id) + 'date', date, + 'count', daily_count ) ) - FROM analyticsPageViews - WHERE - path = view.path AND - created >= datetime('now', '-30 days') - GROUP BY strftime('%Y-%m-%d', created) + FROM ( + SELECT + strftime('%Y-%m-%d', created) AS date, + COUNT(id) AS daily_count + FROM analyticsPageViews + WHERE + path = view.path AND + created >= datetime('now', '-30 days') + GROUP BY date + ) AS daily_data ) AS last_30_days_data FROM analyticsPageViews view @@ -192,14 +197,17 @@ func initPageViewCount(app *pocketbase.PocketBase, e *core.ServeEvent) { }) } - // Return the final JSON response - return c.JSON(200, map[string]interface{}{ + // Final response structure + response := map[string]interface{}{ "page": page, "perPage": perPage, "totalItems": totalItems, "totalPages": totalPages, "items": items, - }) + } + + // Return the final JSON response + return c.JSON(200, response) }, apis.ActivityLogger(app)) }