features/working-on-scopes #13
@ -2,8 +2,10 @@ package v1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"go-cook/api/domain"
|
||||||
"go-cook/api/repositories"
|
"go-cook/api/repositories"
|
||||||
"go-cook/api/services"
|
"go-cook/api/services"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
echojwt "github.com/labstack/echo-jwt/v4"
|
echojwt "github.com/labstack/echo-jwt/v4"
|
||||||
@ -11,16 +13,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
|
Config domain.EnvConfig
|
||||||
|
|
||||||
UserService services.UserService
|
UserService services.UserService
|
||||||
userRepo repositories.IUserTable
|
userRepo repositories.IUserTable
|
||||||
recipeRepo repositories.IRecipeTable
|
recipeRepo repositories.IRecipeTable
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(conn *sql.DB) *Handler {
|
func NewHandler(conn *sql.DB, cfg domain.EnvConfig) *Handler {
|
||||||
return &Handler{
|
return &Handler{
|
||||||
|
Config: cfg,
|
||||||
UserService: services.NewUserService(conn),
|
UserService: services.NewUserService(conn),
|
||||||
userRepo: repositories.NewUserRepository(conn),
|
userRepo: repositories.NewUserRepository(conn),
|
||||||
recipeRepo: repositories.NewRecipeRepository(conn),
|
recipeRepo: repositories.NewRecipeRepository(conn),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +34,7 @@ func (h *Handler) Register(v1 *echo.Group) {
|
|||||||
NewClaimsFunc: func(c echo.Context) jwt.Claims {
|
NewClaimsFunc: func(c echo.Context) jwt.Claims {
|
||||||
return new(JwtToken)
|
return new(JwtToken)
|
||||||
},
|
},
|
||||||
SigningKey: []byte("ThisIsABadSecretDontReallyUseThis"),
|
SigningKey: []byte(h.Config.JwtSecret),
|
||||||
}
|
}
|
||||||
|
|
||||||
v1.POST("/login", h.AuthLogin)
|
v1.POST("/login", h.AuthLogin)
|
||||||
@ -53,3 +58,10 @@ func (h *Handler) Register(v1 *echo.Group) {
|
|||||||
//users.POST("/login", h.LoginUser)
|
//users.POST("/login", h.LoginUser)
|
||||||
//users.POST("/update/password", h.UpdatePassword)
|
//users.POST("/update/password", h.UpdatePassword)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) ReturnUnauthorizedResponse(c echo.Context, message string) error {
|
||||||
|
return c.JSON(http.StatusUnauthorized, domain.ErrorResponse{
|
||||||
|
HttpCode: http.StatusUnauthorized,
|
||||||
|
Message: message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user