diff options
| -rw-r--r-- | backend/handlers/map.go | 22 | ||||
| -rw-r--r-- | backend/models/models.go | 13 |
2 files changed, 29 insertions, 6 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 |
diff --git a/backend/models/models.go b/backend/models/models.go index 35929c1..e5d92fb 100644 --- a/backend/models/models.go +++ b/backend/models/models.go | |||
| @@ -64,12 +64,13 @@ type MapHistory struct { | |||
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | type MapRoute struct { | 66 | type MapRoute struct { |
| 67 | RouteID int `json:"route_id"` | 67 | RouteID int `json:"route_id"` |
| 68 | Category Category `json:"category"` | 68 | Category Category `json:"category"` |
| 69 | History MapHistory `json:"history"` | 69 | History MapHistory `json:"history"` |
| 70 | Rating float32 `json:"rating"` | 70 | Rating float32 `json:"rating"` |
| 71 | Description string `json:"description"` | 71 | CompletionCount int `json:"completion_count"` |
| 72 | Showcase string `json:"showcase"` | 72 | Description string `json:"description"` |
| 73 | Showcase string `json:"showcase"` | ||
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | type MapRecords struct { | 76 | type MapRecords struct { |