diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-10-31 22:06:00 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-10-31 22:06:00 +0300 |
| commit | 4210c9b38f9053f6720a6bebaadefd24c542eaa9 (patch) | |
| tree | 5b0061e23cf91291ed9e5f387766148d45103591 /backend/handlers/discussions.go | |
| parent | chore: change repo name to lphub (diff) | |
| download | lphub-4210c9b38f9053f6720a6bebaadefd24c542eaa9.tar.gz lphub-4210c9b38f9053f6720a6bebaadefd24c542eaa9.tar.bz2 lphub-4210c9b38f9053f6720a6bebaadefd24c542eaa9.zip | |
backend: better auth check, audit logging
Diffstat (limited to 'backend/handlers/discussions.go')
| -rw-r--r-- | backend/handlers/discussions.go | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/backend/handlers/discussions.go b/backend/handlers/discussions.go index 604eb39..6267695 100644 --- a/backend/handlers/discussions.go +++ b/backend/handlers/discussions.go | |||
| @@ -160,11 +160,7 @@ func CreateMapDiscussion(c *gin.Context) { | |||
| 160 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 160 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 161 | return | 161 | return |
| 162 | } | 162 | } |
| 163 | user, exists := c.Get("user") | 163 | user, _ := c.Get("user") |
| 164 | if !exists { | ||
| 165 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) | ||
| 166 | return | ||
| 167 | } | ||
| 168 | var request CreateMapDiscussionRequest | 164 | var request CreateMapDiscussionRequest |
| 169 | if err := c.BindJSON(&request); err != nil { | 165 | if err := c.BindJSON(&request); err != nil { |
| 170 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 166 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| @@ -206,11 +202,7 @@ func CreateMapDiscussionComment(c *gin.Context) { | |||
| 206 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 202 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 207 | return | 203 | return |
| 208 | } | 204 | } |
| 209 | user, exists := c.Get("user") | 205 | user, _ := c.Get("user") |
| 210 | if !exists { | ||
| 211 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) | ||
| 212 | return | ||
| 213 | } | ||
| 214 | var request CreateMapDiscussionCommentRequest | 206 | var request CreateMapDiscussionCommentRequest |
| 215 | if err := c.BindJSON(&request); err != nil { | 207 | if err := c.BindJSON(&request); err != nil { |
| 216 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 208 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| @@ -258,11 +250,7 @@ func EditMapDiscussion(c *gin.Context) { | |||
| 258 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 250 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 259 | return | 251 | return |
| 260 | } | 252 | } |
| 261 | user, exists := c.Get("user") | 253 | user, _ := c.Get("user") |
| 262 | if !exists { | ||
| 263 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) | ||
| 264 | return | ||
| 265 | } | ||
| 266 | var request EditMapDiscussionRequest | 254 | var request EditMapDiscussionRequest |
| 267 | if err := c.BindJSON(&request); err != nil { | 255 | if err := c.BindJSON(&request); err != nil { |
| 268 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 256 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| @@ -311,11 +299,7 @@ func DeleteMapDiscussion(c *gin.Context) { | |||
| 311 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 299 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 312 | return | 300 | return |
| 313 | } | 301 | } |
| 314 | user, exists := c.Get("user") | 302 | user, _ := c.Get("user") |
| 315 | if !exists { | ||
| 316 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) | ||
| 317 | return | ||
| 318 | } | ||
| 319 | sql := `UPDATE map_discussions SET is_deleted = true WHERE id = $1 AND map_id = $2 AND user_id = $3` | 303 | sql := `UPDATE map_discussions SET is_deleted = true WHERE id = $1 AND map_id = $2 AND user_id = $3` |
| 320 | result, err := database.DB.Exec(sql, discussionID, mapID, user.(models.User).SteamID) | 304 | result, err := database.DB.Exec(sql, discussionID, mapID, user.(models.User).SteamID) |
| 321 | if err != nil { | 305 | if err != nil { |