aboutsummaryrefslogtreecommitdiff
path: root/backend/handlers/map.go
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-09-22 17:46:07 +0300
committerGitHub <noreply@github.com>2023-09-22 17:46:07 +0300
commit9db6e532a55c4ebee45d1250134a8add18bf837b (patch)
treef57e2fa61d2d575b72a6d0a489f48cd5df4e2f76 /backend/handlers/map.go
parentquicker summary fix (#53) (diff)
downloadlphub-9db6e532a55c4ebee45d1250134a8add18bf837b.tar.gz
lphub-9db6e532a55c4ebee45d1250134a8add18bf837b.tar.bz2
lphub-9db6e532a55c4ebee45d1250134a8add18bf837b.zip
feat: completion count on summary for each cm entry (#63)
Former-commit-id: 38779e7cbddb7e850a5f4a56565938b3dcb14857
Diffstat (limited to 'backend/handlers/map.go')
-rw-r--r--backend/handlers/map.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/backend/handlers/map.go b/backend/handlers/map.go
index 2a060e6..e55dab4 100644
--- a/backend/handlers/map.go
+++ b/backend/handlers/map.go
@@ -101,6 +101,28 @@ func FetchMapSummary(c *gin.Context) {
101 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 101 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
102 return 102 return
103 } 103 }
104 // Get completion count
105 if response.Map.IsCoop {
106 sql = `SELECT count(*) FROM ( SELECT host_id, partner_id, score_count, score_time,
107 ROW_NUMBER() OVER (PARTITION BY host_id, partner_id ORDER BY score_count, score_time) AS rn
108 FROM records_mp WHERE map_id = $1
109 ) sub WHERE sub.rn = 1 AND score_count = $2`
110 err = database.DB.QueryRow(sql, response.Map.ID, route.History.ScoreCount).Scan(&route.CompletionCount)
111 if err != nil {
112 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
113 return
114 }
115 } else {
116 sql = `SELECT count(*) FROM ( SELECT user_id, score_count, score_time,
117 ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY score_count, score_time) AS rn
118 FROM records_sp WHERE map_id = $1
119 ) sub WHERE rn = 1 AND score_count = $2`
120 err = database.DB.QueryRow(sql, response.Map.ID, route.History.ScoreCount).Scan(&route.CompletionCount)
121 if err != nil {
122 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
123 return
124 }
125 }
104 response.Summary.Routes = append(response.Summary.Routes, route) 126 response.Summary.Routes = append(response.Summary.Routes, route)
105 } 127 }
106 // Return response 128 // Return response