aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-06-29 18:57:39 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-06-29 18:57:39 +0300
commit41529b1d6938c52fcbc52aa50a186a0d368d70e5 (patch)
tree4ee8e03cce386349473cec99c35c11b761c79cf9
parentfix: map summary sql (diff)
downloadlphub-41529b1d6938c52fcbc52aa50a186a0d368d70e5.tar.gz
lphub-41529b1d6938c52fcbc52aa50a186a0d368d70e5.tar.bz2
lphub-41529b1d6938c52fcbc52aa50a186a0d368d70e5.zip
feat: return back to single map summary edit
Former-commit-id: 853dd376267ea63e67b1e4e7041f4c5c5f1be380
-rw-r--r--backend/controllers/modController.go45
-rw-r--r--backend/models/requests.go19
2 files changed, 28 insertions, 36 deletions
diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go
index 7c258ef..5fe0f68 100644
--- a/backend/controllers/modController.go
+++ b/backend/controllers/modController.go
@@ -55,34 +55,29 @@ func EditMapSummary(c *gin.Context) {
55 return 55 return
56 } 56 }
57 defer tx.Rollback() 57 defer tx.Rollback()
58 if request.Image != "" { 58 // Fetch route category and score count
59 tx.Exec(`UPDATE maps m SET image = $2 WHERE m.id = $1`, mapID, request.Image) 59 var categoryID, scoreCount int
60 } 60 sql := `SELECT mr.category_id, mr.score_count
61 for _, route := range request.Routes {
62 // Fetch route category and score count
63 var categoryID, scoreCount int
64 sql := `SELECT mr.category_id, mr.score_count
65 FROM map_routes mr 61 FROM map_routes mr
66 INNER JOIN maps m 62 INNER JOIN maps m
67 WHERE m.id = $1 AND mr.id = $2` 63 WHERE m.id = $1 AND mr.id = $2`
68 err = database.DB.QueryRow(sql, mapID, route.RouteID).Scan(&categoryID, &scoreCount) 64 err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount)
69 if err != nil { 65 if err != nil {
70 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 66 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
71 return 67 return
72 } 68 }
73 // Update database with new data 69 // Update database with new data
74 sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` 70 sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1`
75 _, err = tx.Exec(sql, route.RouteID, route.ScoreCount, route.Description, route.Showcase) 71 _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase)
76 if err != nil { 72 if err != nil {
77 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 73 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
78 return 74 return
79 } 75 }
80 sql = `UPDATE map_history SET user_name = $3, score_count = $4, record_date = $5 WHERE map_id = $1 AND category_id = $2` 76 sql = `UPDATE map_history SET user_name = $3, score_count = $4, record_date = $5 WHERE map_id = $1 AND category_id = $2`
81 _, err = tx.Exec(sql, mapID, categoryID, route.UserName, route.ScoreCount, route.RecordDate) 77 _, err = tx.Exec(sql, mapID, categoryID, request.UserName, request.ScoreCount, request.RecordDate)
82 if err != nil { 78 if err != nil {
83 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 79 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
84 return 80 return
85 }
86 } 81 }
87 if err = tx.Commit(); err != nil { 82 if err = tx.Commit(); err != nil {
88 c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) 83 c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error()))
diff --git a/backend/models/requests.go b/backend/models/requests.go
index 7a00567..767b4d8 100644
--- a/backend/models/requests.go
+++ b/backend/models/requests.go
@@ -5,12 +5,16 @@ import (
5 "time" 5 "time"
6) 6)
7 7
8type EditMapSummaryRequest struct { 8type CreateMapSummaryRequest struct {
9 Image string `json:"image" binding:"required"` 9 CategoryID int `json:"category_id" binding:"required"`
10 Routes []EditMapSummaryRequestDetails `json:"routes" binding:"dive"` 10 Description string `json:"description" binding:"required"`
11 Showcase string `json:"showcase" binding:"required"`
12 UserName string `json:"user_name" binding:"required"`
13 ScoreCount int `json:"score_count" binding:"required"`
14 RecordDate time.Time `json:"record_date" binding:"required"`
11} 15}
12 16
13type EditMapSummaryRequestDetails struct { 17type EditMapSummaryRequest struct {
14 RouteID int `json:"route_id" binding:"required"` 18 RouteID int `json:"route_id" binding:"required"`
15 Description string `json:"description" binding:"required"` 19 Description string `json:"description" binding:"required"`
16 Showcase string `json:"showcase" binding:"required"` 20 Showcase string `json:"showcase" binding:"required"`
@@ -19,13 +23,6 @@ type EditMapSummaryRequestDetails struct {
19 RecordDate time.Time `json:"record_date" binding:"required"` 23 RecordDate time.Time `json:"record_date" binding:"required"`
20} 24}
21 25
22type CreateMapHistoryRequest struct {
23 CategoryID int `json:"category_id" binding:"required"`
24 UserName string `json:"user_name" binding:"required"`
25 ScoreCount int `json:"score_count" binding:"required"`
26 RecordDate time.Time `json:"record_date" binding:"required"`
27}
28
29type RecordRequest struct { 26type RecordRequest struct {
30 HostDemo *multipart.FileHeader `json:"host_demo" form:"host_demo" binding:"required" swaggerignore:"true"` 27 HostDemo *multipart.FileHeader `json:"host_demo" form:"host_demo" binding:"required" swaggerignore:"true"`
31 PartnerDemo *multipart.FileHeader `json:"partner_demo" form:"partner_demo" swaggerignore:"true"` 28 PartnerDemo *multipart.FileHeader `json:"partner_demo" form:"partner_demo" swaggerignore:"true"`