From 98c3b7f384eb455fcba5c1ca85ce5cfc331a29ec Mon Sep 17 00:00:00 2001 From: cpride Date: Wed, 22 Jan 2025 07:58:57 -0600 Subject: [PATCH] refactor: total activity time query --- backend/src/database/activity.go | 10 ++++------ frontend/src/Pages/AdminLayer2.tsx | 4 +--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/backend/src/database/activity.go b/backend/src/database/activity.go index d5053e30..30994c45 100644 --- a/backend/src/database/activity.go +++ b/backend/src/database/activity.go @@ -210,7 +210,7 @@ func (db *DB) GetTotalStudentsEnrolled(facilityID *uint) (int, error) { query = query.Where("u.facility_id = ?", facilityID) } - err := query.Debug().Find(&totalStudents).Error + err := query.Find(&totalStudents).Error if err != nil { return 0, NewDBError(err, "error getting total students enrolled") } @@ -219,11 +219,9 @@ func (db *DB) GetTotalStudentsEnrolled(facilityID *uint) (int, error) { func (db *DB) GetTotalHourlyActivity(facilityID *uint) (int, error) { var totalActivity int - subQry := db.Table("users u"). - Select("CASE WHEN SUM(a.total_time) IS NULL THEN 0 ELSE ROUND(SUM(a.total_time)/3600, 0) END AS total_time"). - Joins("LEFT JOIN activities a ON u.id = a.user_id"). - Where("u.role = ?", "student") - + subQry := db.Table("activities a"). + Select("COALESCE(ROUND(SUM(a.total_time)/3600, 0), 0) AS total_activity_time"). + Joins("INNER JOIN users u ON u.id = a.user_id") if facilityID != nil { subQry = subQry.Where("u.facility_id = ?", facilityID) } diff --git a/frontend/src/Pages/AdminLayer2.tsx b/frontend/src/Pages/AdminLayer2.tsx index ff172381..dc17daca 100644 --- a/frontend/src/Pages/AdminLayer2.tsx +++ b/frontend/src/Pages/AdminLayer2.tsx @@ -79,9 +79,7 @@ export default function AdminLayer2() { />