From 9cd44de9be62e1291f84763bc029f995301e1e03 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Fri, 22 Sep 2023 23:58:26 +0300 Subject: feat: discussions (#59) Former-commit-id: ac6ac59367650b6a37650f5aec0587c6ce4d3dd1 --- backend/api/routes.go | 89 ++++++++---- backend/database/init.sql | 34 +++++ backend/handlers/discussions.go | 291 ++++++++++++++++++++++++++++++++++++++++ backend/handlers/home.go | 2 - backend/handlers/login.go | 1 - backend/handlers/logs.go | 2 - backend/handlers/map.go | 35 +++-- backend/handlers/mod.go | 28 ++-- backend/handlers/record.go | 13 +- backend/handlers/user.go | 16 +-- 10 files changed, 425 insertions(+), 86 deletions(-) create mode 100644 backend/handlers/discussions.go (limited to 'backend') diff --git a/backend/api/routes.go b/backend/api/routes.go index fd3b8cc..339dc73 100644 --- a/backend/api/routes.go +++ b/backend/api/routes.go @@ -7,35 +7,72 @@ import ( ginSwagger "github.com/swaggo/gin-swagger" ) +const ( + apiPath string = "/api" + v1Path string = "/v1" + swaggerPath string = "/swagger/*any" + indexPath string = "/" + tokenPath string = "/token" + loginPath string = "/login" + profilePath string = "/profile" + usersPath string = "/users/:userid" + demosPath string = "/demos" + mapSummaryPath string = "/maps/:mapid/summary" + mapImagePath string = "/maps/:mapid/image" + mapLeaderboardsPath string = "/maps/:mapid/leaderboards" + mapRecordPath string = "/maps/:mapid/record" + mapDiscussionsPath string = "/maps/:mapid/discussions" + mapDiscussionIDPath string = "/maps/:mapid/discussions/:discussionid" + rankingsPath string = "/rankings" + searchPath string = "/search" + gamesPath string = "/games" + chaptersPath string = "/games/:gameid" + chapterMapsPath string = "/chapters/:chapterid" + scoreLogsPath string = "/logs/score" + modLogsPath string = "/logs/mod" +) + func InitRoutes(router *gin.Engine) { - api := router.Group("/api") + api := router.Group(apiPath) { - v1 := api.Group("/v1") - v1.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) - v1.GET("/", func(c *gin.Context) { + v1 := api.Group(v1Path) + // Swagger + v1.GET(swaggerPath, ginSwagger.WrapHandler(swaggerfiles.Handler)) + v1.GET(indexPath, func(c *gin.Context) { c.File("docs/index.html") }) - v1.GET("/token", handlers.GetCookie) - v1.DELETE("/token", handlers.DeleteCookie) - v1.GET("/login", handlers.Login) - v1.GET("/profile", CheckAuth, handlers.Profile) - v1.PUT("/profile", CheckAuth, handlers.UpdateCountryCode) - v1.POST("/profile", CheckAuth, handlers.UpdateUser) - v1.GET("/users/:id", CheckAuth, handlers.FetchUser) - v1.GET("/demos", handlers.DownloadDemoWithID) - v1.GET("/maps/:id/summary", handlers.FetchMapSummary) - v1.POST("/maps/:id/summary", CheckAuth, handlers.CreateMapSummary) - v1.PUT("/maps/:id/summary", CheckAuth, handlers.EditMapSummary) - v1.DELETE("/maps/:id/summary", CheckAuth, handlers.DeleteMapSummary) - v1.PUT("/maps/:id/image", CheckAuth, handlers.EditMapImage) - v1.GET("/maps/:id/leaderboards", handlers.FetchMapLeaderboards) - v1.POST("/maps/:id/record", CheckAuth, handlers.CreateRecordWithDemo) - v1.GET("/rankings", handlers.Rankings) - v1.GET("/search", handlers.SearchWithQuery) - v1.GET("/games", handlers.FetchGames) - v1.GET("/games/:id", handlers.FetchChapters) - v1.GET("/chapters/:id", handlers.FetchChapterMaps) - v1.GET("/logs/score", handlers.ScoreLogs) - v1.GET("/logs/mod", CheckAuth, handlers.ModLogs) + // Tokens, login + v1.GET(tokenPath, handlers.GetCookie) + v1.DELETE(tokenPath, handlers.DeleteCookie) + v1.GET(loginPath, handlers.Login) + // Users, profiles + v1.GET(profilePath, CheckAuth, handlers.Profile) + v1.PUT(profilePath, CheckAuth, handlers.UpdateCountryCode) + v1.POST(profilePath, CheckAuth, handlers.UpdateUser) + v1.GET(usersPath, CheckAuth, handlers.FetchUser) + // Maps + v1.GET(mapSummaryPath, handlers.FetchMapSummary) + v1.POST(mapSummaryPath, CheckAuth, handlers.CreateMapSummary) + v1.PUT(mapSummaryPath, CheckAuth, handlers.EditMapSummary) + v1.DELETE(mapSummaryPath, CheckAuth, handlers.DeleteMapSummary) + v1.PUT(mapImagePath, CheckAuth, handlers.EditMapImage) + v1.GET(mapLeaderboardsPath, handlers.FetchMapLeaderboards) + v1.POST(mapRecordPath, CheckAuth, handlers.CreateRecordWithDemo) + v1.GET(demosPath, handlers.DownloadDemoWithID) + v1.GET(mapDiscussionsPath, handlers.FetchMapDiscussions) + v1.GET(mapDiscussionIDPath, handlers.FetchMapDiscussion) + v1.POST(mapDiscussionsPath, CheckAuth, handlers.CreateMapDiscussion) + v1.PUT(mapDiscussionIDPath, CheckAuth, handlers.EditMapDiscussion) + v1.DELETE(mapDiscussionIDPath, CheckAuth, handlers.DeleteMapDiscussion) + // Rankings, search + v1.GET(rankingsPath, handlers.Rankings) + v1.GET(searchPath, handlers.SearchWithQuery) + // Games, chapters, maps + v1.GET(gamesPath, handlers.FetchGames) + v1.GET(chaptersPath, handlers.FetchChapters) + v1.GET(chapterMapsPath, handlers.FetchChapterMaps) + // Logs + v1.GET(scoreLogsPath, handlers.ScoreLogs) + v1.GET(modLogsPath, CheckAuth, handlers.ModLogs) } } diff --git a/backend/database/init.sql b/backend/database/init.sql index abace5c..0f8196b 100644 --- a/backend/database/init.sql +++ b/backend/database/init.sql @@ -82,6 +82,40 @@ CREATE TABLE map_ratings ( FOREIGN KEY (user_id) REFERENCES users(steam_id) ); +CREATE TABLE map_discussions ( + id SERIAL, + map_id SMALLINT NOT NULL, + user_id TEXT NOT NULL, + title TEXT NOT NULL, + content TEXT NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT now(), + updated_at TIMESTAMP NOT NULL DEFAULT now(), + PRIMARY KEY (id), + FOREIGN KEY (map_id) REFERENCES maps(id), + FOREIGN KEY (user_id) REFERENCES users(steam_id) +); + +CREATE TABLE map_discussions_comments ( + id SERIAL, + discussion_id INT NOT NULL, + user_id TEXT NOT NULL, + comment TEXT NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT now(), + PRIMARY KEY (id), + FOREIGN KEY (discussion_id) REFERENCES map_discussions(id), + FOREIGN KEY (user_id) REFERENCES users(steam_id) +); + +CREATE TABLE map_discussions_upvotes ( + id SERIAL, + discussion_id INT NOT NULL, + user_id TEXT NOT NULL, + upvoted BOOLEAN NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (discussion_id) REFERENCES map_discussions(id), + FOREIGN KEY (user_id) REFERENCES users(steam_id) +); + CREATE TABLE demos ( id UUID, location_id TEXT NOT NULL, diff --git a/backend/handlers/discussions.go b/backend/handlers/discussions.go new file mode 100644 index 0000000..605c7c3 --- /dev/null +++ b/backend/handlers/discussions.go @@ -0,0 +1,291 @@ +package handlers + +import ( + "net/http" + "strconv" + "time" + + "github.com/gin-gonic/gin" + "github.com/pektezol/leastportalshub/backend/database" + "github.com/pektezol/leastportalshub/backend/models" +) + +type MapDiscussionResponse struct { + Discussion MapDiscussion `json:"discussion"` +} + +type MapDiscussionsResponse struct { + Discussions []MapDiscussionOnlyTitle `json:"discussions"` +} + +type MapDiscussion struct { + ID int `json:"id"` + Creator models.UserShortWithAvatar `json:"creator"` + Title string `json:"title"` + Content string `json:"content"` + // Upvotes int `json:"upvotes"` + UpdatedAt time.Time `json:"updated_at"` + Comments []MapDiscussionComment `json:"comments"` +} + +type MapDiscussionOnlyTitle struct { + ID int `json:"id"` + Creator models.UserShortWithAvatar `json:"creator"` + Title string `json:"title"` + // Upvotes int `json:"upvotes"` + UpdatedAt time.Time `json:"updated_at"` + Comments []MapDiscussionComment `json:"comments"` +} + +type MapDiscussionComment struct { + User models.UserShortWithAvatar `json:"user"` + Comment string `json:"comment"` + Date time.Time `json:"date"` +} + +type CreateMapDiscussionRequest struct { + Title string `json:"title" binding:"required"` + Content string `json:"content" binding:"required"` +} + +type EditMapDiscussionRequest struct { + Title string `json:"title" binding:"required"` + Content string `json:"content" binding:"required"` +} + +// GET Map Discussions +// +// @Description Get map discussions with specified map id. +// @Tags maps +// @Produce json +// @Param mapid path int true "Map ID" +// @Success 200 {object} models.Response{data=MapDiscussionsResponse} +// @Router /maps/{mapid}/discussions [get] +func FetchMapDiscussions(c *gin.Context) { + // TODO: get upvotes + response := MapDiscussionsResponse{} + mapID, err := strconv.Atoi(c.Param("mapid")) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + sql := `SELECT md.id, u.steam_id, u.user_name, u.avatar_link, md.title, md.updated_at FROM map_discussions md + INNER JOIN users u ON md.user_id = u.steam_id WHERE md.map_id = $1 + ORDER BY md.updated_at DESC` + rows, err := database.DB.Query(sql, mapID) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + // Get discussion data + for rows.Next() { + discussion := MapDiscussionOnlyTitle{} + err := rows.Scan(&discussion.ID, &discussion.Creator.SteamID, &discussion.Creator.UserName, &discussion.Creator.AvatarLink, &discussion.Title, &discussion.UpdatedAt) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + response.Discussions = append(response.Discussions, discussion) + } + c.JSON(http.StatusOK, models.Response{ + Success: true, + Message: "Successfully retrieved map discussions.", + Data: response, + }) +} + +// GET Map Discussion +// +// @Description Get map discussion with specified map and discussion id. +// @Tags maps +// @Produce json +// @Param mapid path int true "Map ID" +// @Param discussionid path int true "Discussion ID" +// @Success 200 {object} models.Response{data=MapDiscussionResponse} +// @Router /maps/{mapid}/discussions/{discussionid} [get] +func FetchMapDiscussion(c *gin.Context) { + // TODO: get upvotes + response := MapDiscussionResponse{} + mapID, err := strconv.Atoi(c.Param("mapid")) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + discussionID, err := strconv.Atoi(c.Param("discussionid")) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + sql := `SELECT md.id, u.steam_id, u.user_name, u.avatar_link, md.title, md.content, md.updated_at FROM map_discussions md + INNER JOIN users u ON md.user_id = u.steam_id WHERE md.map_id = $1 AND md.id = $2` + 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) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + // Get commments + sql = `SELECT u.steam_id, u.user_name, u.avatar_link, mdc.comment, mdc.created_at FROM map_discussions_comments mdc + INNER JOIN users u ON mdc.user_id = u.steam_id WHERE mdc.discussion_id = $1` + comments, err := database.DB.Query(sql, response.Discussion.ID) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + for comments.Next() { + comment := MapDiscussionComment{} + err = comments.Scan(&comment.User.SteamID, &comment.User.UserName, &comment.User.AvatarLink, &comment.Comment, &comment.Date) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + response.Discussion.Comments = append(response.Discussion.Comments, comment) + } + c.JSON(http.StatusOK, models.Response{ + Success: true, + Message: "Successfully retrieved map discussion.", + Data: response, + }) +} + +// POST Map Discussion +// +// @Description Create map discussion with specified map id. +// @Tags maps +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Param mapid path int true "Map ID" +// @Param discussionid path int true "Discussion ID" +// @Param request body CreateMapDiscussionRequest true "Body" +// @Success 200 {object} models.Response{data=CreateMapDiscussionRequest} +// @Router /maps/{mapid}/discussions [post] +func CreateMapDiscussion(c *gin.Context) { + mapID, err := strconv.Atoi(c.Param("mapid")) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + user, exists := c.Get("user") + if !exists { + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) + return + } + var request CreateMapDiscussionRequest + if err := c.BindJSON(&request); err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + sql := `INSERT INTO map_discussions (map_id,user_id,title,"content") + VALUES($1,$2,$3,$4);` + _, err = database.DB.Exec(sql, mapID, user.(models.User).SteamID, request.Title, request.Content) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + c.JSON(http.StatusOK, models.Response{ + Success: true, + Message: "Successfully created map discussion.", + Data: request, + }) +} + +// PUT Map Discussion +// +// @Description Edit map discussion with specified map id. +// @Tags maps +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Param mapid path int true "Map ID" +// @Param discussionid path int true "Discussion ID" +// @Param request body EditMapDiscussionRequest true "Body" +// @Success 200 {object} models.Response{data=EditMapDiscussionRequest} +// @Router /maps/{mapid}/discussions/{discussionid} [put] +func EditMapDiscussion(c *gin.Context) { + mapID, err := strconv.Atoi(c.Param("mapid")) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + discussionID, err := strconv.Atoi(c.Param("discussionid")) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + user, exists := c.Get("user") + if !exists { + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) + return + } + var request EditMapDiscussionRequest + if err := c.BindJSON(&request); err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + sql := `UPDATE map_discussions SET title = $4, content = $5, updated_at = $6 WHERE id = $1 AND map_id = $2 AND user_id = $3` + result, err := database.DB.Exec(sql, discussionID, mapID, user.(models.User).SteamID, request.Title, request.Content, time.Now().UTC()) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + affectedRows, err := result.RowsAffected() + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + if affectedRows == 0 { + c.JSON(http.StatusOK, models.ErrorResponse("You can only edit your own post.")) + return + } + c.JSON(http.StatusOK, models.Response{ + Success: true, + Message: "Successfully edited map discussion.", + Data: request, + }) +} + +// DELETE Map Summary +// +// @Description Delete map summary with specified map id. +// @Tags maps +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Param mapid path int true "Map ID" +// @Param discussionid path int true "Discussion ID" +// @Success 200 {object} models.Response +// @Router /maps/{mapid}/discussions/{discussionid} [delete] +func DeleteMapDiscussion(c *gin.Context) { + mapID, err := strconv.Atoi(c.Param("mapid")) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + discussionID, err := strconv.Atoi(c.Param("discussionid")) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + user, exists := c.Get("user") + if !exists { + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) + return + } + sql := `DELETE FROM map_discussions WHERE id = $1 AND map_id = $2 AND user_id = $3` + result, err := database.DB.Exec(sql, discussionID, mapID, user.(models.User).SteamID) + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + affectedRows, err := result.RowsAffected() + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + if affectedRows == 0 { + c.JSON(http.StatusOK, models.ErrorResponse("You can only delete your own post.")) + return + } + c.JSON(http.StatusOK, models.Response{ + Success: true, + Message: "Successfully deleted map discussion.", + Data: nil, + }) +} diff --git a/backend/handlers/home.go b/backend/handlers/home.go index 42e27be..c9742f2 100644 --- a/backend/handlers/home.go +++ b/backend/handlers/home.go @@ -35,7 +35,6 @@ type MapShortWithGame struct { // @Tags rankings // @Produce json // @Success 200 {object} models.Response{data=RankingsResponse} -// @Failure 400 {object} models.Response // @Router /rankings [get] func Rankings(c *gin.Context) { response := RankingsResponse{ @@ -142,7 +141,6 @@ func Rankings(c *gin.Context) { // @Produce json // @Param q query string false "Search user or map name." // @Success 200 {object} models.Response{data=SearchResponse} -// @Failure 400 {object} models.Response // @Router /search [get] func SearchWithQuery(c *gin.Context) { query := c.Query("q") diff --git a/backend/handlers/login.go b/backend/handlers/login.go index a7e4379..dc6e4a5 100644 --- a/backend/handlers/login.go +++ b/backend/handlers/login.go @@ -26,7 +26,6 @@ type LoginResponse struct { // @Accept json // @Produce json // @Success 200 {object} models.Response{data=LoginResponse} -// @Failure 400 {object} models.Response // @Router /login [get] func Login(c *gin.Context) { openID := steam_go.NewOpenId(c.Request) diff --git a/backend/handlers/logs.go b/backend/handlers/logs.go index b6bcef6..6f59238 100644 --- a/backend/handlers/logs.go +++ b/backend/handlers/logs.go @@ -78,7 +78,6 @@ type ScoreLogsResponseDetails struct { // @Produce json // @Param Authorization header string true "JWT Token" // @Success 200 {object} models.Response{data=LogsResponse} -// @Failure 400 {object} models.Response // @Router /logs/mod [get] func ModLogs(c *gin.Context) { mod, exists := c.Get("mod") @@ -125,7 +124,6 @@ func ModLogs(c *gin.Context) { // @Tags logs // @Produce json // @Success 200 {object} models.Response{data=ScoreLogsResponse} -// @Failure 400 {object} models.Response // @Router /logs/score [get] func ScoreLogs(c *gin.Context) { response := ScoreLogsResponse{Logs: []ScoreLogsResponseDetails{}} diff --git a/backend/handlers/map.go b/backend/handlers/map.go index f3198ff..3bf14cd 100644 --- a/backend/handlers/map.go +++ b/backend/handlers/map.go @@ -58,12 +58,11 @@ type RecordMultiplayer struct { // @Description Get map summary with specified id. // @Tags maps // @Produce json -// @Param id path int true "Map ID" -// @Success 200 {object} models.Response{data=MapSummaryResponse} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/summary [get] +// @Param mapid path int true "Map ID" +// @Success 200 {object} models.Response{data=MapSummaryResponse} +// @Router /maps/{mapid}/summary [get] func FetchMapSummary(c *gin.Context) { - id := c.Param("id") + id := c.Param("mapid") response := MapSummaryResponse{Map: models.Map{}, Summary: models.MapSummary{Routes: []models.MapRoute{}}} intID, err := strconv.Atoi(id) if err != nil { @@ -138,14 +137,13 @@ func FetchMapSummary(c *gin.Context) { // @Description Get map leaderboards with specified id. // @Tags maps // @Produce json -// @Param id path int true "Map ID" +// @Param mapid path int true "Map ID" // @Param page query int false "Page Number (default: 1)" // @Param pageSize query int false "Number of Records Per Page (default: 20)" // @Success 200 {object} models.Response{data=MapLeaderboardsResponse} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/leaderboards [get] +// @Router /maps/{mapid}/leaderboards [get] func FetchMapLeaderboards(c *gin.Context) { - id := c.Param("id") + id := c.Param("mapid") // Get map data response := MapLeaderboardsResponse{Map: models.Map{}, Records: nil, Pagination: models.Pagination{}} page, err := strconv.Atoi(c.DefaultQuery("page", "1")) @@ -349,12 +347,11 @@ func FetchGames(c *gin.Context) { // @Description Get chapters from the specified game id. // @Tags games & chapters // @Produce json -// @Param id path int true "Game ID" -// @Success 200 {object} models.Response{data=ChaptersResponse} -// @Failure 400 {object} models.Response -// @Router /games/{id} [get] +// @Param gameid path int true "Game ID" +// @Success 200 {object} models.Response{data=ChaptersResponse} +// @Router /games/{gameid} [get] func FetchChapters(c *gin.Context) { - gameID := c.Param("id") + gameID := c.Param("gameid") intID, err := strconv.Atoi(gameID) if err != nil { c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) @@ -391,12 +388,12 @@ func FetchChapters(c *gin.Context) { // @Description Get maps from the specified chapter id. // @Tags games & chapters // @Produce json -// @Param id path int true "Chapter ID" -// @Success 200 {object} models.Response{data=ChapterMapsResponse} -// @Failure 400 {object} models.Response -// @Router /chapters/{id} [get] +// @Param chapterid path int true "Chapter ID" +// @Success 200 {object} models.Response{data=ChapterMapsResponse} +// @Failure 400 {object} models.Response +// @Router /chapters/{chapterid} [get] func FetchChapterMaps(c *gin.Context) { - chapterID := c.Param("id") + chapterID := c.Param("chapterid") intID, err := strconv.Atoi(chapterID) if err != nil { c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) diff --git a/backend/handlers/mod.go b/backend/handlers/mod.go index 1d04a96..3559887 100644 --- a/backend/handlers/mod.go +++ b/backend/handlers/mod.go @@ -42,11 +42,10 @@ type EditMapImageRequest struct { // @Tags maps // @Produce json // @Param Authorization header string true "JWT Token" -// @Param id path int true "Map ID" +// @Param mapid path int true "Map ID" // @Param request body CreateMapSummaryRequest true "Body" // @Success 200 {object} models.Response{data=CreateMapSummaryRequest} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/summary [post] +// @Router /maps/{mapid}/summary [post] func CreateMapSummary(c *gin.Context) { // Check if user exists user, exists := c.Get("user") @@ -60,7 +59,7 @@ func CreateMapSummary(c *gin.Context) { return } // Bind parameter and body - id := c.Param("id") + id := c.Param("mapid") mapID, err := strconv.Atoi(id) if err != nil { c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) @@ -123,11 +122,10 @@ func CreateMapSummary(c *gin.Context) { // @Tags maps // @Produce json // @Param Authorization header string true "JWT Token" -// @Param id path int true "Map ID" +// @Param mapid path int true "Map ID" // @Param request body EditMapSummaryRequest true "Body" // @Success 200 {object} models.Response{data=EditMapSummaryRequest} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/summary [put] +// @Router /maps/{mapid}/summary [put] func EditMapSummary(c *gin.Context) { // Check if user exists user, exists := c.Get("user") @@ -141,7 +139,7 @@ func EditMapSummary(c *gin.Context) { return } // Bind parameter and body - id := c.Param("id") + id := c.Param("mapid") mapID, err := strconv.Atoi(id) if err != nil { c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) @@ -204,11 +202,10 @@ func EditMapSummary(c *gin.Context) { // @Tags maps // @Produce json // @Param Authorization header string true "JWT Token" -// @Param id path int true "Map ID" +// @Param mapid path int true "Map ID" // @Param request body DeleteMapSummaryRequest true "Body" // @Success 200 {object} models.Response{data=DeleteMapSummaryRequest} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/summary [delete] +// @Router /maps/{mapid}/summary [delete] func DeleteMapSummary(c *gin.Context) { // Check if user exists user, exists := c.Get("user") @@ -222,7 +219,7 @@ func DeleteMapSummary(c *gin.Context) { return } // Bind parameter and body - id := c.Param("id") + id := c.Param("mapid") mapID, err := strconv.Atoi(id) if err != nil { c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) @@ -289,11 +286,10 @@ func DeleteMapSummary(c *gin.Context) { // @Tags maps // @Produce json // @Param Authorization header string true "JWT Token" -// @Param id path int true "Map ID" +// @Param mapid path int true "Map ID" // @Param request body EditMapImageRequest true "Body" // @Success 200 {object} models.Response{data=EditMapImageRequest} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/image [put] +// @Router /maps/{mapid}/image [put] func EditMapImage(c *gin.Context) { // Check if user exists user, exists := c.Get("user") @@ -307,7 +303,7 @@ func EditMapImage(c *gin.Context) { return } // Bind parameter and body - id := c.Param("id") + id := c.Param("mapid") mapID, err := strconv.Atoi(id) if err != nil { c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) diff --git a/backend/handlers/record.go b/backend/handlers/record.go index 75b5583..70234c3 100644 --- a/backend/handlers/record.go +++ b/backend/handlers/record.go @@ -37,18 +37,16 @@ type RecordResponse struct { // @Tags maps // @Accept mpfd // @Produce json -// @Param id path int true "Map ID" +// @Param mapid path int true "Map ID" // @Param Authorization header string true "JWT Token" // @Param host_demo formData file true "Host Demo" // @Param partner_demo formData file false "Partner Demo" // @Param is_partner_orange formData boolean false "Is Partner Orange" // @Param partner_id formData string false "Partner ID" // @Success 200 {object} models.Response{data=RecordResponse} -// @Failure 400 {object} models.Response -// @Failure 401 {object} models.Response -// @Router /maps/{id}/record [post] +// @Router /maps/{mapid}/record [post] func CreateRecordWithDemo(c *gin.Context) { - mapId := c.Param("id") + mapId := c.Param("mapid") // Check if user exists user, exists := c.Get("user") if !exists { @@ -216,9 +214,8 @@ func CreateRecordWithDemo(c *gin.Context) { // @Tags demo // @Accept json // @Produce octet-stream -// @Param uuid query string true "Demo UUID" -// @Success 200 {file} binary "Demo File" -// @Failure 400 {object} models.Response +// @Param uuid query string true "Demo UUID" +// @Success 200 {file} binary "Demo File" // @Router /demos [get] func DownloadDemoWithID(c *gin.Context) { uuid := c.Query("uuid") diff --git a/backend/handlers/user.go b/backend/handlers/user.go index 2df2040..f04145e 100644 --- a/backend/handlers/user.go +++ b/backend/handlers/user.go @@ -63,8 +63,6 @@ type ScoreResponse struct { // @Produce json // @Param Authorization header string true "JWT Token" // @Success 200 {object} models.Response{data=ProfileResponse} -// @Failure 400 {object} models.Response -// @Failure 401 {object} models.Response // @Router /profile [get] func Profile(c *gin.Context) { // Check if user exists @@ -343,13 +341,11 @@ func Profile(c *gin.Context) { // @Tags users // @Accept json // @Produce json -// @Param id path int true "User ID" -// @Success 200 {object} models.Response{data=ProfileResponse} -// @Failure 400 {object} models.Response -// @Failure 404 {object} models.Response -// @Router /users/{id} [get] +// @Param userid path int true "User ID" +// @Success 200 {object} models.Response{data=ProfileResponse} +// @Router /users/{userid} [get] func FetchUser(c *gin.Context) { - id := c.Param("id") + id := c.Param("userid") // Check if id is all numbers and 17 length match, _ := regexp.MatchString("^[0-9]{17}$", id) if !match { @@ -634,8 +630,6 @@ func FetchUser(c *gin.Context) { // @Produce json // @Param Authorization header string true "JWT Token" // @Success 200 {object} models.Response{data=ProfileResponse} -// @Failure 400 {object} models.Response -// @Failure 401 {object} models.Response // @Router /profile [post] func UpdateUser(c *gin.Context) { // Check if user exists @@ -681,8 +675,6 @@ func UpdateUser(c *gin.Context) { // @Param Authorization header string true "JWT Token" // @Param country_code query string true "Country Code [XX]" // @Success 200 {object} models.Response -// @Failure 400 {object} models.Response -// @Failure 401 {object} models.Response // @Router /profile [put] func UpdateCountryCode(c *gin.Context) { // Check if user exists -- cgit v1.2.3