diff options
Diffstat (limited to 'backend/handlers')
| -rw-r--r-- | backend/handlers/map.go | 11 | ||||
| -rw-r--r-- | backend/handlers/mod.go | 86 | ||||
| -rw-r--r-- | backend/handlers/user.go | 24 |
3 files changed, 31 insertions, 90 deletions
diff --git a/backend/handlers/map.go b/backend/handlers/map.go index f2ea8ac..bf7c821 100644 --- a/backend/handlers/map.go +++ b/backend/handlers/map.go | |||
| @@ -87,12 +87,11 @@ func FetchMapSummary(c *gin.Context) { | |||
| 87 | return | 87 | return |
| 88 | } | 88 | } |
| 89 | // Get map routes and histories | 89 | // Get map routes and histories |
| 90 | sql = `SELECT r.id, c.id, c.name, h.user_name, h.score_count, h.record_date, r.description, r.showcase, COALESCE(avg(rating), 0.0) FROM map_routes r | 90 | sql = `SELECT mh.id, c.id, c.name, mh.user_name, mh.score_count, mh.record_date, mh.description, mh.showcase, COALESCE(avg(rating), 0.0) FROM map_history mh |
| 91 | INNER JOIN categories c ON r.category_id = c.id | 91 | INNER JOIN categories c ON mh.category_id = c.id |
| 92 | INNER JOIN map_history h ON r.map_id = h.map_id AND r.category_id = h.category_id | 92 | LEFT JOIN map_ratings rt ON mh.map_id = rt.map_id AND mh.category_id = rt.category_id |
| 93 | LEFT JOIN map_ratings rt ON r.map_id = rt.map_id AND r.category_id = rt.category_id | 93 | WHERE mh.map_id = $1 AND mh.score_count = mh.score_count GROUP BY mh.id, c.id, mh.user_name, mh.score_count, mh.record_date, mh.description, mh.showcase |
| 94 | WHERE r.map_id = $1 AND h.score_count = r.score_count GROUP BY r.id, c.id, h.user_name, h.score_count, h.record_date, r.description, r.showcase | 94 | ORDER BY mh.record_date ASC;` |
| 95 | ORDER BY h.record_date ASC;` | ||
| 96 | rows, err := database.DB.Query(sql, id) | 95 | rows, err := database.DB.Query(sql, id) |
| 97 | if err != nil { | 96 | if err != nil { |
| 98 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 97 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
diff --git a/backend/handlers/mod.go b/backend/handlers/mod.go index 3709e1d..72a9fd8 100644 --- a/backend/handlers/mod.go +++ b/backend/handlers/mod.go | |||
| @@ -16,7 +16,7 @@ type CreateMapSummaryRequest struct { | |||
| 16 | Description string `json:"description" binding:"required"` | 16 | Description string `json:"description" binding:"required"` |
| 17 | Showcase string `json:"showcase"` | 17 | Showcase string `json:"showcase"` |
| 18 | UserName string `json:"user_name" binding:"required"` | 18 | UserName string `json:"user_name" binding:"required"` |
| 19 | ScoreCount *int `json:"score_count"` | 19 | ScoreCount int `json:"score_count" binding:"required"` |
| 20 | RecordDate time.Time `json:"record_date" binding:"required"` | 20 | RecordDate time.Time `json:"record_date" binding:"required"` |
| 21 | } | 21 | } |
| 22 | 22 | ||
| @@ -25,7 +25,7 @@ type EditMapSummaryRequest struct { | |||
| 25 | Description string `json:"description" binding:"required"` | 25 | Description string `json:"description" binding:"required"` |
| 26 | Showcase string `json:"showcase"` | 26 | Showcase string `json:"showcase"` |
| 27 | UserName string `json:"user_name" binding:"required"` | 27 | UserName string `json:"user_name" binding:"required"` |
| 28 | ScoreCount int `json:"score_count"` | 28 | ScoreCount int `json:"score_count" binding:"required"` |
| 29 | RecordDate time.Time `json:"record_date" binding:"required"` | 29 | RecordDate time.Time `json:"record_date" binding:"required"` |
| 30 | } | 30 | } |
| 31 | 31 | ||
| @@ -93,17 +93,9 @@ func CreateMapSummary(c *gin.Context) { | |||
| 93 | return | 93 | return |
| 94 | } | 94 | } |
| 95 | // Update database with new data | 95 | // Update database with new data |
| 96 | sql = `INSERT INTO map_routes (map_id,category_id,score_count,description,showcase) | 96 | sql = `INSERT INTO map_history (map_id,category_id,user_name,score_count,description,showcase,record_date) |
| 97 | VALUES ($1,$2,$3,$4,$5)` | 97 | VALUES ($1,$2,$3,$4,$5)` |
| 98 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.ScoreCount, request.Description, request.Showcase) | 98 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.Description, request.Showcase, request.RecordDate) |
| 99 | if err != nil { | ||
| 100 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, fmt.Sprintf("INSERT#map_routes: %s", err.Error())) | ||
| 101 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 102 | return | ||
| 103 | } | ||
| 104 | sql = `INSERT INTO map_history (map_id,category_id,user_name,score_count,record_date) | ||
| 105 | VALUES ($1,$2,$3,$4,$5)` | ||
| 106 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.RecordDate) | ||
| 107 | if err != nil { | 99 | if err != nil { |
| 108 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, fmt.Sprintf("INSERT#map_history: %s", err.Error())) | 100 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, fmt.Sprintf("INSERT#map_history: %s", err.Error())) |
| 109 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 101 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| @@ -113,7 +105,7 @@ func CreateMapSummary(c *gin.Context) { | |||
| 113 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 105 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 114 | return | 106 | return |
| 115 | } | 107 | } |
| 116 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, request.CategoryID, *request.ScoreCount)) | 108 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, request.CategoryID, request.ScoreCount)) |
| 117 | c.JSON(http.StatusOK, models.Response{ | 109 | c.JSON(http.StatusOK, models.Response{ |
| 118 | Success: true, | 110 | Success: true, |
| 119 | Message: "Successfully created map summary.", | 111 | Message: "Successfully created map summary.", |
| @@ -145,7 +137,8 @@ func EditMapSummary(c *gin.Context) { | |||
| 145 | } | 137 | } |
| 146 | // Bind parameter and body | 138 | // Bind parameter and body |
| 147 | id := c.Param("mapid") | 139 | id := c.Param("mapid") |
| 148 | mapID, err := strconv.Atoi(id) | 140 | // we get mapid in path parameters, but it's not really used anywhere here lol. |
| 141 | _, err := strconv.Atoi(id) | ||
| 149 | if err != nil { | 142 | if err != nil { |
| 150 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 143 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 151 | return | 144 | return |
| @@ -163,34 +156,11 @@ func EditMapSummary(c *gin.Context) { | |||
| 163 | return | 156 | return |
| 164 | } | 157 | } |
| 165 | defer tx.Rollback() | 158 | defer tx.Rollback() |
| 166 | // Fetch route category and score count | ||
| 167 | var categoryID, scoreCount, historyID int | ||
| 168 | sql := `SELECT mr.category_id, mr.score_count FROM map_routes mr INNER JOIN maps m ON m.id = mr.map_id WHERE m.id = $1 AND mr.id = $2` | ||
| 169 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) | ||
| 170 | if err != nil { | ||
| 171 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(RouteID: %d) SELECT#map_routes: %s", request.RouteID, err.Error())) | ||
| 172 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 173 | return | ||
| 174 | } | ||
| 175 | sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3` | ||
| 176 | err = database.DB.QueryRow(sql, scoreCount, categoryID, mapID).Scan(&historyID) | ||
| 177 | if err != nil { | ||
| 178 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(RouteID: %d) SELECT#map_history: %s", request.RouteID, err.Error())) | ||
| 179 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 180 | return | ||
| 181 | } | ||
| 182 | // Update database with new data | 159 | // Update database with new data |
| 183 | sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` | 160 | sql := `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4, description = $5, showcase = $6 WHERE id = $1` |
| 184 | _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) | 161 | _, err = tx.Exec(sql, request.RouteID, request.UserName, request.ScoreCount, request.RecordDate, request.Description, request.Showcase) |
| 185 | if err != nil { | ||
| 186 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(RouteID: %d) UPDATE#map_routes: %s", request.RouteID, err.Error())) | ||
| 187 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 188 | return | ||
| 189 | } | ||
| 190 | sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1` | ||
| 191 | _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate) | ||
| 192 | if err != nil { | 162 | if err != nil { |
| 193 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(HistoryID: %d) UPDATE#map_history: %s", historyID, err.Error())) | 163 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(HistoryID: %d) UPDATE#map_history: %s", request.RouteID, err.Error())) |
| 194 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 164 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 195 | return | 165 | return |
| 196 | } | 166 | } |
| @@ -198,7 +168,6 @@ func EditMapSummary(c *gin.Context) { | |||
| 198 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 168 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 199 | return | 169 | return |
| 200 | } | 170 | } |
| 201 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, categoryID, scoreCount)) | ||
| 202 | c.JSON(http.StatusOK, models.Response{ | 171 | c.JSON(http.StatusOK, models.Response{ |
| 203 | Success: true, | 172 | Success: true, |
| 204 | Message: "Successfully updated map summary.", | 173 | Message: "Successfully updated map summary.", |
| @@ -230,7 +199,8 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 230 | } | 199 | } |
| 231 | // Bind parameter and body | 200 | // Bind parameter and body |
| 232 | id := c.Param("mapid") | 201 | id := c.Param("mapid") |
| 233 | mapID, err := strconv.Atoi(id) | 202 | // we get mapid in path parameters, but it's not really used anywhere here lol. |
| 203 | _, err := strconv.Atoi(id) | ||
| 234 | if err != nil { | 204 | if err != nil { |
| 235 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 205 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 236 | return | 206 | return |
| @@ -248,38 +218,11 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 248 | return | 218 | return |
| 249 | } | 219 | } |
| 250 | defer tx.Rollback() | 220 | defer tx.Rollback() |
| 251 | // Fetch route category and score count | ||
| 252 | var checkMapID, scoreCount, categoryID, mapHistoryID int | ||
| 253 | sql := `SELECT m.id, mr.score_count, mr.category_id FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id WHERE m.id = $1 AND mr.id = $2` | ||
| 254 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&checkMapID, &scoreCount, &categoryID) | ||
| 255 | if err != nil { | ||
| 256 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(RouteID: %d) SELECT#map_routes: %s", request.RouteID, err.Error())) | ||
| 257 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 258 | return | ||
| 259 | } | ||
| 260 | if mapID != checkMapID { | ||
| 261 | c.JSON(http.StatusOK, models.ErrorResponse("Map ID does not exist.")) | ||
| 262 | return | ||
| 263 | } | ||
| 264 | sql = `SELECT mh.id FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id INNER JOIN map_history mh ON m.id=mh.map_id WHERE m.id = $1 AND mh.category_id = $2 AND mh.score_count = $3` | ||
| 265 | err = database.DB.QueryRow(sql, mapID, categoryID, scoreCount).Scan(&mapHistoryID) | ||
| 266 | if err != nil { | ||
| 267 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(RouteID: %d) SELECT#map_history: %s", request.RouteID, err.Error())) | ||
| 268 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 269 | return | ||
| 270 | } | ||
| 271 | // Update database with new data | 221 | // Update database with new data |
| 272 | sql = `DELETE FROM map_routes mr WHERE mr.id = $1 ` | 222 | sql := `DELETE FROM map_history mh WHERE mh.id = $1` |
| 273 | _, err = tx.Exec(sql, request.RouteID) | 223 | _, err = tx.Exec(sql, request.RouteID) |
| 274 | if err != nil { | 224 | if err != nil { |
| 275 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(RouteID: %d) DELETE#map_routes: %s", request.RouteID, err.Error())) | 225 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(HistoryID: %d) DELETE#map_history: %s", request.RouteID, err.Error())) |
| 276 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 277 | return | ||
| 278 | } | ||
| 279 | sql = `DELETE FROM map_history mh WHERE mh.id = $1` | ||
| 280 | _, err = tx.Exec(sql, mapHistoryID) | ||
| 281 | if err != nil { | ||
| 282 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(HistoryID: %d) DELETE#map_history: %s", mapHistoryID, err.Error())) | ||
| 283 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 226 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 284 | return | 227 | return |
| 285 | } | 228 | } |
| @@ -287,7 +230,6 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 287 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 230 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 288 | return | 231 | return |
| 289 | } | 232 | } |
| 290 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, categoryID, scoreCount)) | ||
| 291 | c.JSON(http.StatusOK, models.Response{ | 233 | c.JSON(http.StatusOK, models.Response{ |
| 292 | Success: true, | 234 | Success: true, |
| 293 | Message: "Successfully delete map summary.", | 235 | Message: "Successfully delete map summary.", |
diff --git a/backend/handlers/user.go b/backend/handlers/user.go index 88bbe45..8febf3a 100644 --- a/backend/handlers/user.go +++ b/backend/handlers/user.go | |||
| @@ -99,15 +99,15 @@ func Profile(c *gin.Context) { | |||
| 99 | // Get user completion count | 99 | // Get user completion count |
| 100 | sql = `SELECT 'records_sp' AS table_name, COUNT(sp.id) | 100 | sql = `SELECT 'records_sp' AS table_name, COUNT(sp.id) |
| 101 | FROM records_sp sp JOIN ( | 101 | FROM records_sp sp JOIN ( |
| 102 | SELECT mr.map_id, MIN(mr.score_count) AS min_score_count | 102 | SELECT mh.map_id, MIN(mh.score_count) AS min_score_count |
| 103 | FROM public.map_routes mr WHERE mr.category_id = 1 GROUP BY mr.map_id | 103 | FROM public.map_history mh WHERE mh.category_id = 1 GROUP BY mh.map_id |
| 104 | ) AS subquery_sp ON sp.map_id = subquery_sp.map_id AND sp.score_count = subquery_sp.min_score_count | 104 | ) AS subquery_sp ON sp.map_id = subquery_sp.map_id AND sp.score_count = subquery_sp.min_score_count |
| 105 | WHERE sp.user_id = $1 AND sp.is_deleted = false | 105 | WHERE sp.user_id = $1 AND sp.is_deleted = false |
| 106 | UNION ALL | 106 | UNION ALL |
| 107 | SELECT 'records_mp' AS table_name, COUNT(mp.id) | 107 | SELECT 'records_mp' AS table_name, COUNT(mp.id) |
| 108 | FROM public.records_mp mp JOIN ( | 108 | FROM public.records_mp mp JOIN ( |
| 109 | SELECT mr.map_id, MIN(mr.score_count) AS min_score_count | 109 | SELECT mh.map_id, MIN(mh.score_count) AS min_score_count |
| 110 | FROM public.map_routes mr WHERE mr.category_id = 1 GROUP BY mr.map_id | 110 | FROM public.map_history mh WHERE mh.category_id = 1 GROUP BY mh.map_id |
| 111 | ) AS subquery_mp ON mp.map_id = subquery_mp.map_id AND mp.score_count = subquery_mp.min_score_count | 111 | ) AS subquery_mp ON mp.map_id = subquery_mp.map_id AND mp.score_count = subquery_mp.min_score_count |
| 112 | WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false` | 112 | WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false` |
| 113 | rows, err := database.DB.Query(sql, user.(models.User).SteamID) | 113 | rows, err := database.DB.Query(sql, user.(models.User).SteamID) |
| @@ -293,7 +293,7 @@ func Profile(c *gin.Context) { | |||
| 293 | } | 293 | } |
| 294 | records := []ProfileRecords{} | 294 | records := []ProfileRecords{} |
| 295 | // Get singleplayer records | 295 | // Get singleplayer records |
| 296 | sql = `SELECT sp.id, m.game_id, m.chapter_id, sp.map_id, m."name", (SELECT mr.score_count FROM map_routes mr WHERE mr.map_id = sp.map_id ORDER BY mr.score_count ASC LIMIT 1) AS wr_count, sp.score_count, sp.score_time, sp.demo_id, sp.record_date | 296 | sql = `SELECT sp.id, m.game_id, m.chapter_id, sp.map_id, m."name", (SELECT mh.score_count FROM map_history mh WHERE mh.map_id = sp.map_id ORDER BY mh.score_count ASC LIMIT 1) AS wr_count, sp.score_count, sp.score_time, sp.demo_id, sp.record_date |
| 297 | FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 AND sp.is_deleted = false ORDER BY sp.map_id, sp.score_count, sp.score_time` | 297 | FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 AND sp.is_deleted = false ORDER BY sp.map_id, sp.score_count, sp.score_time` |
| 298 | rows, err = database.DB.Query(sql, user.(models.User).SteamID) | 298 | rows, err = database.DB.Query(sql, user.(models.User).SteamID) |
| 299 | if err != nil { | 299 | if err != nil { |
| @@ -347,7 +347,7 @@ func Profile(c *gin.Context) { | |||
| 347 | records[len(records)-1].Scores = append(records[len(records)-1].Scores, score) | 347 | records[len(records)-1].Scores = append(records[len(records)-1].Scores, score) |
| 348 | } | 348 | } |
| 349 | // Get multiplayer records | 349 | // Get multiplayer records |
| 350 | sql = `SELECT mp.id, m.game_id, m.chapter_id, mp.map_id, m."name", (SELECT mr.score_count FROM map_routes mr WHERE mr.map_id = mp.map_id ORDER BY mr.score_count ASC LIMIT 1) AS wr_count, mp.score_count, mp.score_time, CASE WHEN host_id = $1 THEN mp.host_demo_id WHEN partner_id = $1 THEN mp.partner_demo_id END demo_id, mp.record_date | 350 | sql = `SELECT mp.id, m.game_id, m.chapter_id, mp.map_id, m."name", (SELECT mh.score_count FROM map_history mh WHERE mh.map_id = mp.map_id ORDER BY mh.score_count ASC LIMIT 1) AS wr_count, mp.score_count, mp.score_time, CASE WHEN host_id = $1 THEN mp.host_demo_id WHEN partner_id = $1 THEN mp.partner_demo_id END demo_id, mp.record_date |
| 351 | FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false ORDER BY mp.map_id, mp.score_count, mp.score_time` | 351 | FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false ORDER BY mp.map_id, mp.score_count, mp.score_time` |
| 352 | rows, err = database.DB.Query(sql, user.(models.User).SteamID) | 352 | rows, err = database.DB.Query(sql, user.(models.User).SteamID) |
| 353 | if err != nil { | 353 | if err != nil { |
| @@ -473,15 +473,15 @@ func FetchUser(c *gin.Context) { | |||
| 473 | // Get user completion count | 473 | // Get user completion count |
| 474 | sql = `SELECT 'records_sp' AS table_name, COUNT(sp.id) | 474 | sql = `SELECT 'records_sp' AS table_name, COUNT(sp.id) |
| 475 | FROM records_sp sp JOIN ( | 475 | FROM records_sp sp JOIN ( |
| 476 | SELECT mr.map_id, MIN(mr.score_count) AS min_score_count | 476 | SELECT mh.map_id, MIN(mh.score_count) AS min_score_count |
| 477 | FROM public.map_routes mr WHERE mr.category_id = 1 GROUP BY mr.map_id | 477 | FROM public.map_history mh WHERE mh.category_id = 1 GROUP BY mh.map_id |
| 478 | ) AS subquery_sp ON sp.map_id = subquery_sp.map_id AND sp.score_count = subquery_sp.min_score_count | 478 | ) AS subquery_sp ON sp.map_id = subquery_sp.map_id AND sp.score_count = subquery_sp.min_score_count |
| 479 | WHERE sp.user_id = $1 AND sp.is_deleted = false | 479 | WHERE sp.user_id = $1 AND sp.is_deleted = false |
| 480 | UNION ALL | 480 | UNION ALL |
| 481 | SELECT 'records_mp' AS table_name, COUNT(mp.id) | 481 | SELECT 'records_mp' AS table_name, COUNT(mp.id) |
| 482 | FROM public.records_mp mp JOIN ( | 482 | FROM public.records_mp mp JOIN ( |
| 483 | SELECT mr.map_id, MIN(mr.score_count) AS min_score_count | 483 | SELECT mh.map_id, MIN(mh.score_count) AS min_score_count |
| 484 | FROM public.map_routes mr WHERE mr.category_id = 1 GROUP BY mr.map_id | 484 | FROM public.map_history mh WHERE mh.category_id = 1 GROUP BY mh.map_id |
| 485 | ) AS subquery_mp ON mp.map_id = subquery_mp.map_id AND mp.score_count = subquery_mp.min_score_count | 485 | ) AS subquery_mp ON mp.map_id = subquery_mp.map_id AND mp.score_count = subquery_mp.min_score_count |
| 486 | WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false` | 486 | WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false` |
| 487 | rows, err = database.DB.Query(sql, user.SteamID) | 487 | rows, err = database.DB.Query(sql, user.SteamID) |
| @@ -667,7 +667,7 @@ func FetchUser(c *gin.Context) { | |||
| 667 | } | 667 | } |
| 668 | records := []ProfileRecords{} | 668 | records := []ProfileRecords{} |
| 669 | // Get singleplayer records | 669 | // Get singleplayer records |
| 670 | sql = `SELECT sp.id, m.game_id, m.chapter_id, sp.map_id, m."name", (SELECT mr.score_count FROM map_routes mr WHERE mr.map_id = sp.map_id ORDER BY mr.score_count ASC LIMIT 1) AS wr_count, sp.score_count, sp.score_time, sp.demo_id, sp.record_date | 670 | sql = `SELECT sp.id, m.game_id, m.chapter_id, sp.map_id, m."name", (SELECT mh.score_count FROM map_history mh WHERE mh.map_id = sp.map_id ORDER BY mh.score_count ASC LIMIT 1) AS wr_count, sp.score_count, sp.score_time, sp.demo_id, sp.record_date |
| 671 | FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 AND sp.is_deleted = false ORDER BY sp.map_id, sp.score_count, sp.score_time` | 671 | FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 AND sp.is_deleted = false ORDER BY sp.map_id, sp.score_count, sp.score_time` |
| 672 | rows, err = database.DB.Query(sql, user.SteamID) | 672 | rows, err = database.DB.Query(sql, user.SteamID) |
| 673 | if err != nil { | 673 | if err != nil { |
| @@ -721,7 +721,7 @@ func FetchUser(c *gin.Context) { | |||
| 721 | records[len(records)-1].Scores = append(records[len(records)-1].Scores, score) | 721 | records[len(records)-1].Scores = append(records[len(records)-1].Scores, score) |
| 722 | } | 722 | } |
| 723 | // Get multiplayer records | 723 | // Get multiplayer records |
| 724 | sql = `SELECT mp.id, m.game_id, m.chapter_id, mp.map_id, m."name", (SELECT mr.score_count FROM map_routes mr WHERE mr.map_id = mp.map_id ORDER BY mr.score_count ASC LIMIT 1) AS wr_count, mp.score_count, mp.score_time, CASE WHEN host_id = $1 THEN mp.host_demo_id WHEN partner_id = $1 THEN mp.partner_demo_id END demo_id, mp.record_date | 724 | sql = `SELECT mp.id, m.game_id, m.chapter_id, mp.map_id, m."name", (SELECT mh.score_count FROM map_history mh WHERE mh.map_id = mp.map_id ORDER BY mh.score_count ASC LIMIT 1) AS wr_count, mp.score_count, mp.score_time, CASE WHEN host_id = $1 THEN mp.host_demo_id WHEN partner_id = $1 THEN mp.partner_demo_id END demo_id, mp.record_date |
| 725 | FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false ORDER BY mp.map_id, mp.score_count, mp.score_time` | 725 | FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false ORDER BY mp.map_id, mp.score_count, mp.score_time` |
| 726 | rows, err = database.DB.Query(sql, user.SteamID) | 726 | rows, err = database.DB.Query(sql, user.SteamID) |
| 727 | if err != nil { | 727 | if err != nil { |