modified: main_dc/yalarba/api_yal/internal/domain/auth/handler.go
modified: main_dc/yalarba/api_yal/internal/domain/auth/router.go modified: main_dc/yalarba/api_yal/internal/domain/auth/servcie.go set mock service for auth layer
This commit is contained in:
@@ -6,22 +6,20 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"api_yal/internal/service"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
// AuthHandler обработчик для аутентификации
|
||||
type AuthHandler struct {
|
||||
accountService service.AccountService
|
||||
validator *validator.Validate
|
||||
authService AuthService
|
||||
validator *validator.Validate
|
||||
}
|
||||
|
||||
// NewAuthHandler создает новый экземпляр AuthHandler
|
||||
func NewAuthHandler(accountService service.AccountService) *AuthHandler {
|
||||
func NewAuthHandler(authService *AuthService) *AuthHandler {
|
||||
return &AuthHandler{
|
||||
accountService: accountService,
|
||||
validator: validator.New(),
|
||||
authService: *NewAuthService(),
|
||||
validator: validator.New(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +52,4 @@ func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,35 @@
|
||||
package auth
|
||||
|
||||
import ()
|
||||
import (
|
||||
"api_yal/internal/logger"
|
||||
"api_yal/internal/middleware"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
// RegisterRoutes регистрирует маршруты аутентификации
|
||||
func RegisterRoutes(r chi.Router) {
|
||||
handler := NewAuthHandler(NewAuthService())
|
||||
l := logger.Get()
|
||||
l.Debug("Регистрация маршрутов аутентификации")
|
||||
|
||||
r.Route("/auth", func(r chi.Router) {
|
||||
// Публичные маршруты (без аутентификации)
|
||||
r.Group(func(r chi.Router) {
|
||||
// r.Post("/login", handler.Login)
|
||||
r.Post("/register", handler.Register)
|
||||
// r.Post("/refresh", handler.RefreshToken)
|
||||
// r.Post("/reset-password", handler.ResetPassword)
|
||||
})
|
||||
|
||||
// Защищенные маршруты (требуют аутентификации)
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(middleware.AuthMiddlewareWithContext) // middleware специфичный для auth
|
||||
|
||||
// r.Post("/logout", handler.Logout)
|
||||
// r.Get("/profile", handler.GetProfile)
|
||||
// r.Put("/profile", handler.UpdateProfile)
|
||||
// r.Post("/change-password", handler.ChangePassword)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1 +1,11 @@
|
||||
package auth
|
||||
package auth
|
||||
|
||||
import ()
|
||||
|
||||
type AuthService struct {
|
||||
}
|
||||
|
||||
func NewAuthService() *AuthService {
|
||||
return &AuthService{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user