Onyx-API/internal/server/routes.go

72 lines
1.9 KiB
Go
Raw Permalink Normal View History

2023-09-15 18:21:04 +02:00
package server
import (
// github.com/labstack/echo/v4"
//"github.com/golang-jwt/jwt/v4"
//echojwt "github.com/labstack/echo-jwt"
"api-users/internal/chargers"
"api-users/internal/users"
//"api-users/internal/auth"
)
func (s *Server) Routes() error {
// Init repositories
usersRepo := users.NewUsersRepository(s.db)
chargersRepo := chargers.NewChargersRepository(s.db)
// Init controllers
usersController := users.NewUsersController(s.config, usersRepo, s.mailer)
chargersController := chargers.NewChargersController(s.config, chargersRepo)
// Init custom routes
usersRoutes := users.NewUsersRouter(s.config, usersController)
chargersRoutes := chargers.NewChargersRouter(s.config, chargersController)
//chargersHttp := chargers.NewChargersHttpHandlers
// Set routes
e := s.router
v1 := e.Group("/api/v1")
// Users routes
// usersGroup := v1.Group("/users")
usersRoutes.MapUsersRoutes(v1)
// Chargers routes
chargersGroup := v1.Group("/chargers")
chargersRoutes.MapChargersRoutes(chargersGroup)
return nil
/*log.Println("Loading routes...")
s.Router = echo.New()
//router_config := echojwt.Config{
// SigningKey: s.Config.JwtKey,
// NewClaimsFunc: func(c echo.Context) jwt.Claims {
// return new(auth.JWTClaim)
// },
//}
// Init repositories
// userRepo := usersRepository.NewUsersRepository(s.DB)
chargerRepo := chargersRepo.NewChargersRepo(s.DB)
api := s.Router.Group("/api")
{
// Users
// api.POST("/auth", controllers.GenerateToken)
// secured := api.Group("/user")
// {
// secured.Use(echojwt.WithConfig(router_config))
// secured.GET("", controllers.GetUser)
// }
// Chargers
// api.GET("/chargers", controllers.GetChargers)
api.GET("/chargers/all", chargerRepo.GetAllChargers)
// api.GET("/chargers/:id", controllers.GetChargerByID)
// api.GET("/chargers/search/:q", controllers.SearchChargers)
}
return nil*/
}