refactor(analyticsApi): fixed last_30_days_data (8)
Build and Push Docker image / build-and-push (push) Successful in 2m3s
Details
Build and Push Docker image / build-and-push (push) Successful in 2m3s
Details
This commit is contained in:
parent
0d5b976e97
commit
c8b8f9d93b
|
@ -1,7 +1,6 @@
|
||||||
package analyticsApi
|
package analyticsApi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"git.stuve.uni-ulm.de/stuve-it/stuve-it-backend/ldapApi"
|
"git.stuve.uni-ulm.de/stuve-it/stuve-it-backend/ldapApi"
|
||||||
"git.stuve.uni-ulm.de/stuve-it/stuve-it-backend/logger"
|
"git.stuve.uni-ulm.de/stuve-it/stuve-it-backend/logger"
|
||||||
"github.com/labstack/echo/v5"
|
"github.com/labstack/echo/v5"
|
||||||
|
@ -120,17 +119,11 @@ func initPageViewCount(app *pocketbase.PocketBase, e *core.ServeEvent) {
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Item struct {
|
|
||||||
Path string `json:"path"`
|
|
||||||
Count int `json:"count"`
|
|
||||||
Last30DaysData []Last30DaysData `json:"last_30_days_data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Query paginated items
|
// Query paginated items
|
||||||
var rawItems []struct {
|
var Items []struct {
|
||||||
Path string `db:"path" json:"path"`
|
Path string `db:"path" json:"path"`
|
||||||
Count int `db:"count" json:"count"`
|
Count int `db:"count" json:"count"`
|
||||||
Last30DaysData string `db:"last_30_days_data" json:"last_30_days_data"` // JSON string to parse
|
Last30DaysData []Last30DaysData `db:"last_30_days_data" json:"last_30_days_data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
err = app.Dao().DB().
|
err = app.Dao().DB().
|
||||||
|
@ -167,36 +160,19 @@ func initPageViewCount(app *pocketbase.PocketBase, e *core.ServeEvent) {
|
||||||
"perPage": perPage,
|
"perPage": perPage,
|
||||||
"offset": offset,
|
"offset": offset,
|
||||||
}).
|
}).
|
||||||
All(&rawItems)
|
All(&Items)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apis.NewApiError(500, "Failed to query page view data", err)
|
return apis.NewApiError(500, "Failed to query page view data", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse last_30_days_data JSON string into structured data
|
|
||||||
var items []Item
|
|
||||||
for _, rawItem := range rawItems {
|
|
||||||
var last30DaysData []Last30DaysData
|
|
||||||
if rawItem.Last30DaysData != "" {
|
|
||||||
if err := json.Unmarshal([]byte(rawItem.Last30DaysData), &last30DaysData); err != nil {
|
|
||||||
return apis.NewApiError(500, "Failed to parse last_30_days_data", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
items = append(items, Item{
|
|
||||||
Path: rawItem.Path,
|
|
||||||
Count: rawItem.Count,
|
|
||||||
Last30DaysData: last30DaysData,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Final response structure
|
// Final response structure
|
||||||
response := map[string]interface{}{
|
response := map[string]interface{}{
|
||||||
"page": page,
|
"page": page,
|
||||||
"perPage": perPage,
|
"perPage": perPage,
|
||||||
"totalItems": totalItems,
|
"totalItems": totalItems,
|
||||||
"totalPages": totalPages,
|
"totalPages": totalPages,
|
||||||
"items": items,
|
"items": Items,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the final JSON response
|
// Return the final JSON response
|
||||||
|
|
Loading…
Reference in New Issue