busybar / cmd / api / main.go
main.go
Raw
package main

import (
	"github.com/danielrhuynh/busybar/internal/auth"
	"github.com/danielrhuynh/busybar/internal/controllers"

	"github.com/go-playground/validator"

	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"

	"github.com/rs/cors"
)

func main() {
	e := echo.New()

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	corsMiddleware := cors.New(cors.Options{
		AllowedOrigins:   []string{"http://localhost:4000"},
		AllowedMethods:   []string{"GET", "POST", "PUT", "DELETE"},
		AllowedHeaders:   []string{"Authorization", "Content-Type"},
		AllowCredentials: true,
	})

	e.Use(echo.WrapMiddleware(corsMiddleware.Handler))
	e.Validator = &CustomValidator{Validator: validator.New()}

	public, user, _ := auth.CreateRouteGroups(e)

	public.GET("/v1/healthcheck", controllers.HealthCheck)

	// ----- AUTH ROUTES -----
	public.GET("/v1/auth/:provider/url", controllers.GetAuthURL)
	public.GET("/v1/auth/:provider/callback", controllers.AuthCallback)
	// user.POST("/v1/auth/rotate-token", controllers.AuthRotateToken)
	user.GET("/v1/auth/session", controllers.AuthGetSession)
	user.GET("/v1/auth/logout", controllers.AuthLogout)

	// ----- USER ROUTES -----
	user.POST("/v1/user/register", controllers.UserRegister)
	user.DELETE("/v1/user/delete", controllers.UserDeleteAccount)

	// ----- REPORTS ROUTES -----
	user.POST("/v1/report-data", controllers.CreateReport)
	user.GET("/v1/get/user-data", controllers.GetUserWaitTimes)
	user.GET("/v1/get/average-wait-times", controllers.GetAverageWaitTimes)

	// ----- ANALYTICS ROUTES -----
	e.GET("/v1/get/busiest-days", controllers.GetBusiestDays)
	e.GET("/v1/get/busiest-bar", controllers.GetBusiestBar)
	e.GET("/v1/get/trending-bars", controllers.GetTrendingBars)
	e.GET("/v1/get/shortest-wait", controllers.GetShortestWaitBar)
	e.GET("/v1/get/bars", controllers.GetBarsList)

	// ----- ACHIEVEMENTS ROUTES -----
	user.GET("/v1/achievements", controllers.GetUserAchievements)

	e.Logger.Fatal(e.Start(":4000"))
}