211 lines
18 KiB
Go
211 lines
18 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"cmr-backend/internal/httpapi/handlers"
|
|
"cmr-backend/internal/httpapi/middleware"
|
|
"cmr-backend/internal/platform/jwtx"
|
|
"cmr-backend/internal/service"
|
|
)
|
|
|
|
func NewRouter(
|
|
appEnv string,
|
|
jwtManager *jwtx.Manager,
|
|
authService *service.AuthService,
|
|
opsAuthService *service.OpsAuthService,
|
|
opsSummaryService *service.OpsSummaryService,
|
|
entryService *service.EntryService,
|
|
entryHomeService *service.EntryHomeService,
|
|
adminAssetService *service.AdminAssetService,
|
|
adminResourceService *service.AdminResourceService,
|
|
adminProductionService *service.AdminProductionService,
|
|
adminEventService *service.AdminEventService,
|
|
adminPipelineService *service.AdminPipelineService,
|
|
eventService *service.EventService,
|
|
eventPlayService *service.EventPlayService,
|
|
publicExperienceService *service.PublicExperienceService,
|
|
configService *service.ConfigService,
|
|
homeService *service.HomeService,
|
|
mapExperienceService *service.MapExperienceService,
|
|
profileService *service.ProfileService,
|
|
resultService *service.ResultService,
|
|
sessionService *service.SessionService,
|
|
devService *service.DevService,
|
|
meService *service.MeService,
|
|
) http.Handler {
|
|
mux := http.NewServeMux()
|
|
|
|
healthHandler := handlers.NewHealthHandler()
|
|
authHandler := handlers.NewAuthHandler(authService)
|
|
opsAuthHandler := handlers.NewOpsAuthHandler(opsAuthService)
|
|
opsSummaryHandler := handlers.NewOpsSummaryHandler(opsSummaryService)
|
|
regionOptionsHandler := handlers.NewRegionOptionsHandler()
|
|
entryHandler := handlers.NewEntryHandler(entryService)
|
|
entryHomeHandler := handlers.NewEntryHomeHandler(entryHomeService)
|
|
adminAssetHandler := handlers.NewAdminAssetHandler(adminAssetService)
|
|
adminResourceHandler := handlers.NewAdminResourceHandler(adminResourceService)
|
|
adminProductionHandler := handlers.NewAdminProductionHandler(adminProductionService)
|
|
adminEventHandler := handlers.NewAdminEventHandler(adminEventService)
|
|
adminPipelineHandler := handlers.NewAdminPipelineHandler(adminPipelineService)
|
|
eventHandler := handlers.NewEventHandler(eventService)
|
|
eventPlayHandler := handlers.NewEventPlayHandler(eventPlayService)
|
|
publicExperienceHandler := handlers.NewPublicExperienceHandler(publicExperienceService)
|
|
configHandler := handlers.NewConfigHandler(configService)
|
|
homeHandler := handlers.NewHomeHandler(homeService)
|
|
mapExperienceHandler := handlers.NewMapExperienceHandler(mapExperienceService)
|
|
profileHandler := handlers.NewProfileHandler(profileService)
|
|
resultHandler := handlers.NewResultHandler(resultService)
|
|
sessionHandler := handlers.NewSessionHandler(sessionService)
|
|
devHandler := handlers.NewDevHandler(devService)
|
|
opsWorkbenchHandler := handlers.NewOpsWorkbenchHandler()
|
|
meHandler := handlers.NewMeHandler(meService)
|
|
authMiddleware := middleware.NewAuthMiddleware(jwtManager)
|
|
opsAuthMiddleware := middleware.NewOpsAuthMiddleware(jwtManager, appEnv)
|
|
|
|
mux.HandleFunc("GET /healthz", healthHandler.Get)
|
|
mux.HandleFunc("GET /home", homeHandler.GetHome)
|
|
mux.HandleFunc("GET /cards", homeHandler.GetCards)
|
|
mux.HandleFunc("GET /experience-maps", mapExperienceHandler.ListMaps)
|
|
mux.HandleFunc("GET /experience-maps/{mapAssetPublicID}", mapExperienceHandler.GetMapDetail)
|
|
mux.HandleFunc("GET /public/experience-maps", publicExperienceHandler.ListMaps)
|
|
mux.HandleFunc("GET /public/experience-maps/{mapAssetPublicID}", publicExperienceHandler.GetMapDetail)
|
|
mux.HandleFunc("GET /entry/resolve", entryHandler.Resolve)
|
|
mux.Handle("GET /admin/assets", authMiddleware(http.HandlerFunc(adminAssetHandler.ListAssets)))
|
|
mux.Handle("POST /admin/assets/register-link", authMiddleware(http.HandlerFunc(adminAssetHandler.RegisterLink)))
|
|
mux.Handle("POST /admin/assets/upload", authMiddleware(http.HandlerFunc(adminAssetHandler.UploadFile)))
|
|
mux.Handle("GET /admin/assets/{assetPublicID}", authMiddleware(http.HandlerFunc(adminAssetHandler.GetAsset)))
|
|
mux.Handle("GET /admin/maps", authMiddleware(http.HandlerFunc(adminResourceHandler.ListMaps)))
|
|
mux.Handle("POST /admin/maps", authMiddleware(http.HandlerFunc(adminResourceHandler.CreateMap)))
|
|
mux.Handle("GET /admin/maps/{mapPublicID}", authMiddleware(http.HandlerFunc(adminResourceHandler.GetMap)))
|
|
mux.Handle("POST /admin/maps/{mapPublicID}/versions", authMiddleware(http.HandlerFunc(adminResourceHandler.CreateMapVersion)))
|
|
mux.Handle("GET /admin/places", authMiddleware(http.HandlerFunc(adminProductionHandler.ListPlaces)))
|
|
mux.Handle("POST /admin/places", authMiddleware(http.HandlerFunc(adminProductionHandler.CreatePlace)))
|
|
mux.Handle("GET /admin/places/{placePublicID}", authMiddleware(http.HandlerFunc(adminProductionHandler.GetPlace)))
|
|
mux.Handle("GET /admin/map-assets", authMiddleware(http.HandlerFunc(adminProductionHandler.ListMapAssets)))
|
|
mux.Handle("POST /admin/places/{placePublicID}/map-assets", authMiddleware(http.HandlerFunc(adminProductionHandler.CreateMapAsset)))
|
|
mux.Handle("GET /admin/map-assets/{mapAssetPublicID}", authMiddleware(http.HandlerFunc(adminProductionHandler.GetMapAsset)))
|
|
mux.Handle("PUT /admin/map-assets/{mapAssetPublicID}", authMiddleware(http.HandlerFunc(adminProductionHandler.UpdateMapAsset)))
|
|
mux.Handle("POST /admin/map-assets/{mapAssetPublicID}/tile-releases", authMiddleware(http.HandlerFunc(adminProductionHandler.CreateTileRelease)))
|
|
mux.Handle("POST /admin/map-assets/{mapAssetPublicID}/course-sets", authMiddleware(http.HandlerFunc(adminProductionHandler.CreateCourseSet)))
|
|
mux.Handle("GET /admin/course-sources", authMiddleware(http.HandlerFunc(adminProductionHandler.ListCourseSources)))
|
|
mux.Handle("POST /admin/course-sources", authMiddleware(http.HandlerFunc(adminProductionHandler.CreateCourseSource)))
|
|
mux.Handle("GET /admin/course-sources/{sourcePublicID}", authMiddleware(http.HandlerFunc(adminProductionHandler.GetCourseSource)))
|
|
mux.Handle("GET /admin/course-sets/{courseSetPublicID}", authMiddleware(http.HandlerFunc(adminProductionHandler.GetCourseSet)))
|
|
mux.Handle("POST /admin/course-sets/{courseSetPublicID}/variants", authMiddleware(http.HandlerFunc(adminProductionHandler.CreateCourseVariant)))
|
|
mux.Handle("GET /admin/runtime-bindings", authMiddleware(http.HandlerFunc(adminProductionHandler.ListRuntimeBindings)))
|
|
mux.Handle("POST /admin/runtime-bindings", authMiddleware(http.HandlerFunc(adminProductionHandler.CreateRuntimeBinding)))
|
|
mux.Handle("GET /admin/runtime-bindings/{runtimeBindingPublicID}", authMiddleware(http.HandlerFunc(adminProductionHandler.GetRuntimeBinding)))
|
|
mux.Handle("POST /admin/ops/tile-releases/import", authMiddleware(http.HandlerFunc(adminProductionHandler.ImportTileRelease)))
|
|
mux.Handle("POST /admin/ops/course-sets/import-kml-batch", authMiddleware(http.HandlerFunc(adminProductionHandler.ImportCourseSetKMLBatch)))
|
|
mux.Handle("GET /admin/playfields", authMiddleware(http.HandlerFunc(adminResourceHandler.ListPlayfields)))
|
|
mux.Handle("POST /admin/playfields", authMiddleware(http.HandlerFunc(adminResourceHandler.CreatePlayfield)))
|
|
mux.Handle("GET /admin/playfields/{playfieldPublicID}", authMiddleware(http.HandlerFunc(adminResourceHandler.GetPlayfield)))
|
|
mux.Handle("POST /admin/playfields/{playfieldPublicID}/versions", authMiddleware(http.HandlerFunc(adminResourceHandler.CreatePlayfieldVersion)))
|
|
mux.Handle("GET /admin/resource-packs", authMiddleware(http.HandlerFunc(adminResourceHandler.ListResourcePacks)))
|
|
mux.Handle("POST /admin/resource-packs", authMiddleware(http.HandlerFunc(adminResourceHandler.CreateResourcePack)))
|
|
mux.Handle("GET /admin/resource-packs/{resourcePackPublicID}", authMiddleware(http.HandlerFunc(adminResourceHandler.GetResourcePack)))
|
|
mux.Handle("POST /admin/resource-packs/{resourcePackPublicID}/versions", authMiddleware(http.HandlerFunc(adminResourceHandler.CreateResourcePackVersion)))
|
|
mux.Handle("GET /admin/events", authMiddleware(http.HandlerFunc(adminEventHandler.ListEvents)))
|
|
mux.Handle("POST /admin/events", authMiddleware(http.HandlerFunc(adminEventHandler.CreateEvent)))
|
|
mux.Handle("GET /admin/events/{eventPublicID}", authMiddleware(http.HandlerFunc(adminEventHandler.GetEvent)))
|
|
mux.Handle("PUT /admin/events/{eventPublicID}", authMiddleware(http.HandlerFunc(adminEventHandler.UpdateEvent)))
|
|
mux.Handle("POST /admin/events/{eventPublicID}/source", authMiddleware(http.HandlerFunc(adminEventHandler.SaveSource)))
|
|
mux.Handle("GET /admin/events/{eventPublicID}/presentations", authMiddleware(http.HandlerFunc(adminEventHandler.ListPresentations)))
|
|
mux.Handle("POST /admin/events/{eventPublicID}/presentations", authMiddleware(http.HandlerFunc(adminEventHandler.CreatePresentation)))
|
|
mux.Handle("POST /admin/events/{eventPublicID}/presentations/import", authMiddleware(http.HandlerFunc(adminEventHandler.ImportPresentation)))
|
|
mux.Handle("GET /admin/presentations/{presentationPublicID}", authMiddleware(http.HandlerFunc(adminEventHandler.GetPresentation)))
|
|
mux.Handle("GET /admin/events/{eventPublicID}/content-bundles", authMiddleware(http.HandlerFunc(adminEventHandler.ListContentBundles)))
|
|
mux.Handle("POST /admin/events/{eventPublicID}/content-bundles", authMiddleware(http.HandlerFunc(adminEventHandler.CreateContentBundle)))
|
|
mux.Handle("POST /admin/events/{eventPublicID}/content-bundles/import", authMiddleware(http.HandlerFunc(adminEventHandler.ImportContentBundle)))
|
|
mux.Handle("GET /admin/content-bundles/{contentBundlePublicID}", authMiddleware(http.HandlerFunc(adminEventHandler.GetContentBundle)))
|
|
mux.Handle("POST /admin/events/{eventPublicID}/defaults", authMiddleware(http.HandlerFunc(adminEventHandler.UpdateEventDefaults)))
|
|
mux.Handle("GET /admin/events/{eventPublicID}/pipeline", authMiddleware(http.HandlerFunc(adminPipelineHandler.GetEventPipeline)))
|
|
mux.Handle("POST /admin/sources/{sourceID}/build", authMiddleware(http.HandlerFunc(adminPipelineHandler.BuildSource)))
|
|
mux.Handle("GET /admin/builds/{buildID}", authMiddleware(http.HandlerFunc(adminPipelineHandler.GetBuild)))
|
|
mux.Handle("POST /admin/builds/{buildID}/publish", authMiddleware(http.HandlerFunc(adminPipelineHandler.PublishBuild)))
|
|
mux.Handle("GET /admin/releases/{releasePublicID}", authMiddleware(http.HandlerFunc(adminPipelineHandler.GetRelease)))
|
|
mux.Handle("POST /admin/releases/{releasePublicID}/runtime-binding", authMiddleware(http.HandlerFunc(adminPipelineHandler.BindReleaseRuntime)))
|
|
mux.Handle("POST /admin/events/{eventPublicID}/rollback", authMiddleware(http.HandlerFunc(adminPipelineHandler.RollbackRelease)))
|
|
if appEnv != "production" {
|
|
mux.HandleFunc("GET /dev/workbench", devHandler.Workbench)
|
|
mux.HandleFunc("GET /admin/ops-workbench", opsWorkbenchHandler.Get)
|
|
mux.HandleFunc("POST /dev/bootstrap-demo", devHandler.BootstrapDemo)
|
|
mux.HandleFunc("POST /dev/client-logs", devHandler.CreateClientLog)
|
|
mux.HandleFunc("GET /dev/client-logs", devHandler.ListClientLogs)
|
|
mux.HandleFunc("DELETE /dev/client-logs", devHandler.ClearClientLogs)
|
|
mux.HandleFunc("GET /dev/manifest-summary", devHandler.ManifestSummary)
|
|
mux.HandleFunc("GET /dev/demo-assets/manifests/{demoKey}", devHandler.DemoGameManifest)
|
|
mux.HandleFunc("GET /dev/demo-assets/presentations/{demoKey}", devHandler.DemoPresentationSchema)
|
|
mux.HandleFunc("GET /dev/demo-assets/content-manifests/{demoKey}", devHandler.DemoContentManifest)
|
|
mux.HandleFunc("GET /dev/config/local-files", configHandler.ListLocalFiles)
|
|
mux.HandleFunc("POST /dev/events/{eventPublicID}/config-sources/import-local", configHandler.ImportLocal)
|
|
mux.HandleFunc("POST /dev/config-builds/preview", configHandler.BuildPreview)
|
|
mux.HandleFunc("POST /dev/config-builds/publish", configHandler.PublishBuild)
|
|
}
|
|
mux.Handle("GET /me/entry-home", authMiddleware(http.HandlerFunc(entryHomeHandler.Get)))
|
|
mux.Handle("GET /me/profile", authMiddleware(http.HandlerFunc(profileHandler.Get)))
|
|
mux.HandleFunc("GET /events/{eventPublicID}", eventHandler.GetDetail)
|
|
mux.HandleFunc("GET /public/events/{eventPublicID}", publicExperienceHandler.GetEventDetail)
|
|
mux.HandleFunc("GET /public/events/{eventPublicID}/play", publicExperienceHandler.GetEventPlay)
|
|
mux.HandleFunc("POST /public/events/{eventPublicID}/launch", publicExperienceHandler.Launch)
|
|
mux.Handle("GET /events/{eventPublicID}/play", authMiddleware(http.HandlerFunc(eventPlayHandler.Get)))
|
|
mux.Handle("GET /events/{eventPublicID}/config-sources", authMiddleware(http.HandlerFunc(configHandler.ListSources)))
|
|
mux.Handle("POST /events/{eventPublicID}/launch", authMiddleware(http.HandlerFunc(eventHandler.Launch)))
|
|
mux.Handle("GET /config-sources/{sourceID}", authMiddleware(http.HandlerFunc(configHandler.GetSource)))
|
|
mux.Handle("GET /config-builds/{buildID}", authMiddleware(http.HandlerFunc(configHandler.GetBuild)))
|
|
mux.Handle("GET /sessions/{sessionPublicID}", authMiddleware(http.HandlerFunc(sessionHandler.GetDetail)))
|
|
mux.Handle("GET /sessions/{sessionPublicID}/result", authMiddleware(http.HandlerFunc(resultHandler.GetSessionResult)))
|
|
mux.HandleFunc("POST /sessions/{sessionPublicID}/start", sessionHandler.Start)
|
|
mux.HandleFunc("POST /sessions/{sessionPublicID}/finish", sessionHandler.Finish)
|
|
mux.HandleFunc("POST /auth/sms/send", authHandler.SendSMSCode)
|
|
mux.HandleFunc("POST /auth/login/sms", authHandler.LoginSMS)
|
|
mux.HandleFunc("POST /auth/login/wechat-mini", authHandler.LoginWechatMini)
|
|
mux.HandleFunc("POST /ops/auth/sms/send", opsAuthHandler.SendSMSCode)
|
|
mux.HandleFunc("POST /ops/auth/register", opsAuthHandler.Register)
|
|
mux.HandleFunc("POST /ops/auth/login/sms", opsAuthHandler.LoginSMS)
|
|
mux.HandleFunc("POST /ops/auth/refresh", opsAuthHandler.Refresh)
|
|
mux.HandleFunc("POST /ops/auth/logout", opsAuthHandler.Logout)
|
|
mux.Handle("GET /ops/me", opsAuthMiddleware(http.HandlerFunc(opsAuthHandler.Me)))
|
|
mux.Handle("POST /auth/bind/mobile", authMiddleware(http.HandlerFunc(authHandler.BindMobile)))
|
|
mux.HandleFunc("POST /auth/refresh", authHandler.Refresh)
|
|
mux.HandleFunc("POST /auth/logout", authHandler.Logout)
|
|
mux.Handle("GET /me", authMiddleware(http.HandlerFunc(meHandler.Get)))
|
|
mux.Handle("GET /me/sessions", authMiddleware(http.HandlerFunc(sessionHandler.ListMine)))
|
|
mux.Handle("GET /me/results", authMiddleware(http.HandlerFunc(resultHandler.ListMine)))
|
|
mux.Handle("GET /ops/admin/summary", opsAuthMiddleware(http.HandlerFunc(opsSummaryHandler.GetOverview)))
|
|
mux.Handle("GET /ops/admin/region-options", opsAuthMiddleware(http.HandlerFunc(regionOptionsHandler.Get)))
|
|
mux.Handle("GET /ops/admin/assets", opsAuthMiddleware(http.HandlerFunc(adminAssetHandler.ListAssets)))
|
|
mux.Handle("POST /ops/admin/assets/register-link", opsAuthMiddleware(http.HandlerFunc(adminAssetHandler.RegisterLink)))
|
|
mux.Handle("POST /ops/admin/assets/upload", opsAuthMiddleware(http.HandlerFunc(adminAssetHandler.UploadFile)))
|
|
mux.Handle("GET /ops/admin/assets/{assetPublicID}", opsAuthMiddleware(http.HandlerFunc(adminAssetHandler.GetAsset)))
|
|
mux.Handle("GET /ops/admin/places", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.ListPlaces)))
|
|
mux.Handle("POST /ops/admin/places", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.CreatePlace)))
|
|
mux.Handle("GET /ops/admin/places/{placePublicID}", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.GetPlace)))
|
|
mux.Handle("GET /ops/admin/map-assets", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.ListMapAssets)))
|
|
mux.Handle("POST /ops/admin/places/{placePublicID}/map-assets", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.CreateMapAsset)))
|
|
mux.Handle("GET /ops/admin/map-assets/{mapAssetPublicID}", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.GetMapAsset)))
|
|
mux.Handle("PUT /ops/admin/map-assets/{mapAssetPublicID}", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.UpdateMapAsset)))
|
|
mux.Handle("POST /ops/admin/map-assets/{mapAssetPublicID}/tile-releases", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.CreateTileRelease)))
|
|
mux.Handle("POST /ops/admin/ops/tile-releases/import", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.ImportTileRelease)))
|
|
mux.Handle("GET /ops/admin/course-sources", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.ListCourseSources)))
|
|
mux.Handle("GET /ops/admin/course-sources/{sourcePublicID}", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.GetCourseSource)))
|
|
mux.Handle("GET /ops/admin/course-sets/{courseSetPublicID}", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.GetCourseSet)))
|
|
mux.Handle("POST /ops/admin/ops/course-sets/import-kml-batch", opsAuthMiddleware(http.HandlerFunc(adminProductionHandler.ImportCourseSetKMLBatch)))
|
|
mux.Handle("GET /ops/admin/events", opsAuthMiddleware(http.HandlerFunc(adminEventHandler.ListEvents)))
|
|
mux.Handle("POST /ops/admin/events", opsAuthMiddleware(http.HandlerFunc(adminEventHandler.CreateEvent)))
|
|
mux.Handle("GET /ops/admin/events/{eventPublicID}", opsAuthMiddleware(http.HandlerFunc(adminEventHandler.GetEvent)))
|
|
mux.Handle("PUT /ops/admin/events/{eventPublicID}", opsAuthMiddleware(http.HandlerFunc(adminEventHandler.UpdateEvent)))
|
|
mux.Handle("POST /ops/admin/events/{eventPublicID}/presentations/import", opsAuthMiddleware(http.HandlerFunc(adminEventHandler.ImportPresentation)))
|
|
mux.Handle("POST /ops/admin/events/{eventPublicID}/content-bundles/import", opsAuthMiddleware(http.HandlerFunc(adminEventHandler.ImportContentBundle)))
|
|
mux.Handle("POST /ops/admin/events/{eventPublicID}/defaults", opsAuthMiddleware(http.HandlerFunc(adminEventHandler.UpdateEventDefaults)))
|
|
mux.Handle("GET /ops/admin/events/{eventPublicID}/pipeline", opsAuthMiddleware(http.HandlerFunc(adminPipelineHandler.GetEventPipeline)))
|
|
mux.Handle("POST /ops/admin/sources/{sourceID}/build", opsAuthMiddleware(http.HandlerFunc(adminPipelineHandler.BuildSource)))
|
|
mux.Handle("GET /ops/admin/builds/{buildID}", opsAuthMiddleware(http.HandlerFunc(adminPipelineHandler.GetBuild)))
|
|
mux.Handle("POST /ops/admin/builds/{buildID}/publish", opsAuthMiddleware(http.HandlerFunc(adminPipelineHandler.PublishBuild)))
|
|
mux.Handle("GET /ops/admin/releases/{releasePublicID}", opsAuthMiddleware(http.HandlerFunc(adminPipelineHandler.GetRelease)))
|
|
mux.Handle("POST /ops/admin/events/{eventPublicID}/rollback", opsAuthMiddleware(http.HandlerFunc(adminPipelineHandler.RollbackRelease)))
|
|
|
|
return mux
|
|
}
|