Select Git revision
routes.go 6.33 KiB
package main
import (
"fmt"
"git.randomchars.net/levatax/tournament-website/oauth"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"log"
"net/http"
)
func registerRoutes() {
router.GET("/", func(context *gin.Context) {
authText, authRef := getAuthButton(oauth.GetSelf(context))
if ts, err := getTournaments(); err != nil {
log.Printf("error retrieving tournaments: %s", err)
context.String(http.StatusInternalServerError, "Internal Server Error")
return
} else {
populateTournaments(ts)
context.HTML(http.StatusOK, "index.tmpl", gin.H{
"auth_text": authText,
"auth_ref": authRef,
"tournaments": ts,
})
}
})
router.GET("/enroll/:id", func(context *gin.Context) {
user := oauth.GetSelf(context)
if user == nil {
context.Redirect(http.StatusTemporaryRedirect, "/auth/login")
return
}
// TODO: consume user stuff here
t := contextTournament(context)
if t == nil {
return
}
populateTournament(t)
authText, authRef := getAuthButton(user)
sy, sm, sd := t.StartTime.Date()
dy, dm, dd := t.Deadline.Date()
context.HTML(http.StatusOK, "form.tmpl", gin.H{
"auth_text": authText,
"auth_ref": authRef,
"tournament": tournamentPayload{
Title: t.Attributes["title"],
StartTimeString: fmt.Sprintf("%d-%.2d-%.2d", sy, sm, sd),
DeadlineString: fmt.Sprintf("%d-%.2d-%.2d", dy, dm, dd),
TeamSizeString: t.Attributes["size"],
Prize: t.Attributes["prize"],
},
})
})
router.POST("/enroll/:id", func(context *gin.Context) {
user := oauth.GetSelf(context)
if user == nil {
context.Redirect(http.StatusFound, "/auth/login")
return
}
// TODO: handle form submit
context.String(http.StatusOK, "TODO")