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 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 26 deletions(-) (limited to 'backend/api/routes.go') 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) } } -- cgit v1.2.3