diff options
| -rw-r--r-- | backend/controllers/modController.go | 49 | ||||
| -rw-r--r-- | backend/models/requests.go | 5 | ||||
| -rw-r--r-- | docs/docs.go | 45 | ||||
| -rw-r--r-- | docs/swagger.json | 45 | ||||
| -rw-r--r-- | docs/swagger.yaml | 27 |
5 files changed, 88 insertions, 83 deletions
diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index 9d14f92..7c258ef 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go | |||
| @@ -48,17 +48,6 @@ func EditMapSummary(c *gin.Context) { | |||
| 48 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 48 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 49 | return | 49 | return |
| 50 | } | 50 | } |
| 51 | // Fetch route category and score count | ||
| 52 | var categoryID, scoreCount int | ||
| 53 | sql := `SELECT mr.category_id, mr.score_count | ||
| 54 | FROM map_routes mr | ||
| 55 | INNER JOIN maps m | ||
| 56 | WHERE m.id = $1 AND mr.id = $2` | ||
| 57 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) | ||
| 58 | if err != nil { | ||
| 59 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 60 | return | ||
| 61 | } | ||
| 62 | // Start database transaction | 51 | // Start database transaction |
| 63 | tx, err := database.DB.Begin() | 52 | tx, err := database.DB.Begin() |
| 64 | if err != nil { | 53 | if err != nil { |
| @@ -66,18 +55,34 @@ func EditMapSummary(c *gin.Context) { | |||
| 66 | return | 55 | return |
| 67 | } | 56 | } |
| 68 | defer tx.Rollback() | 57 | defer tx.Rollback() |
| 69 | // Update database with new data | 58 | if request.Image != "" { |
| 70 | sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` | 59 | tx.Exec(`UPDATE maps m SET image = $2 WHERE m.id = $1`, mapID, request.Image) |
| 71 | _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) | ||
| 72 | if err != nil { | ||
| 73 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 74 | return | ||
| 75 | } | 60 | } |
| 76 | sql = `UPDATE map_history SET user_name = $3, score_count = $4, record_date = $5 WHERE map_id = $1 AND category_id = $2` | 61 | for _, route := range request.Routes { |
| 77 | _, err = tx.Exec(sql, mapID, categoryID, request.UserName, request.ScoreCount, request.RecordDate) | 62 | // Fetch route category and score count |
| 78 | if err != nil { | 63 | var categoryID, scoreCount int |
| 79 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 64 | sql := `SELECT mr.category_id, mr.score_count |
| 80 | return | 65 | FROM map_routes mr |
| 66 | INNER JOIN maps m | ||
| 67 | WHERE m.id = $1 AND mr.id = $2` | ||
| 68 | err = database.DB.QueryRow(sql, mapID, route.RouteID).Scan(&categoryID, &scoreCount) | ||
| 69 | if err != nil { | ||
| 70 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 71 | return | ||
| 72 | } | ||
| 73 | // Update database with new data | ||
| 74 | 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) | ||
| 76 | if err != nil { | ||
| 77 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 78 | return | ||
| 79 | } | ||
| 80 | 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) | ||
| 82 | if err != nil { | ||
| 83 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 84 | return | ||
| 85 | } | ||
| 81 | } | 86 | } |
| 82 | if err = tx.Commit(); err != nil { | 87 | if err = tx.Commit(); err != nil { |
| 83 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 88 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) |
diff --git a/backend/models/requests.go b/backend/models/requests.go index 4b4657b..7a00567 100644 --- a/backend/models/requests.go +++ b/backend/models/requests.go | |||
| @@ -6,6 +6,11 @@ import ( | |||
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | type EditMapSummaryRequest struct { | 8 | type EditMapSummaryRequest struct { |
| 9 | Image string `json:"image" binding:"required"` | ||
| 10 | Routes []EditMapSummaryRequestDetails `json:"routes" binding:"dive"` | ||
| 11 | } | ||
| 12 | |||
| 13 | type EditMapSummaryRequestDetails struct { | ||
| 9 | RouteID int `json:"route_id" binding:"required"` | 14 | RouteID int `json:"route_id" binding:"required"` |
| 10 | Description string `json:"description" binding:"required"` | 15 | Description string `json:"description" binding:"required"` |
| 11 | Showcase string `json:"showcase" binding:"required"` | 16 | Showcase string `json:"showcase" binding:"required"` |
diff --git a/docs/docs.go b/docs/docs.go index 91f91ef..8318e14 100644 --- a/docs/docs.go +++ b/docs/docs.go | |||
| @@ -377,19 +377,7 @@ const docTemplate = `{ | |||
| 377 | "200": { | 377 | "200": { |
| 378 | "description": "OK", | 378 | "description": "OK", |
| 379 | "schema": { | 379 | "schema": { |
| 380 | "allOf": [ | 380 | "$ref": "#/definitions/models.Response" |
| 381 | { | ||
| 382 | "$ref": "#/definitions/models.Response" | ||
| 383 | }, | ||
| 384 | { | ||
| 385 | "type": "object", | ||
| 386 | "properties": { | ||
| 387 | "data": { | ||
| 388 | "$ref": "#/definitions/models.RecordRequest" | ||
| 389 | } | ||
| 390 | } | ||
| 391 | } | ||
| 392 | ] | ||
| 393 | } | 381 | } |
| 394 | }, | 382 | }, |
| 395 | "400": { | 383 | "400": { |
| @@ -889,6 +877,23 @@ const docTemplate = `{ | |||
| 889 | "models.EditMapSummaryRequest": { | 877 | "models.EditMapSummaryRequest": { |
| 890 | "type": "object", | 878 | "type": "object", |
| 891 | "required": [ | 879 | "required": [ |
| 880 | "image" | ||
| 881 | ], | ||
| 882 | "properties": { | ||
| 883 | "image": { | ||
| 884 | "type": "string" | ||
| 885 | }, | ||
| 886 | "routes": { | ||
| 887 | "type": "array", | ||
| 888 | "items": { | ||
| 889 | "$ref": "#/definitions/models.EditMapSummaryRequestDetails" | ||
| 890 | } | ||
| 891 | } | ||
| 892 | } | ||
| 893 | }, | ||
| 894 | "models.EditMapSummaryRequestDetails": { | ||
| 895 | "type": "object", | ||
| 896 | "required": [ | ||
| 892 | "description", | 897 | "description", |
| 893 | "record_date", | 898 | "record_date", |
| 894 | "route_id", | 899 | "route_id", |
| @@ -991,6 +996,9 @@ const docTemplate = `{ | |||
| 991 | "rating": { | 996 | "rating": { |
| 992 | "type": "number" | 997 | "type": "number" |
| 993 | }, | 998 | }, |
| 999 | "route_id": { | ||
| 1000 | "type": "integer" | ||
| 1001 | }, | ||
| 994 | "showcase": { | 1002 | "showcase": { |
| 995 | "type": "string" | 1003 | "type": "string" |
| 996 | } | 1004 | } |
| @@ -1078,17 +1086,6 @@ const docTemplate = `{ | |||
| 1078 | } | 1086 | } |
| 1079 | } | 1087 | } |
| 1080 | }, | 1088 | }, |
| 1081 | "models.RecordRequest": { | ||
| 1082 | "type": "object", | ||
| 1083 | "properties": { | ||
| 1084 | "is_partner_orange": { | ||
| 1085 | "type": "boolean" | ||
| 1086 | }, | ||
| 1087 | "partner_id": { | ||
| 1088 | "type": "string" | ||
| 1089 | } | ||
| 1090 | } | ||
| 1091 | }, | ||
| 1092 | "models.Response": { | 1089 | "models.Response": { |
| 1093 | "type": "object", | 1090 | "type": "object", |
| 1094 | "properties": { | 1091 | "properties": { |
diff --git a/docs/swagger.json b/docs/swagger.json index c6bbfbc..212ebee 100644 --- a/docs/swagger.json +++ b/docs/swagger.json | |||
| @@ -370,19 +370,7 @@ | |||
| 370 | "200": { | 370 | "200": { |
| 371 | "description": "OK", | 371 | "description": "OK", |
| 372 | "schema": { | 372 | "schema": { |
| 373 | "allOf": [ | 373 | "$ref": "#/definitions/models.Response" |
| 374 | { | ||
| 375 | "$ref": "#/definitions/models.Response" | ||
| 376 | }, | ||
| 377 | { | ||
| 378 | "type": "object", | ||
| 379 | "properties": { | ||
| 380 | "data": { | ||
| 381 | "$ref": "#/definitions/models.RecordRequest" | ||
| 382 | } | ||
| 383 | } | ||
| 384 | } | ||
| 385 | ] | ||
| 386 | } | 374 | } |
| 387 | }, | 375 | }, |
| 388 | "400": { | 376 | "400": { |
| @@ -882,6 +870,23 @@ | |||
| 882 | "models.EditMapSummaryRequest": { | 870 | "models.EditMapSummaryRequest": { |
| 883 | "type": "object", | 871 | "type": "object", |
| 884 | "required": [ | 872 | "required": [ |
| 873 | "image" | ||
| 874 | ], | ||
| 875 | "properties": { | ||
| 876 | "image": { | ||
| 877 | "type": "string" | ||
| 878 | }, | ||
| 879 | "routes": { | ||
| 880 | "type": "array", | ||
| 881 | "items": { | ||
| 882 | "$ref": "#/definitions/models.EditMapSummaryRequestDetails" | ||
| 883 | } | ||
| 884 | } | ||
| 885 | } | ||
| 886 | }, | ||
| 887 | "models.EditMapSummaryRequestDetails": { | ||
| 888 | "type": "object", | ||
| 889 | "required": [ | ||
| 885 | "description", | 890 | "description", |
| 886 | "record_date", | 891 | "record_date", |
| 887 | "route_id", | 892 | "route_id", |
| @@ -984,6 +989,9 @@ | |||
| 984 | "rating": { | 989 | "rating": { |
| 985 | "type": "number" | 990 | "type": "number" |
| 986 | }, | 991 | }, |
| 992 | "route_id": { | ||
| 993 | "type": "integer" | ||
| 994 | }, | ||
| 987 | "showcase": { | 995 | "showcase": { |
| 988 | "type": "string" | 996 | "type": "string" |
| 989 | } | 997 | } |
| @@ -1071,17 +1079,6 @@ | |||
| 1071 | } | 1079 | } |
| 1072 | } | 1080 | } |
| 1073 | }, | 1081 | }, |
| 1074 | "models.RecordRequest": { | ||
| 1075 | "type": "object", | ||
| 1076 | "properties": { | ||
| 1077 | "is_partner_orange": { | ||
| 1078 | "type": "boolean" | ||
| 1079 | }, | ||
| 1080 | "partner_id": { | ||
| 1081 | "type": "string" | ||
| 1082 | } | ||
| 1083 | } | ||
| 1084 | }, | ||
| 1085 | "models.Response": { | 1082 | "models.Response": { |
| 1086 | "type": "object", | 1083 | "type": "object", |
| 1087 | "properties": { | 1084 | "properties": { |
diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 4291cfc..ba20f6d 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml | |||
| @@ -34,6 +34,17 @@ definitions: | |||
| 34 | type: object | 34 | type: object |
| 35 | models.EditMapSummaryRequest: | 35 | models.EditMapSummaryRequest: |
| 36 | properties: | 36 | properties: |
| 37 | image: | ||
| 38 | type: string | ||
| 39 | routes: | ||
| 40 | items: | ||
| 41 | $ref: '#/definitions/models.EditMapSummaryRequestDetails' | ||
| 42 | type: array | ||
| 43 | required: | ||
| 44 | - image | ||
| 45 | type: object | ||
| 46 | models.EditMapSummaryRequestDetails: | ||
| 47 | properties: | ||
| 37 | description: | 48 | description: |
| 38 | type: string | 49 | type: string |
| 39 | record_date: | 50 | record_date: |
| @@ -102,6 +113,8 @@ definitions: | |||
| 102 | $ref: '#/definitions/models.MapHistory' | 113 | $ref: '#/definitions/models.MapHistory' |
| 103 | rating: | 114 | rating: |
| 104 | type: number | 115 | type: number |
| 116 | route_id: | ||
| 117 | type: integer | ||
| 105 | showcase: | 118 | showcase: |
| 106 | type: string | 119 | type: string |
| 107 | type: object | 120 | type: object |
| @@ -158,13 +171,6 @@ definitions: | |||
| 158 | $ref: '#/definitions/models.UserRanking' | 171 | $ref: '#/definitions/models.UserRanking' |
| 159 | type: array | 172 | type: array |
| 160 | type: object | 173 | type: object |
| 161 | models.RecordRequest: | ||
| 162 | properties: | ||
| 163 | is_partner_orange: | ||
| 164 | type: boolean | ||
| 165 | partner_id: | ||
| 166 | type: string | ||
| 167 | type: object | ||
| 168 | models.Response: | 174 | models.Response: |
| 169 | properties: | 175 | properties: |
| 170 | data: {} | 176 | data: {} |
| @@ -429,12 +435,7 @@ paths: | |||
| 429 | "200": | 435 | "200": |
| 430 | description: OK | 436 | description: OK |
| 431 | schema: | 437 | schema: |
| 432 | allOf: | 438 | $ref: '#/definitions/models.Response' |
| 433 | - $ref: '#/definitions/models.Response' | ||
| 434 | - properties: | ||
| 435 | data: | ||
| 436 | $ref: '#/definitions/models.RecordRequest' | ||
| 437 | type: object | ||
| 438 | "400": | 439 | "400": |
| 439 | description: Bad Request | 440 | description: Bad Request |
| 440 | schema: | 441 | schema: |