diff options
Diffstat (limited to '')
| -rw-r--r-- | backend/controllers/modController.go | 67 |
1 files changed, 47 insertions, 20 deletions
diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index e2add1f..7ce5cb4 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go | |||
| @@ -3,21 +3,48 @@ package controllers | |||
| 3 | import ( | 3 | import ( |
| 4 | "net/http" | 4 | "net/http" |
| 5 | "strconv" | 5 | "strconv" |
| 6 | "time" | ||
| 6 | 7 | ||
| 7 | "github.com/gin-gonic/gin" | 8 | "github.com/gin-gonic/gin" |
| 8 | "github.com/pektezol/leastportalshub/backend/database" | 9 | "github.com/pektezol/leastportalshub/backend/database" |
| 9 | "github.com/pektezol/leastportalshub/backend/models" | 10 | "github.com/pektezol/leastportalshub/backend/models" |
| 10 | ) | 11 | ) |
| 11 | 12 | ||
| 13 | type CreateMapSummaryRequest struct { | ||
| 14 | CategoryID int `json:"category_id" binding:"required"` | ||
| 15 | Description string `json:"description" binding:"required"` | ||
| 16 | Showcase string `json:"showcase"` | ||
| 17 | UserName string `json:"user_name" binding:"required"` | ||
| 18 | ScoreCount *int `json:"score_count" binding:"required"` | ||
| 19 | RecordDate time.Time `json:"record_date" binding:"required"` | ||
| 20 | } | ||
| 21 | |||
| 22 | type EditMapSummaryRequest struct { | ||
| 23 | RouteID int `json:"route_id" binding:"required"` | ||
| 24 | Description string `json:"description" binding:"required"` | ||
| 25 | Showcase string `json:"showcase"` | ||
| 26 | UserName string `json:"user_name" binding:"required"` | ||
| 27 | ScoreCount *int `json:"score_count" binding:"required"` | ||
| 28 | RecordDate time.Time `json:"record_date" binding:"required"` | ||
| 29 | } | ||
| 30 | |||
| 31 | type DeleteMapSummaryRequest struct { | ||
| 32 | RouteID int `json:"route_id" binding:"required"` | ||
| 33 | } | ||
| 34 | |||
| 35 | type EditMapImageRequest struct { | ||
| 36 | Image string `json:"image" binding:"required"` | ||
| 37 | } | ||
| 38 | |||
| 12 | // POST Map Summary | 39 | // POST Map Summary |
| 13 | // | 40 | // |
| 14 | // @Description Create map summary with specified map id. | 41 | // @Description Create map summary with specified map id. |
| 15 | // @Tags maps | 42 | // @Tags maps |
| 16 | // @Produce json | 43 | // @Produce json |
| 17 | // @Param Authorization header string true "JWT Token" | 44 | // @Param Authorization header string true "JWT Token" |
| 18 | // @Param id path int true "Map ID" | 45 | // @Param id path int true "Map ID" |
| 19 | // @Param request body models.CreateMapSummaryRequest true "Body" | 46 | // @Param request body CreateMapSummaryRequest true "Body" |
| 20 | // @Success 200 {object} models.Response{data=models.CreateMapSummaryRequest} | 47 | // @Success 200 {object} models.Response{data=CreateMapSummaryRequest} |
| 21 | // @Failure 400 {object} models.Response | 48 | // @Failure 400 {object} models.Response |
| 22 | // @Router /maps/{id}/summary [post] | 49 | // @Router /maps/{id}/summary [post] |
| 23 | func CreateMapSummary(c *gin.Context) { | 50 | func CreateMapSummary(c *gin.Context) { |
| @@ -44,7 +71,7 @@ func CreateMapSummary(c *gin.Context) { | |||
| 44 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 71 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 45 | return | 72 | return |
| 46 | } | 73 | } |
| 47 | var request models.CreateMapSummaryRequest | 74 | var request CreateMapSummaryRequest |
| 48 | if err := c.BindJSON(&request); err != nil { | 75 | if err := c.BindJSON(&request); err != nil { |
| 49 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 76 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 50 | return | 77 | return |
| @@ -100,10 +127,10 @@ func CreateMapSummary(c *gin.Context) { | |||
| 100 | // @Description Edit map summary with specified map id. | 127 | // @Description Edit map summary with specified map id. |
| 101 | // @Tags maps | 128 | // @Tags maps |
| 102 | // @Produce json | 129 | // @Produce json |
| 103 | // @Param Authorization header string true "JWT Token" | 130 | // @Param Authorization header string true "JWT Token" |
| 104 | // @Param id path int true "Map ID" | 131 | // @Param id path int true "Map ID" |
| 105 | // @Param request body models.EditMapSummaryRequest true "Body" | 132 | // @Param request body EditMapSummaryRequest true "Body" |
| 106 | // @Success 200 {object} models.Response{data=models.EditMapSummaryRequest} | 133 | // @Success 200 {object} models.Response{data=EditMapSummaryRequest} |
| 107 | // @Failure 400 {object} models.Response | 134 | // @Failure 400 {object} models.Response |
| 108 | // @Router /maps/{id}/summary [put] | 135 | // @Router /maps/{id}/summary [put] |
| 109 | func EditMapSummary(c *gin.Context) { | 136 | func EditMapSummary(c *gin.Context) { |
| @@ -130,7 +157,7 @@ func EditMapSummary(c *gin.Context) { | |||
| 130 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 157 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 131 | return | 158 | return |
| 132 | } | 159 | } |
| 133 | var request models.EditMapSummaryRequest | 160 | var request EditMapSummaryRequest |
| 134 | if err := c.BindJSON(&request); err != nil { | 161 | if err := c.BindJSON(&request); err != nil { |
| 135 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 162 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 136 | return | 163 | return |
| @@ -186,10 +213,10 @@ func EditMapSummary(c *gin.Context) { | |||
| 186 | // @Description Delete map summary with specified map id. | 213 | // @Description Delete map summary with specified map id. |
| 187 | // @Tags maps | 214 | // @Tags maps |
| 188 | // @Produce json | 215 | // @Produce json |
| 189 | // @Param Authorization header string true "JWT Token" | 216 | // @Param Authorization header string true "JWT Token" |
| 190 | // @Param id path int true "Map ID" | 217 | // @Param id path int true "Map ID" |
| 191 | // @Param request body models.DeleteMapSummaryRequest true "Body" | 218 | // @Param request body DeleteMapSummaryRequest true "Body" |
| 192 | // @Success 200 {object} models.Response{data=models.DeleteMapSummaryRequest} | 219 | // @Success 200 {object} models.Response{data=DeleteMapSummaryRequest} |
| 193 | // @Failure 400 {object} models.Response | 220 | // @Failure 400 {object} models.Response |
| 194 | // @Router /maps/{id}/summary [delete] | 221 | // @Router /maps/{id}/summary [delete] |
| 195 | func DeleteMapSummary(c *gin.Context) { | 222 | func DeleteMapSummary(c *gin.Context) { |
| @@ -216,7 +243,7 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 216 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 243 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 217 | return | 244 | return |
| 218 | } | 245 | } |
| 219 | var request models.DeleteMapSummaryRequest | 246 | var request DeleteMapSummaryRequest |
| 220 | if err := c.BindJSON(&request); err != nil { | 247 | if err := c.BindJSON(&request); err != nil { |
| 221 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 248 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 222 | return | 249 | return |
| @@ -276,10 +303,10 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 276 | // @Description Edit map image with specified map id. | 303 | // @Description Edit map image with specified map id. |
| 277 | // @Tags maps | 304 | // @Tags maps |
| 278 | // @Produce json | 305 | // @Produce json |
| 279 | // @Param Authorization header string true "JWT Token" | 306 | // @Param Authorization header string true "JWT Token" |
| 280 | // @Param id path int true "Map ID" | 307 | // @Param id path int true "Map ID" |
| 281 | // @Param request body models.EditMapImageRequest true "Body" | 308 | // @Param request body EditMapImageRequest true "Body" |
| 282 | // @Success 200 {object} models.Response{data=models.EditMapImageRequest} | 309 | // @Success 200 {object} models.Response{data=EditMapImageRequest} |
| 283 | // @Failure 400 {object} models.Response | 310 | // @Failure 400 {object} models.Response |
| 284 | // @Router /maps/{id}/image [put] | 311 | // @Router /maps/{id}/image [put] |
| 285 | func EditMapImage(c *gin.Context) { | 312 | func EditMapImage(c *gin.Context) { |
| @@ -306,7 +333,7 @@ func EditMapImage(c *gin.Context) { | |||
| 306 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 333 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 307 | return | 334 | return |
| 308 | } | 335 | } |
| 309 | var request models.EditMapImageRequest | 336 | var request EditMapImageRequest |
| 310 | if err := c.BindJSON(&request); err != nil { | 337 | if err := c.BindJSON(&request); err != nil { |
| 311 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 338 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 312 | return | 339 | return |