diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-12-22 12:22:14 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-22 12:22:14 +0300 |
| commit | 7f56ba240f71c1f6800d1d51ba278b8d5a968ab3 (patch) | |
| tree | f19a3febf0be9111584d601b5adf254e1df2c9de /backend | |
| parent | fix: set db connection limits (#140) (diff) | |
| download | lphub-7f56ba240f71c1f6800d1d51ba278b8d5a968ab3.tar.gz lphub-7f56ba240f71c1f6800d1d51ba278b8d5a968ab3.tar.bz2 lphub-7f56ba240f71c1f6800d1d51ba278b8d5a968ab3.zip | |
fix: discussions logic cleanup, docs title changes (#142)
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/database/init.sql | 1 | ||||
| -rw-r--r-- | backend/handlers/discussions.go | 35 | ||||
| -rw-r--r-- | backend/handlers/map.go | 4 | ||||
| -rw-r--r-- | backend/handlers/mod.go | 8 | ||||
| -rw-r--r-- | backend/handlers/record.go | 4 |
5 files changed, 27 insertions, 25 deletions
diff --git a/backend/database/init.sql b/backend/database/init.sql index 9851ad7..54867ca 100644 --- a/backend/database/init.sql +++ b/backend/database/init.sql | |||
| @@ -91,6 +91,7 @@ CREATE TABLE map_discussions ( | |||
| 91 | content TEXT NOT NULL, | 91 | content TEXT NOT NULL, |
| 92 | created_at TIMESTAMP NOT NULL DEFAULT now(), | 92 | created_at TIMESTAMP NOT NULL DEFAULT now(), |
| 93 | updated_at TIMESTAMP NOT NULL DEFAULT now(), | 93 | updated_at TIMESTAMP NOT NULL DEFAULT now(), |
| 94 | is_deleted BOOLEAN NOT NULL DEFAULT false, | ||
| 94 | PRIMARY KEY (id), | 95 | PRIMARY KEY (id), |
| 95 | FOREIGN KEY (map_id) REFERENCES maps(id), | 96 | FOREIGN KEY (map_id) REFERENCES maps(id), |
| 96 | FOREIGN KEY (user_id) REFERENCES users(steam_id) | 97 | FOREIGN KEY (user_id) REFERENCES users(steam_id) |
diff --git a/backend/handlers/discussions.go b/backend/handlers/discussions.go index 04c91d0..89297f2 100644 --- a/backend/handlers/discussions.go +++ b/backend/handlers/discussions.go | |||
| @@ -24,6 +24,7 @@ type MapDiscussion struct { | |||
| 24 | Title string `json:"title"` | 24 | Title string `json:"title"` |
| 25 | Content string `json:"content"` | 25 | Content string `json:"content"` |
| 26 | // Upvotes int `json:"upvotes"` | 26 | // Upvotes int `json:"upvotes"` |
| 27 | CreatedAt time.Time `json:"created_at"` | ||
| 27 | UpdatedAt time.Time `json:"updated_at"` | 28 | UpdatedAt time.Time `json:"updated_at"` |
| 28 | Comments []MapDiscussionComment `json:"comments"` | 29 | Comments []MapDiscussionComment `json:"comments"` |
| 29 | } | 30 | } |
| @@ -51,7 +52,7 @@ type EditMapDiscussionRequest struct { | |||
| 51 | // GET Map Discussions | 52 | // GET Map Discussions |
| 52 | // | 53 | // |
| 53 | // @Description Get map discussions with specified map id. | 54 | // @Description Get map discussions with specified map id. |
| 54 | // @Tags maps | 55 | // @Tags maps / discussions |
| 55 | // @Produce json | 56 | // @Produce json |
| 56 | // @Param mapid path int true "Map ID" | 57 | // @Param mapid path int true "Map ID" |
| 57 | // @Success 200 {object} models.Response{data=MapDiscussionsResponse} | 58 | // @Success 200 {object} models.Response{data=MapDiscussionsResponse} |
| @@ -64,8 +65,8 @@ func FetchMapDiscussions(c *gin.Context) { | |||
| 64 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 65 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 65 | return | 66 | return |
| 66 | } | 67 | } |
| 67 | sql := `SELECT md.id, u.steam_id, u.user_name, u.avatar_link, md.title, md.content, md.updated_at FROM map_discussions md | 68 | sql := `SELECT md.id, u.steam_id, u.user_name, u.avatar_link, md.title, md.content, md.created_at, md.updated_at FROM map_discussions md |
| 68 | INNER JOIN users u ON md.user_id = u.steam_id WHERE md.map_id = $1 | 69 | INNER JOIN users u ON md.user_id = u.steam_id WHERE md.map_id = $1 AND is_deleted = false |
| 69 | ORDER BY md.updated_at DESC` | 70 | ORDER BY md.updated_at DESC` |
| 70 | rows, err := database.DB.Query(sql, mapID) | 71 | rows, err := database.DB.Query(sql, mapID) |
| 71 | if err != nil { | 72 | if err != nil { |
| @@ -75,7 +76,7 @@ func FetchMapDiscussions(c *gin.Context) { | |||
| 75 | // Get discussion data | 76 | // Get discussion data |
| 76 | for rows.Next() { | 77 | for rows.Next() { |
| 77 | discussion := MapDiscussion{} | 78 | discussion := MapDiscussion{} |
| 78 | err := rows.Scan(&discussion.ID, &discussion.Creator.SteamID, &discussion.Creator.UserName, &discussion.Creator.AvatarLink, &discussion.Title, &discussion.Content, &discussion.UpdatedAt) | 79 | err := rows.Scan(&discussion.ID, &discussion.Creator.SteamID, &discussion.Creator.UserName, &discussion.Creator.AvatarLink, &discussion.Title, &discussion.Content, &discussion.CreatedAt, &discussion.UpdatedAt) |
| 79 | if err != nil { | 80 | if err != nil { |
| 80 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 81 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 81 | return | 82 | return |
| @@ -92,7 +93,7 @@ func FetchMapDiscussions(c *gin.Context) { | |||
| 92 | // GET Map Discussion | 93 | // GET Map Discussion |
| 93 | // | 94 | // |
| 94 | // @Description Get map discussion with specified map and discussion id. | 95 | // @Description Get map discussion with specified map and discussion id. |
| 95 | // @Tags maps | 96 | // @Tags maps / discussions |
| 96 | // @Produce json | 97 | // @Produce json |
| 97 | // @Param mapid path int true "Map ID" | 98 | // @Param mapid path int true "Map ID" |
| 98 | // @Param discussionid path int true "Discussion ID" | 99 | // @Param discussionid path int true "Discussion ID" |
| @@ -111,9 +112,9 @@ func FetchMapDiscussion(c *gin.Context) { | |||
| 111 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 112 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 112 | return | 113 | return |
| 113 | } | 114 | } |
| 114 | sql := `SELECT md.id, u.steam_id, u.user_name, u.avatar_link, md.title, md.content, md.updated_at FROM map_discussions md | 115 | sql := `SELECT md.id, u.steam_id, u.user_name, u.avatar_link, md.title, md.content, md.created_at, md.updated_at FROM map_discussions md |
| 115 | INNER JOIN users u ON md.user_id = u.steam_id WHERE md.map_id = $1 AND md.id = $2` | 116 | INNER JOIN users u ON md.user_id = u.steam_id WHERE md.map_id = $1 AND md.id = $2 AND is_deleted = false` |
| 116 | err = database.DB.QueryRow(sql, mapID, discussionID).Scan(&response.Discussion.ID, &response.Discussion.Creator.SteamID, &response.Discussion.Creator.UserName, &response.Discussion.Creator.AvatarLink, &response.Discussion.Title, &response.Discussion.Content, &response.Discussion.UpdatedAt) | 117 | err = database.DB.QueryRow(sql, mapID, discussionID).Scan(&response.Discussion.ID, &response.Discussion.Creator.SteamID, &response.Discussion.Creator.UserName, &response.Discussion.Creator.AvatarLink, &response.Discussion.Title, &response.Discussion.Content, &response.Discussion.CreatedAt, &response.Discussion.UpdatedAt) |
| 117 | if err != nil { | 118 | if err != nil { |
| 118 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 119 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 119 | return | 120 | return |
| @@ -145,7 +146,7 @@ func FetchMapDiscussion(c *gin.Context) { | |||
| 145 | // POST Map Discussion | 146 | // POST Map Discussion |
| 146 | // | 147 | // |
| 147 | // @Description Create map discussion with specified map id. | 148 | // @Description Create map discussion with specified map id. |
| 148 | // @Tags maps | 149 | // @Tags maps / discussions |
| 149 | // @Produce json | 150 | // @Produce json |
| 150 | // @Param Authorization header string true "JWT Token" | 151 | // @Param Authorization header string true "JWT Token" |
| 151 | // @Param mapid path int true "Map ID" | 152 | // @Param mapid path int true "Map ID" |
| @@ -185,11 +186,11 @@ func CreateMapDiscussion(c *gin.Context) { | |||
| 185 | // POST Map Discussion Comment | 186 | // POST Map Discussion Comment |
| 186 | // | 187 | // |
| 187 | // @Description Create map discussion comment with specified map id. | 188 | // @Description Create map discussion comment with specified map id. |
| 188 | // @Tags maps | 189 | // @Tags maps / discussions |
| 189 | // @Produce json | 190 | // @Produce json |
| 190 | // @Param Authorization header string true "JWT Token" | 191 | // @Param Authorization header string true "JWT Token" |
| 191 | // @Param mapid path int true "Map ID" | 192 | // @Param mapid path int true "Map ID" |
| 192 | // @Param discussionid path int true "Discussion ID" | 193 | // @Param discussionid path int true "Discussion ID" |
| 193 | // @Param request body CreateMapDiscussionCommentRequest true "Body" | 194 | // @Param request body CreateMapDiscussionCommentRequest true "Body" |
| 194 | // @Success 200 {object} models.Response{data=CreateMapDiscussionCommentRequest} | 195 | // @Success 200 {object} models.Response{data=CreateMapDiscussionCommentRequest} |
| 195 | // @Router /maps/{mapid}/discussions/{discussionid} [post] | 196 | // @Router /maps/{mapid}/discussions/{discussionid} [post] |
| @@ -231,7 +232,7 @@ func CreateMapDiscussionComment(c *gin.Context) { | |||
| 231 | // PUT Map Discussion | 232 | // PUT Map Discussion |
| 232 | // | 233 | // |
| 233 | // @Description Edit map discussion with specified map id. | 234 | // @Description Edit map discussion with specified map id. |
| 234 | // @Tags maps | 235 | // @Tags maps / discussions |
| 235 | // @Produce json | 236 | // @Produce json |
| 236 | // @Param Authorization header string true "JWT Token" | 237 | // @Param Authorization header string true "JWT Token" |
| 237 | // @Param mapid path int true "Map ID" | 238 | // @Param mapid path int true "Map ID" |
| @@ -260,7 +261,7 @@ func EditMapDiscussion(c *gin.Context) { | |||
| 260 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 261 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 261 | return | 262 | return |
| 262 | } | 263 | } |
| 263 | sql := `UPDATE map_discussions SET title = $4, content = $5, updated_at = $6 WHERE id = $1 AND map_id = $2 AND user_id = $3` | 264 | sql := `UPDATE map_discussions SET title = $4, content = $5, updated_at = $6 WHERE id = $1 AND map_id = $2 AND user_id = $3 AND is_deleted = false` |
| 264 | result, err := database.DB.Exec(sql, discussionID, mapID, user.(models.User).SteamID, request.Title, request.Content, time.Now().UTC()) | 265 | result, err := database.DB.Exec(sql, discussionID, mapID, user.(models.User).SteamID, request.Title, request.Content, time.Now().UTC()) |
| 265 | if err != nil { | 266 | if err != nil { |
| 266 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 267 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| @@ -282,10 +283,10 @@ func EditMapDiscussion(c *gin.Context) { | |||
| 282 | }) | 283 | }) |
| 283 | } | 284 | } |
| 284 | 285 | ||
| 285 | // DELETE Map Summary | 286 | // DELETE Map Discussion |
| 286 | // | 287 | // |
| 287 | // @Description Delete map summary with specified map id. | 288 | // @Description Delete map discussion with specified map id. |
| 288 | // @Tags maps | 289 | // @Tags maps / discussions |
| 289 | // @Produce json | 290 | // @Produce json |
| 290 | // @Param Authorization header string true "JWT Token" | 291 | // @Param Authorization header string true "JWT Token" |
| 291 | // @Param mapid path int true "Map ID" | 292 | // @Param mapid path int true "Map ID" |
| @@ -308,7 +309,7 @@ func DeleteMapDiscussion(c *gin.Context) { | |||
| 308 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) | 309 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) |
| 309 | return | 310 | return |
| 310 | } | 311 | } |
| 311 | sql := `DELETE FROM map_discussions WHERE id = $1 AND map_id = $2 AND user_id = $3` | 312 | sql := `UPDATE map_discussions SET is_disabled = true WHERE id = $1 AND map_id = $2 AND user_id = $3` |
| 312 | result, err := database.DB.Exec(sql, discussionID, mapID, user.(models.User).SteamID) | 313 | result, err := database.DB.Exec(sql, discussionID, mapID, user.(models.User).SteamID) |
| 313 | if err != nil { | 314 | if err != nil { |
| 314 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 315 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
diff --git a/backend/handlers/map.go b/backend/handlers/map.go index f985a23..dfadade 100644 --- a/backend/handlers/map.go +++ b/backend/handlers/map.go | |||
| @@ -61,7 +61,7 @@ type RecordMultiplayer struct { | |||
| 61 | // GET Map Summary | 61 | // GET Map Summary |
| 62 | // | 62 | // |
| 63 | // @Description Get map summary with specified id. | 63 | // @Description Get map summary with specified id. |
| 64 | // @Tags maps | 64 | // @Tags maps / summary |
| 65 | // @Produce json | 65 | // @Produce json |
| 66 | // @Param mapid path int true "Map ID" | 66 | // @Param mapid path int true "Map ID" |
| 67 | // @Success 200 {object} models.Response{data=MapSummaryResponse} | 67 | // @Success 200 {object} models.Response{data=MapSummaryResponse} |
| @@ -140,7 +140,7 @@ func FetchMapSummary(c *gin.Context) { | |||
| 140 | // GET Map Leaderboards | 140 | // GET Map Leaderboards |
| 141 | // | 141 | // |
| 142 | // @Description Get map leaderboards with specified id. | 142 | // @Description Get map leaderboards with specified id. |
| 143 | // @Tags maps | 143 | // @Tags maps / leaderboards |
| 144 | // @Produce json | 144 | // @Produce json |
| 145 | // @Param mapid path int true "Map ID" | 145 | // @Param mapid path int true "Map ID" |
| 146 | // @Param page query int false "Page Number (default: 1)" | 146 | // @Param page query int false "Page Number (default: 1)" |
diff --git a/backend/handlers/mod.go b/backend/handlers/mod.go index 845152f..3709e1d 100644 --- a/backend/handlers/mod.go +++ b/backend/handlers/mod.go | |||
| @@ -40,7 +40,7 @@ type EditMapImageRequest struct { | |||
| 40 | // POST Map Summary | 40 | // POST Map Summary |
| 41 | // | 41 | // |
| 42 | // @Description Create map summary with specified map id. | 42 | // @Description Create map summary with specified map id. |
| 43 | // @Tags maps | 43 | // @Tags maps / summary |
| 44 | // @Produce json | 44 | // @Produce json |
| 45 | // @Param Authorization header string true "JWT Token" | 45 | // @Param Authorization header string true "JWT Token" |
| 46 | // @Param mapid path int true "Map ID" | 46 | // @Param mapid path int true "Map ID" |
| @@ -124,7 +124,7 @@ func CreateMapSummary(c *gin.Context) { | |||
| 124 | // PUT Map Summary | 124 | // PUT Map Summary |
| 125 | // | 125 | // |
| 126 | // @Description Edit map summary with specified map id. | 126 | // @Description Edit map summary with specified map id. |
| 127 | // @Tags maps | 127 | // @Tags maps / summary |
| 128 | // @Produce json | 128 | // @Produce json |
| 129 | // @Param Authorization header string true "JWT Token" | 129 | // @Param Authorization header string true "JWT Token" |
| 130 | // @Param mapid path int true "Map ID" | 130 | // @Param mapid path int true "Map ID" |
| @@ -209,7 +209,7 @@ func EditMapSummary(c *gin.Context) { | |||
| 209 | // DELETE Map Summary | 209 | // DELETE Map Summary |
| 210 | // | 210 | // |
| 211 | // @Description Delete map summary with specified map id. | 211 | // @Description Delete map summary with specified map id. |
| 212 | // @Tags maps | 212 | // @Tags maps / summary |
| 213 | // @Produce json | 213 | // @Produce json |
| 214 | // @Param Authorization header string true "JWT Token" | 214 | // @Param Authorization header string true "JWT Token" |
| 215 | // @Param mapid path int true "Map ID" | 215 | // @Param mapid path int true "Map ID" |
| @@ -298,7 +298,7 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 298 | // PUT Map Image | 298 | // PUT Map Image |
| 299 | // | 299 | // |
| 300 | // @Description Edit map image with specified map id. | 300 | // @Description Edit map image with specified map id. |
| 301 | // @Tags maps | 301 | // @Tags maps / summary |
| 302 | // @Produce json | 302 | // @Produce json |
| 303 | // @Param Authorization header string true "JWT Token" | 303 | // @Param Authorization header string true "JWT Token" |
| 304 | // @Param mapid path int true "Map ID" | 304 | // @Param mapid path int true "Map ID" |
diff --git a/backend/handlers/record.go b/backend/handlers/record.go index 5dff085..79e9d3b 100644 --- a/backend/handlers/record.go +++ b/backend/handlers/record.go | |||
| @@ -35,7 +35,7 @@ type RecordResponse struct { | |||
| 35 | // POST Record | 35 | // POST Record |
| 36 | // | 36 | // |
| 37 | // @Description Post record with demo of a specific map. | 37 | // @Description Post record with demo of a specific map. |
| 38 | // @Tags maps | 38 | // @Tags maps / leaderboards |
| 39 | // @Accept mpfd | 39 | // @Accept mpfd |
| 40 | // @Produce json | 40 | // @Produce json |
| 41 | // @Param mapid path int true "Map ID" | 41 | // @Param mapid path int true "Map ID" |
| @@ -202,7 +202,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 202 | // DELETE Record | 202 | // DELETE Record |
| 203 | // | 203 | // |
| 204 | // @Description Delete record with specified map and record id. | 204 | // @Description Delete record with specified map and record id. |
| 205 | // @Tags maps | 205 | // @Tags maps / leaderboards |
| 206 | // @Produce json | 206 | // @Produce json |
| 207 | // @Param mapid path int true "Map ID" | 207 | // @Param mapid path int true "Map ID" |
| 208 | // @Param recordid path int true "Record ID" | 208 | // @Param recordid path int true "Record ID" |