164 lines
5.3 KiB
Go
164 lines
5.3 KiB
Go
package platform
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/rs/zerolog"
|
|
"go.uber.org/fx"
|
|
|
|
"base/config"
|
|
appAsset "base/internal/application/asset"
|
|
appAuth "base/internal/application/auth"
|
|
appDiscovery "base/internal/application/discovery"
|
|
appLanding "base/internal/application/landing"
|
|
appProfile "base/internal/application/profile"
|
|
appProfileRole "base/internal/application/profilerole"
|
|
appSkill "base/internal/application/skill"
|
|
appSpecialist "base/internal/application/specialist"
|
|
"base/internal/server/middleware"
|
|
)
|
|
|
|
type Controller struct {
|
|
logger zerolog.Logger
|
|
middleware middleware.Middleware
|
|
config *config.AppConfig
|
|
e *gin.Engine
|
|
authService appAuth.Service
|
|
profileService appProfile.Service
|
|
profileRoleService appProfileRole.Service
|
|
skillService appSkill.Service
|
|
assetService appAsset.Service
|
|
discoveryService appDiscovery.Service
|
|
landingService appLanding.Service
|
|
specialistService appSpecialist.Service
|
|
}
|
|
|
|
type Param struct {
|
|
Logger zerolog.Logger
|
|
Engine *gin.Engine
|
|
Middleware middleware.Middleware
|
|
Config *config.AppConfig
|
|
AuthService appAuth.Service
|
|
ProfileService appProfile.Service
|
|
ProfileRoleService appProfileRole.Service
|
|
SkillService appSkill.Service
|
|
AssetService appAsset.Service
|
|
DiscoveryService appDiscovery.Service
|
|
LandingService appLanding.Service
|
|
SpecialistService appSpecialist.Service
|
|
|
|
fx.In
|
|
}
|
|
|
|
func New(lc fx.Lifecycle, param Param) *Controller {
|
|
c := &Controller{
|
|
logger: param.Logger,
|
|
e: param.Engine,
|
|
middleware: param.Middleware,
|
|
config: param.Config,
|
|
authService: param.AuthService,
|
|
profileService: param.ProfileService,
|
|
profileRoleService: param.ProfileRoleService,
|
|
skillService: param.SkillService,
|
|
assetService: param.AssetService,
|
|
discoveryService: param.DiscoveryService,
|
|
landingService: param.LandingService,
|
|
specialistService: param.SpecialistService,
|
|
}
|
|
|
|
lc.Append(
|
|
fx.Hook{
|
|
OnStart: func(ctx context.Context) error {
|
|
c.SetupRouter()
|
|
|
|
return nil
|
|
},
|
|
OnStop: func(ctx context.Context) error {
|
|
return nil
|
|
},
|
|
},
|
|
)
|
|
|
|
return c
|
|
}
|
|
|
|
func (ctl *Controller) SetupRouter() {
|
|
apiRouter := ctl.e.Group("/api")
|
|
ctl.registerRoutes(apiRouter.Group("/v1"))
|
|
ctl.registerSpecialistRoutes(apiRouter.Group("/specialists/v1"))
|
|
}
|
|
|
|
func (ctl *Controller) registerRoutes(router *gin.RouterGroup) {
|
|
authRouter := router.Group("/auth")
|
|
ctl.registerAuthRoutes(authRouter)
|
|
|
|
accountRouter := router.Group("/account")
|
|
ctl.registerAccountRoutes(accountRouter)
|
|
|
|
profileRouter := router.Group("/profiles")
|
|
ctl.registerProfileRoutes(profileRouter)
|
|
ctl.registerAssetRoutes(router)
|
|
|
|
platformRouter := router.Group("/platform")
|
|
ctl.registerPlatformRoutes(platformRouter)
|
|
|
|
landingRouter := router.Group("/landing")
|
|
ctl.registerLandingRoutes(landingRouter)
|
|
}
|
|
|
|
func (ctl *Controller) registerPlatformRoutes(platformRouter *gin.RouterGroup) {
|
|
protected := platformRouter.Use(ctl.middleware.AuthShield())
|
|
protected.GET("/profile-roles", ctl.ListProfileRoles)
|
|
protected.GET("/skills", ctl.ListSkills)
|
|
protected.GET("/overview/discovery", ctl.GetDiscoveryOverview)
|
|
protected.GET("/overview/specialist", ctl.GetSpecialistOverview)
|
|
protected.POST("/verify-account", ctl.VerifyAccount)
|
|
protected.POST("/setup-profile", ctl.SetupProfile)
|
|
}
|
|
|
|
func (ctl *Controller) registerLandingRoutes(landingRouter *gin.RouterGroup) {
|
|
landingRouter.GET("", ctl.GetLanding)
|
|
}
|
|
|
|
func (ctl *Controller) registerAuthRoutes(authRouter *gin.RouterGroup) {
|
|
authRouter.POST("/login", ctl.LoginWithCredentials)
|
|
authRouter.POST("/register", ctl.RegisterWithCredentials)
|
|
authRouter.POST("/refresh-token", ctl.RefreshToken)
|
|
authRouter.POST("/oauth/redirect-url", ctl.GetOauthRedirectURL)
|
|
authRouter.GET("/oauth/callback/:provider", ctl.OauthCallbackGET)
|
|
authRouter.POST("/oauth/callback", ctl.OauthCallback)
|
|
authRouter.POST("/send-reset-password-email", ctl.SendResetPasswordEmail)
|
|
authRouter.POST("/reset-password", ctl.ResetPassword)
|
|
|
|
// Protected routes
|
|
protectedRoutes := authRouter.Use(ctl.middleware.AuthShield())
|
|
protectedRoutes.POST("/send-verification-email", ctl.SendVerificationEmail)
|
|
}
|
|
|
|
func (ctl *Controller) registerAccountRoutes(accountRouter *gin.RouterGroup) {
|
|
protected := accountRouter.Use(ctl.middleware.AuthShield())
|
|
protected.GET("/info", ctl.GetUserInfo)
|
|
}
|
|
|
|
func (ctl *Controller) registerProfileRoutes(profileRouter *gin.RouterGroup) {
|
|
profileRouter.POST("", ctl.CreateProfile)
|
|
profileRouter.GET("", ctl.ListProfiles)
|
|
profileRouter.GET("/handle/:handle", ctl.GetProfileByHandle)
|
|
profileRouter.GET("/:id/assets", ctl.ListAssetsByProfile)
|
|
profileRouter.GET("/:id", ctl.GetProfile)
|
|
profileRouter.PUT("/:id", ctl.UpdateProfile)
|
|
profileRouter.DELETE("/:id", ctl.DeleteProfile)
|
|
}
|
|
|
|
func (ctl *Controller) registerAssetRoutes(router *gin.RouterGroup) {
|
|
assetRouter := router.Group("/assets")
|
|
assetRouter.GET("/categories", ctl.ListAssetCategories)
|
|
assetRouter.POST("/categories/preview", ctl.ListCategoriesWithPreview)
|
|
assetRouter.GET("/categories/:id/assets", ctl.ListAssetsByCategoryID)
|
|
assetRouter.POST("", ctl.CreateAsset)
|
|
assetRouter.GET("/:id", ctl.GetAsset)
|
|
assetRouter.PUT("/:id", ctl.UpdateAsset)
|
|
assetRouter.DELETE("/:id", ctl.DeleteAsset)
|
|
}
|