aboutsummaryrefslogtreecommitdiff
path: root/backend/api/routes.go
blob: ecfb54b5d09378d63807e1cc493b2f7391a24872 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package api

import (
	"lphub/handlers"

	"github.com/gin-gonic/gin"
	swaggerfiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func InitRoutes(router *gin.Engine) {
	api := router.Group("/api")
	{
		v1 := api.Group("/v1")
		// Swagger
		v1.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
		v1.GET("/", func(c *gin.Context) {
			c.File("docs/index.html")
		})
		// Tokens, login
		v1.GET("/token", handlers.GetCookie)
		v1.DELETE("/token", handlers.DeleteCookie)
		v1.GET("/login", handlers.Login)
		// Users, profiles
		v1.GET("/profile", IsAuthenticated, handlers.Profile)
		v1.PUT("/profile", IsAuthenticated, handlers.UpdateCountryCode)
		v1.POST("/profile", IsAuthenticated, handlers.UpdateUser)
		v1.GET("/users/:userid", IsAuthenticated, handlers.FetchUser)
		// Maps
		// - Summary
		v1.GET("/maps/:mapid/summary", handlers.FetchMapSummary)
		v1.POST("/maps/:mapid/summary", IsAuthenticated, handlers.CreateMapSummary)
		v1.PUT("/maps/:mapid/summary", IsAuthenticated, handlers.EditMapSummary)
		v1.DELETE("/maps/:mapid/summary", IsAuthenticated, handlers.DeleteMapSummary)
		v1.PUT("/maps/:mapid/image", IsAuthenticated, handlers.EditMapImage)
		// - Leaderboards
		v1.GET("/maps/:mapid/leaderboards", handlers.FetchMapLeaderboards)
		v1.POST("/maps/:mapid/record", IsAuthenticated, handlers.CreateRecordWithDemo)
		v1.DELETE("/maps/:mapid/record/:recordid", IsAuthenticated, handlers.DeleteRecord)
		v1.GET("/demos", handlers.DownloadDemoWithID)
		// - Discussions
		v1.GET("/maps/:mapid/discussions", handlers.FetchMapDiscussions)
		v1.GET("/maps/:mapid/discussions/:discussionid", handlers.FetchMapDiscussion)
		v1.POST("/maps/:mapid/discussions", IsAuthenticated, handlers.CreateMapDiscussion)
		v1.POST("/maps/:mapid/discussions/:discussionid", IsAuthenticated, handlers.CreateMapDiscussionComment)
		v1.PUT("/maps/:mapid/discussions/:discussionid", IsAuthenticated, handlers.EditMapDiscussion)
		v1.DELETE("/maps/:mapid/discussions/:discussionid", IsAuthenticated, handlers.DeleteMapDiscussion)
		// Rankings, search
		v1.GET("/rankings/lphub", handlers.RankingsLPHUB)
		v1.GET("/rankings/steam", handlers.RankingsSteam)
		v1.GET("/search", handlers.SearchWithQuery)
		// Games, chapters, maps
		v1.GET("/games", handlers.FetchGames)
		v1.GET("/games/:gameid", handlers.FetchChapters)
		v1.GET("/chapters/:chapterid", handlers.FetchChapterMaps)
		v1.GET("/games/:gameid/maps", handlers.FetchMaps)
		// Logs
		v1.GET("/logs/score", handlers.ScoreLogs)
		// v1.GET("/logs/mod", IsAuthenticated, handlers.ModLogs)
	}
}