Moved handler to use interfaces and added the refreshToken endpoint

This commit is contained in:
James Tombleson 2024-04-21 08:59:51 -07:00
parent 0383d554b8
commit b02ed3f86a

View File

@ -5,7 +5,6 @@ import (
"net/http" "net/http"
"git.jamestombleson.com/jtom38/go-cook/internal/domain" "git.jamestombleson.com/jtom38/go-cook/internal/domain"
"git.jamestombleson.com/jtom38/go-cook/internal/repositories"
"git.jamestombleson.com/jtom38/go-cook/internal/services" "git.jamestombleson.com/jtom38/go-cook/internal/services"
"github.com/golang-jwt/jwt/v5" "github.com/golang-jwt/jwt/v5"
@ -16,19 +15,18 @@ import (
type Handler struct { type Handler struct {
Config domain.EnvConfig Config domain.EnvConfig
UserService services.UserService users services.UserService
userRepo repositories.IUserTable recipes services.Recipes
recipeRepo repositories.IRecipeTable refreshTokens services.RefreshToken
refreshTokenRepo repositories.RefreshTokenRepository
} }
func NewHandler(conn *sql.DB, cfg domain.EnvConfig) *Handler { func NewHandler(conn *sql.DB, cfg domain.EnvConfig) *Handler {
return &Handler{ return &Handler{
Config: cfg, Config: cfg,
UserService: services.NewUserService(conn),
userRepo: repositories.NewUserRepository(conn), users: services.NewUserService(conn),
recipeRepo: repositories.NewRecipeRepository(conn), recipes: services.NewRecipesService(conn),
refreshTokenRepo: repositories.NewRefreshTokenRepository(conn), refreshTokens: services.NewRefreshTokenService(conn),
} }
} }
@ -46,6 +44,7 @@ func (h *Handler) Register(v1 *echo.Group) {
auth.Use(echojwt.WithConfig(jwtConfig)) auth.Use(echojwt.WithConfig(jwtConfig))
auth.POST("/scopes/add", h.AddScopes) auth.POST("/scopes/add", h.AddScopes)
auth.POST("/scopes/remove", h.RemoveScopes) auth.POST("/scopes/remove", h.RemoveScopes)
auth.POST("/refreshToken", h.RefreshJwtToken)
demo := v1.Group("/demo") demo := v1.Group("/demo")
demo.GET("/hello", h.DemoHello) demo.GET("/hello", h.DemoHello)