aboutsummaryrefslogtreecommitdiff
path: root/backend/api/routes.go
blob: 81f1ec6d153ba4fbcaf1f68b77447125c81f2e8a (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package api

import (
	"lphub/handlers"

	"github.com/gin-gonic/gin"
	swaggerfiles "github.com/swaggo/files"
	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"
	mapRecordIDPath     string = "/maps/:mapid/record/:recordid"
	mapDiscussionsPath  string = "/maps/:mapid/discussions"
	mapDiscussionIDPath string = "/maps/:mapid/discussions/:discussionid"
	rankingsLPHUBPath   string = "/rankings/lphub"
	rankingsSteamPath   string = "/rankings/steam"
	searchPath          string = "/search"
	gamesPath           string = "/games"
	chaptersPath        string = "/games/:gameid"
	gameMapsPath        string = "/games/:gameid/maps"
	chapterMapsPath     string = "/chapters/:chapterid"
	scoreLogsPath       string = "/logs/score"
	modLogsPath         string = "/logs/mod"
)

func InitRoutes(router *gin.Engine) {
	api := router.Group(apiPath)
	{
		v1 := api.Group(v1Path)
		// Swagger
		v1.GET(swaggerPath, ginSwagger.WrapHandler(swaggerfiles.Handler))
		v1.GET(indexPath, func(c *gin.Context) {
			c.File("docs/index.html")
		})
		// 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
		// - Summary
		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)
		// - Leaderboards
		v1.GET(mapLeaderboardsPath, handlers.FetchMapLeaderboards)
		v1.POST(mapRecordPath, CheckAuth, handlers.CreateRecordWithDemo)
		v1.DELETE(mapRecordIDPath, CheckAuth, handlers.DeleteRecord)
		v1.GET(demosPath, handlers.DownloadDemoWithID)
		// - Discussions
		v1.GET(mapDiscussionsPath, handlers.FetchMapDiscussions)
		v1.GET(mapDiscussionIDPath, handlers.FetchMapDiscussion)
		v1.POST(mapDiscussionsPath, CheckAuth, handlers.CreateMapDiscussion)
		v1.POST(mapDiscussionIDPath, CheckAuth, handlers.CreateMapDiscussionComment)
		v1.PUT(mapDiscussionIDPath, CheckAuth, handlers.EditMapDiscussion)
		v1.DELETE(mapDiscussionIDPath, CheckAuth, handlers.DeleteMapDiscussion)
		// Rankings, search
		v1.GET(rankingsLPHUBPath, handlers.RankingsLPHUB)
		v1.GET(rankingsSteamPath, handlers.RankingsSteam)
		v1.GET(searchPath, handlers.SearchWithQuery)
		// Games, chapters, maps
		v1.GET(gamesPath, handlers.FetchGames)
		v1.GET(chaptersPath, handlers.FetchChapters)
		v1.GET(chapterMapsPath, handlers.FetchChapterMaps)
		v1.GET(gameMapsPath, handlers.FetchMaps)
		// Logs
		v1.GET(scoreLogsPath, handlers.ScoreLogs)
		v1.GET(modLogsPath, CheckAuth, handlers.ModLogs)
	}
}