aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-06-20 20:57:10 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-06-20 20:57:10 +0300
commit9af2c7d17f02be98998d388b421b3d055a96f83e (patch)
tree0e1fe45dec78928c77a0455732acd845916bfcb5 /backend
parentdocs: map summary response (#46) (diff)
downloadlphub-9af2c7d17f02be98998d388b421b3d055a96f83e.tar.gz
lphub-9af2c7d17f02be98998d388b421b3d055a96f83e.tar.bz2
lphub-9af2c7d17f02be98998d388b421b3d055a96f83e.zip
fix: remove duplicate score count in routes (#46)
Diffstat (limited to 'backend')
-rw-r--r--backend/controllers/mapController.go11
-rw-r--r--backend/models/models.go1
2 files changed, 3 insertions, 9 deletions
diff --git a/backend/controllers/mapController.go b/backend/controllers/mapController.go
index e46b766..b5984dc 100644
--- a/backend/controllers/mapController.go
+++ b/backend/controllers/mapController.go
@@ -26,11 +26,6 @@ func FetchMapSummary(c *gin.Context) {
26 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 26 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
27 return 27 return
28 } 28 }
29 // (
30 // SELECT COALESCE(avg(rating), 0.0)
31 // FROM route_ratings
32 // WHERE map_id = $1
33 // )
34 // Get map data 29 // Get map data
35 response.Map.ID = intID 30 response.Map.ID = intID
36 sql := `SELECT m.id, g.name, c.name, m.name 31 sql := `SELECT m.id, g.name, c.name, m.name
@@ -44,11 +39,11 @@ func FetchMapSummary(c *gin.Context) {
44 return 39 return
45 } 40 }
46 // Get map routes and histories 41 // Get map routes and histories
47 sql = `SELECT c.id, c.name, h.user_name, h.score_count, h.record_date, r.score_count, r.description, r.showcase, COALESCE(avg(rating), 0.0) FROM map_routes r 42 sql = `SELECT 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
48 INNER JOIN categories c ON r.category_id = c.id 43 INNER JOIN categories c ON r.category_id = c.id
49 INNER JOIN map_history h ON r.map_id = h.map_id AND r.category_id = h.category_id 44 INNER JOIN map_history h ON r.map_id = h.map_id AND r.category_id = h.category_id
50 LEFT JOIN map_ratings rt ON r.map_id = rt.map_id AND r.category_id = rt.category_id 45 LEFT JOIN map_ratings rt ON r.map_id = rt.map_id AND r.category_id = rt.category_id
51 WHERE r.map_id = $1 AND h.score_count = r.score_count GROUP BY c.id, h.user_name, h.score_count, h.record_date, r.score_count, r.description, r.showcase 46 WHERE r.map_id = $1 AND h.score_count = r.score_count GROUP BY c.id, h.user_name, h.score_count, h.record_date, r.description, r.showcase
52 ORDER BY h.record_date ASC;` 47 ORDER BY h.record_date ASC;`
53 rows, err := database.DB.Query(sql, id) 48 rows, err := database.DB.Query(sql, id)
54 if err != nil { 49 if err != nil {
@@ -57,7 +52,7 @@ func FetchMapSummary(c *gin.Context) {
57 } 52 }
58 for rows.Next() { 53 for rows.Next() {
59 route := models.MapRoute{Category: models.Category{}, History: models.MapHistory{}} 54 route := models.MapRoute{Category: models.Category{}, History: models.MapHistory{}}
60 err = rows.Scan(&route.Category.ID, &route.Category.Name, &route.History.RunnerName, &route.History.ScoreCount, &route.History.Date, &route.ScoreCount, &route.Description, &route.Showcase, &route.Rating) 55 err = rows.Scan(&route.Category.ID, &route.Category.Name, &route.History.RunnerName, &route.History.ScoreCount, &route.History.Date, &route.Description, &route.Showcase, &route.Rating)
61 if err != nil { 56 if err != nil {
62 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 57 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
63 return 58 return
diff --git a/backend/models/models.go b/backend/models/models.go
index 783c339..0727468 100644
--- a/backend/models/models.go
+++ b/backend/models/models.go
@@ -44,7 +44,6 @@ type MapRoute struct {
44 Category Category `json:"category"` 44 Category Category `json:"category"`
45 History MapHistory `json:"history"` 45 History MapHistory `json:"history"`
46 Rating float32 `json:"rating"` 46 Rating float32 `json:"rating"`
47 ScoreCount int `json:"score_count"`
48 Description string `json:"description"` 47 Description string `json:"description"`
49 Showcase string `json:"showcase"` 48 Showcase string `json:"showcase"`
50} 49}