diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/handlers/discussions.go | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/backend/handlers/discussions.go b/backend/handlers/discussions.go index 6687a53..600c612 100644 --- a/backend/handlers/discussions.go +++ b/backend/handlers/discussions.go | |||
| @@ -15,7 +15,7 @@ type MapDiscussionResponse struct { | |||
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | type MapDiscussionsResponse struct { | 17 | type MapDiscussionsResponse struct { |
| 18 | Discussions []MapDiscussionOnlyTitle `json:"discussions"` | 18 | Discussions []MapDiscussion `json:"discussions"` |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | type MapDiscussion struct { | 21 | type MapDiscussion struct { |
| @@ -28,15 +28,6 @@ type MapDiscussion struct { | |||
| 28 | Comments []MapDiscussionComment `json:"comments"` | 28 | Comments []MapDiscussionComment `json:"comments"` |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | type MapDiscussionOnlyTitle struct { | ||
| 32 | ID int `json:"id"` | ||
| 33 | Creator models.UserShortWithAvatar `json:"creator"` | ||
| 34 | Title string `json:"title"` | ||
| 35 | // Upvotes int `json:"upvotes"` | ||
| 36 | UpdatedAt time.Time `json:"updated_at"` | ||
| 37 | Comments []MapDiscussionComment `json:"comments"` | ||
| 38 | } | ||
| 39 | |||
| 40 | type MapDiscussionComment struct { | 31 | type MapDiscussionComment struct { |
| 41 | User models.UserShortWithAvatar `json:"user"` | 32 | User models.UserShortWithAvatar `json:"user"` |
| 42 | Comment string `json:"comment"` | 33 | Comment string `json:"comment"` |
| @@ -69,7 +60,7 @@ func FetchMapDiscussions(c *gin.Context) { | |||
| 69 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 60 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 70 | return | 61 | return |
| 71 | } | 62 | } |
| 72 | sql := `SELECT md.id, u.steam_id, u.user_name, u.avatar_link, md.title, md.updated_at FROM map_discussions md | 63 | sql := `SELECT md.id, u.steam_id, u.user_name, u.avatar_link, md.title, md.content, md.updated_at FROM map_discussions md |
| 73 | INNER JOIN users u ON md.user_id = u.steam_id WHERE md.map_id = $1 | 64 | INNER JOIN users u ON md.user_id = u.steam_id WHERE md.map_id = $1 |
| 74 | ORDER BY md.updated_at DESC` | 65 | ORDER BY md.updated_at DESC` |
| 75 | rows, err := database.DB.Query(sql, mapID) | 66 | rows, err := database.DB.Query(sql, mapID) |
| @@ -79,8 +70,8 @@ func FetchMapDiscussions(c *gin.Context) { | |||
| 79 | } | 70 | } |
| 80 | // Get discussion data | 71 | // Get discussion data |
| 81 | for rows.Next() { | 72 | for rows.Next() { |
| 82 | discussion := MapDiscussionOnlyTitle{} | 73 | discussion := MapDiscussion{} |
| 83 | err := rows.Scan(&discussion.ID, &discussion.Creator.SteamID, &discussion.Creator.UserName, &discussion.Creator.AvatarLink, &discussion.Title, &discussion.UpdatedAt) | 74 | err := rows.Scan(&discussion.ID, &discussion.Creator.SteamID, &discussion.Creator.UserName, &discussion.Creator.AvatarLink, &discussion.Title, &discussion.Content, &discussion.UpdatedAt) |
| 84 | if err != nil { | 75 | if err != nil { |
| 85 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 76 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 86 | return | 77 | return |