diff options
Diffstat (limited to 'backend/handlers/discussions.go')
| -rw-r--r-- | backend/handlers/discussions.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/backend/handlers/discussions.go b/backend/handlers/discussions.go index 600c612..51f5334 100644 --- a/backend/handlers/discussions.go +++ b/backend/handlers/discussions.go | |||
| @@ -39,6 +39,10 @@ type CreateMapDiscussionRequest struct { | |||
| 39 | Content string `json:"content" binding:"required"` | 39 | Content string `json:"content" binding:"required"` |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | type CreateMapDiscussionCommentRequest struct { | ||
| 43 | Comment string `json:"comment" binding:"required"` | ||
| 44 | } | ||
| 45 | |||
| 42 | type EditMapDiscussionRequest struct { | 46 | type EditMapDiscussionRequest struct { |
| 43 | Title string `json:"title" binding:"required"` | 47 | Title string `json:"title" binding:"required"` |
| 44 | Content string `json:"content" binding:"required"` | 48 | Content string `json:"content" binding:"required"` |
| @@ -178,6 +182,51 @@ func CreateMapDiscussion(c *gin.Context) { | |||
| 178 | }) | 182 | }) |
| 179 | } | 183 | } |
| 180 | 184 | ||
| 185 | // POST Map Discussion Comment | ||
| 186 | // | ||
| 187 | // @Description Create map discussion comment with specified map id. | ||
| 188 | // @Tags maps | ||
| 189 | // @Produce json | ||
| 190 | // @Param Authorization header string true "JWT Token" | ||
| 191 | // @Param mapid path int true "Map ID" | ||
| 192 | // @Param request body CreateMapDiscussionCommentRequest true "Body" | ||
| 193 | // @Success 200 {object} models.Response{data=CreateMapDiscussionCommentRequest} | ||
| 194 | // @Router /maps/{mapid}/discussions/{discussionid} [post] | ||
| 195 | func CreateMapDiscussionComment(c *gin.Context) { | ||
| 196 | _, err := strconv.Atoi(c.Param("mapid")) | ||
| 197 | if err != nil { | ||
| 198 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 199 | return | ||
| 200 | } | ||
| 201 | discussionID, err := strconv.Atoi(c.Param("discussionid")) | ||
| 202 | if err != nil { | ||
| 203 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 204 | return | ||
| 205 | } | ||
| 206 | user, exists := c.Get("user") | ||
| 207 | if !exists { | ||
| 208 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) | ||
| 209 | return | ||
| 210 | } | ||
| 211 | var request CreateMapDiscussionCommentRequest | ||
| 212 | if err := c.BindJSON(&request); err != nil { | ||
| 213 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 214 | return | ||
| 215 | } | ||
| 216 | sql := `INSERT INTO map_discussions_comments (discussion_id,user_id,comment) | ||
| 217 | VALUES($1,$2,$3);` | ||
| 218 | _, err = database.DB.Exec(sql, discussionID, user.(models.User).SteamID, request.Comment) | ||
| 219 | if err != nil { | ||
| 220 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 221 | return | ||
| 222 | } | ||
| 223 | c.JSON(http.StatusOK, models.Response{ | ||
| 224 | Success: true, | ||
| 225 | Message: "Successfully created map discussion comment.", | ||
| 226 | Data: request, | ||
| 227 | }) | ||
| 228 | } | ||
| 229 | |||
| 181 | // PUT Map Discussion | 230 | // PUT Map Discussion |
| 182 | // | 231 | // |
| 183 | // @Description Edit map discussion with specified map id. | 232 | // @Description Edit map discussion with specified map id. |