modified: serv_nginx/api_bb/internal/handlers/auth.go
modified: serv_nginx/api_bb/internal/handlers/avatar.go modified: serv_nginx/api_bb/internal/handlers/health.go modified: serv_nginx/api_bb/internal/handlers/user.go modified: serv_nginx/api_bb/internal/routes/routes.go deleted: serv_nginx/bbvue/src/stores/counter.js modified: serv_nginx/bbvue/src/views/Profile.vue update chi to last, moove the routing from handlers to router.go
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
|||||||
"api_bb/pkg/logger"
|
"api_bb/pkg/logger"
|
||||||
"api_bb/pkg/utils"
|
"api_bb/pkg/utils"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,21 +31,6 @@ func NewAuthHandler(authService service.AuthService, jwtService service.JWTServi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *AuthHandler) Routes() chi.Router {
|
|
||||||
r := chi.NewRouter()
|
|
||||||
|
|
||||||
// Обработка OPTIONS запросов для CORS
|
|
||||||
r.Options("/register", h.handleOptions)
|
|
||||||
r.Options("/login", h.handleOptions)
|
|
||||||
r.Options("/logout", h.handleOptions)
|
|
||||||
|
|
||||||
r.Post("/register", h.Register)
|
|
||||||
r.Post("/login", h.Login)
|
|
||||||
r.Post("/logout", h.Logout)
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// Обработчик для OPTIONS запросов
|
// Обработчик для OPTIONS запросов
|
||||||
func (h *AuthHandler) handleOptions(w http.ResponseWriter, r *http.Request) {
|
func (h *AuthHandler) handleOptions(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|||||||
@@ -27,22 +27,6 @@ func NewAvatarHandler(avatarService service.AvatarService) *AvatarHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *AvatarHandler) Routes() chi.Router {
|
|
||||||
r := chi.NewRouter()
|
|
||||||
|
|
||||||
h.logger.Debug("Registering avatar routes",
|
|
||||||
zap.String("POST", "/upload"),
|
|
||||||
zap.String("DELETE", "/delete"),
|
|
||||||
zap.String("GET", "/{filename}"),
|
|
||||||
)
|
|
||||||
|
|
||||||
r.Post("/upload", h.UploadAvatar)
|
|
||||||
r.Delete("/delete", h.DeleteAvatar)
|
|
||||||
r.Get("/{filename}", h.GetAvatar)
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *AvatarHandler) UploadAvatar(w http.ResponseWriter, r *http.Request) {
|
func (h *AvatarHandler) UploadAvatar(w http.ResponseWriter, r *http.Request) {
|
||||||
h.logger.Debug("UploadAvatar START",
|
h.logger.Debug("UploadAvatar START",
|
||||||
zap.String("method", r.Method),
|
zap.String("method", r.Method),
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"api_bb/pkg/utils"
|
"api_bb/pkg/utils"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type HealthHandler struct{}
|
type HealthHandler struct{}
|
||||||
@@ -14,15 +13,6 @@ func NewHealthHandler() *HealthHandler {
|
|||||||
return &HealthHandler{}
|
return &HealthHandler{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HealthHandler) Routes() chi.Router {
|
|
||||||
r := chi.NewRouter()
|
|
||||||
|
|
||||||
r.Get("/health", h.HealthCheck)
|
|
||||||
r.Get("/check", h.Check)
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *HealthHandler) HealthCheck(w http.ResponseWriter, r *http.Request) {
|
func (h *HealthHandler) HealthCheck(w http.ResponseWriter, r *http.Request) {
|
||||||
response := map[string]string{
|
response := map[string]string{
|
||||||
"status": "ok",
|
"status": "ok",
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import (
|
|||||||
"api_bb/pkg/middleware"
|
"api_bb/pkg/middleware"
|
||||||
"api_bb/pkg/utils"
|
"api_bb/pkg/utils"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,15 +29,6 @@ func NewUserHandler(userService service.UserService) *UserHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *UserHandler) Routes() chi.Router {
|
|
||||||
r := chi.NewRouter()
|
|
||||||
|
|
||||||
r.Get("/profile", h.GetProfile)
|
|
||||||
r.Post("/editProfile", h.UpdateProfile)
|
|
||||||
r.Get("/", h.GetUsers) // 👈 ДОБАВЛЯЕМ НОВЫЙ ЭНДПОЙНТ
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserResponse struct {
|
type UserResponse struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
|
|||||||
@@ -42,25 +42,38 @@ func SetupRouter(db *gorm.DB, config *config.Config) http.Handler {
|
|||||||
// Initialize handlers
|
// Initialize handlers
|
||||||
|
|
||||||
// Health routes
|
// Health routes
|
||||||
r.Mount("/api", allHandler.HealthHandler().Routes())
|
r.Route("/api", func(r chi.Router) {
|
||||||
|
r.Get("/health", allHandler.HealthHandler().HealthCheck)
|
||||||
|
r.Get("/check", allHandler.HealthHandler().Check)
|
||||||
|
})
|
||||||
|
|
||||||
// API v1 routes
|
// API v1 routes
|
||||||
r.Route("/v1", func(r chi.Router) {
|
r.Route("/v1", func(r chi.Router) {
|
||||||
r.Get("/check", allHandler.HealthHandler().Check)
|
|
||||||
|
|
||||||
// Public auth routes
|
// Public auth routes
|
||||||
r.Mount("/auth", allHandler.AuthHandler().Routes())
|
r.Route("/auth", func(r chi.Router) {
|
||||||
|
r.Post("/register", allHandler.AuthHandler().Register)
|
||||||
|
r.Post("/login", allHandler.AuthHandler().Login)
|
||||||
|
r.Post("/logout", allHandler.AuthHandler().Logout)
|
||||||
|
})
|
||||||
|
|
||||||
// Protected routes
|
// Protected routes
|
||||||
r.Route("/user", func(r chi.Router) {
|
r.Route("/user", func(r chi.Router) {
|
||||||
r.Use(middleware.AuthMiddleware(jwtService, userRepo))
|
r.Use(middleware.AuthMiddleware(jwtService, userRepo))
|
||||||
r.Use(middleware.RequireAuth)
|
r.Use(middleware.RequireAuth)
|
||||||
|
|
||||||
// Все операции с аватарами теперь через AvatarHandler
|
// user profile routes
|
||||||
r.Mount("/avatars", allHandler.AvatarHandler().Routes())
|
r.Get("/profile", allHandler.UserHandler().GetProfile)
|
||||||
// Профиль пользователя
|
r.Post("/editProfile", allHandler.UserHandler().UpdateProfile)
|
||||||
r.Mount("/", allHandler.UserHandler().Routes())
|
r.Get("/", allHandler.UserHandler().GetUsers)
|
||||||
|
|
||||||
|
// Все операции с аватарами теперь через AvatarHandler
|
||||||
|
r.Route("/avatars", func(r chi.Router) {
|
||||||
|
|
||||||
|
r.Post("/upload", allHandler.AvatarHandler().UploadAvatar)
|
||||||
|
r.Delete("/delete", allHandler.AvatarHandler().DeleteAvatar)
|
||||||
|
r.Get("/{filename}", allHandler.AvatarHandler().GetAvatar)
|
||||||
|
})
|
||||||
// Здесь будут другие защищенные маршруты пользователя
|
// Здесь будут другие защищенные маршруты пользователя
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
import { ref, computed } from 'vue'
|
|
||||||
import { defineStore } from 'pinia'
|
|
||||||
|
|
||||||
export const useCounterStore = defineStore('counter', () => {
|
|
||||||
const count = ref(0)
|
|
||||||
const doubleCount = computed(() => count.value * 2)
|
|
||||||
function increment() {
|
|
||||||
count.value++
|
|
||||||
}
|
|
||||||
|
|
||||||
return { count, doubleCount, increment }
|
|
||||||
})
|
|
||||||
@@ -448,6 +448,8 @@ export default {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
/* Добавляем новые стили для дополнительных секций */
|
/* Добавляем новые стили для дополнительных секций */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user