aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-12-11 16:34:10 +0300
committerGitHub <noreply@github.com>2023-12-11 16:34:10 +0300
commit28045d2635dff2c2b18cbcdc0da424b0ec7da0ac (patch)
treecb94ec913a230f6bd916b7a5bc3721b45e13ea10
parentfeat: add content to discussions list (#59) (diff)
downloadlphub-28045d2635dff2c2b18cbcdc0da424b0ec7da0ac.tar.gz
lphub-28045d2635dff2c2b18cbcdc0da424b0ec7da0ac.tar.bz2
lphub-28045d2635dff2c2b18cbcdc0da424b0ec7da0ac.zip
feat: add discussion comment posting (#59)
-rw-r--r--backend/api/routes.go1
-rw-r--r--backend/handlers/discussions.go49
-rw-r--r--docs/docs.go65
-rw-r--r--docs/swagger.json65
-rw-r--r--docs/swagger.yaml40
5 files changed, 220 insertions, 0 deletions
diff --git a/backend/api/routes.go b/backend/api/routes.go
index 2581a75..ed1ca90 100644
--- a/backend/api/routes.go
+++ b/backend/api/routes.go
@@ -68,6 +68,7 @@ func InitRoutes(router *gin.Engine) {
68 v1.GET(mapDiscussionsPath, handlers.FetchMapDiscussions) 68 v1.GET(mapDiscussionsPath, handlers.FetchMapDiscussions)
69 v1.GET(mapDiscussionIDPath, handlers.FetchMapDiscussion) 69 v1.GET(mapDiscussionIDPath, handlers.FetchMapDiscussion)
70 v1.POST(mapDiscussionsPath, CheckAuth, handlers.CreateMapDiscussion) 70 v1.POST(mapDiscussionsPath, CheckAuth, handlers.CreateMapDiscussion)
71 v1.POST(mapDiscussionIDPath, CheckAuth, handlers.CreateMapDiscussionComment)
71 v1.PUT(mapDiscussionIDPath, CheckAuth, handlers.EditMapDiscussion) 72 v1.PUT(mapDiscussionIDPath, CheckAuth, handlers.EditMapDiscussion)
72 v1.DELETE(mapDiscussionIDPath, CheckAuth, handlers.DeleteMapDiscussion) 73 v1.DELETE(mapDiscussionIDPath, CheckAuth, handlers.DeleteMapDiscussion)
73 // Rankings, search 74 // Rankings, search
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
42type CreateMapDiscussionCommentRequest struct {
43 Comment string `json:"comment" binding:"required"`
44}
45
42type EditMapDiscussionRequest struct { 46type 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]
195func 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.
diff --git a/docs/docs.go b/docs/docs.go
index f689ba6..c2c1bab 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -522,6 +522,60 @@ const docTemplate = `{
522 } 522 }
523 } 523 }
524 }, 524 },
525 "post": {
526 "description": "Create map discussion comment with specified map id.",
527 "produces": [
528 "application/json"
529 ],
530 "tags": [
531 "maps"
532 ],
533 "parameters": [
534 {
535 "type": "string",
536 "description": "JWT Token",
537 "name": "Authorization",
538 "in": "header",
539 "required": true
540 },
541 {
542 "type": "integer",
543 "description": "Map ID",
544 "name": "mapid",
545 "in": "path",
546 "required": true
547 },
548 {
549 "description": "Body",
550 "name": "request",
551 "in": "body",
552 "required": true,
553 "schema": {
554 "$ref": "#/definitions/handlers.CreateMapDiscussionCommentRequest"
555 }
556 }
557 ],
558 "responses": {
559 "200": {
560 "description": "OK",
561 "schema": {
562 "allOf": [
563 {
564 "$ref": "#/definitions/models.Response"
565 },
566 {
567 "type": "object",
568 "properties": {
569 "data": {
570 "$ref": "#/definitions/handlers.CreateMapDiscussionCommentRequest"
571 }
572 }
573 }
574 ]
575 }
576 }
577 }
578 },
525 "delete": { 579 "delete": {
526 "description": "Delete map summary with specified map id.", 580 "description": "Delete map summary with specified map id.",
527 "produces": [ 581 "produces": [
@@ -1325,6 +1379,17 @@ const docTemplate = `{
1325 } 1379 }
1326 } 1380 }
1327 }, 1381 },
1382 "handlers.CreateMapDiscussionCommentRequest": {
1383 "type": "object",
1384 "required": [
1385 "comment"
1386 ],
1387 "properties": {
1388 "comment": {
1389 "type": "string"
1390 }
1391 }
1392 },
1328 "handlers.CreateMapDiscussionRequest": { 1393 "handlers.CreateMapDiscussionRequest": {
1329 "type": "object", 1394 "type": "object",
1330 "required": [ 1395 "required": [
diff --git a/docs/swagger.json b/docs/swagger.json
index a38240e..043fb6b 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -516,6 +516,60 @@
516 } 516 }
517 } 517 }
518 }, 518 },
519 "post": {
520 "description": "Create map discussion comment with specified map id.",
521 "produces": [
522 "application/json"
523 ],
524 "tags": [
525 "maps"
526 ],
527 "parameters": [
528 {
529 "type": "string",
530 "description": "JWT Token",
531 "name": "Authorization",
532 "in": "header",
533 "required": true
534 },
535 {
536 "type": "integer",
537 "description": "Map ID",
538 "name": "mapid",
539 "in": "path",
540 "required": true
541 },
542 {
543 "description": "Body",
544 "name": "request",
545 "in": "body",
546 "required": true,
547 "schema": {
548 "$ref": "#/definitions/handlers.CreateMapDiscussionCommentRequest"
549 }
550 }
551 ],
552 "responses": {
553 "200": {
554 "description": "OK",
555 "schema": {
556 "allOf": [
557 {
558 "$ref": "#/definitions/models.Response"
559 },
560 {
561 "type": "object",
562 "properties": {
563 "data": {
564 "$ref": "#/definitions/handlers.CreateMapDiscussionCommentRequest"
565 }
566 }
567 }
568 ]
569 }
570 }
571 }
572 },
519 "delete": { 573 "delete": {
520 "description": "Delete map summary with specified map id.", 574 "description": "Delete map summary with specified map id.",
521 "produces": [ 575 "produces": [
@@ -1319,6 +1373,17 @@
1319 } 1373 }
1320 } 1374 }
1321 }, 1375 },
1376 "handlers.CreateMapDiscussionCommentRequest": {
1377 "type": "object",
1378 "required": [
1379 "comment"
1380 ],
1381 "properties": {
1382 "comment": {
1383 "type": "string"
1384 }
1385 }
1386 },
1322 "handlers.CreateMapDiscussionRequest": { 1387 "handlers.CreateMapDiscussionRequest": {
1323 "type": "object", 1388 "type": "object",
1324 "required": [ 1389 "required": [
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 3249483..9de09a3 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -18,6 +18,13 @@ definitions:
18 game: 18 game:
19 $ref: '#/definitions/models.Game' 19 $ref: '#/definitions/models.Game'
20 type: object 20 type: object
21 handlers.CreateMapDiscussionCommentRequest:
22 properties:
23 comment:
24 type: string
25 required:
26 - comment
27 type: object
21 handlers.CreateMapDiscussionRequest: 28 handlers.CreateMapDiscussionRequest:
22 properties: 29 properties:
23 content: 30 content:
@@ -772,6 +779,39 @@ paths:
772 type: object 779 type: object
773 tags: 780 tags:
774 - maps 781 - maps
782 post:
783 description: Create map discussion comment with specified map id.
784 parameters:
785 - description: JWT Token
786 in: header
787 name: Authorization
788 required: true
789 type: string
790 - description: Map ID
791 in: path
792 name: mapid
793 required: true
794 type: integer
795 - description: Body
796 in: body
797 name: request
798 required: true
799 schema:
800 $ref: '#/definitions/handlers.CreateMapDiscussionCommentRequest'
801 produces:
802 - application/json
803 responses:
804 "200":
805 description: OK
806 schema:
807 allOf:
808 - $ref: '#/definitions/models.Response'
809 - properties:
810 data:
811 $ref: '#/definitions/handlers.CreateMapDiscussionCommentRequest'
812 type: object
813 tags:
814 - maps
775 put: 815 put:
776 description: Edit map discussion with specified map id. 816 description: Edit map discussion with specified map id.
777 parameters: 817 parameters: