modified: serv_nginx/api_bb/internal/handlers/handlers.go
renamed: "serv_nginx/api_bb/internal/handlers/training_plan_handler\321\216\320\277\321\211" -> serv_nginx/api_bb/internal/handlers/training_plan_handler.go modified: serv_nginx/api_bb/internal/handlers/user_achievement_handler.go modified: serv_nginx/api_bb/internal/routes/routes.go add routing, handlers for trainingPlan object
This commit is contained in:
@@ -23,6 +23,7 @@ type Handler struct {
|
||||
eventHandler *EventHandler
|
||||
eventRegistrationHandler *EventRegistrationHandler
|
||||
personalBestHandler *PersonalBestHandler
|
||||
trainingPlanHandler *TrainingPlanHandler
|
||||
// Здесь будут добавлены другие обработчики
|
||||
// userHandler *UserHandler
|
||||
// eventHandler *EventHandler
|
||||
@@ -41,6 +42,7 @@ func NewHandler(db *gorm.DB, cfg *config.Config) *Handler {
|
||||
eventRepo := repository.NewEventRepository(db)
|
||||
eventRegistrationRepo := repository.NewEventRegistrationRepository(db)
|
||||
personalBestRepo := repository.NewPersonalBestRepository(db)
|
||||
trainingPlanRepo := repository.NewTrainingPlanRepository(db)
|
||||
|
||||
// Initialize logger
|
||||
baseLogger := logger.NewWrapper(logger.Get()) // Создаем базовый логгер
|
||||
@@ -58,6 +60,7 @@ func NewHandler(db *gorm.DB, cfg *config.Config) *Handler {
|
||||
eventRegistrationService := service.NewEventRegistrationService(eventRegistrationRepo, eventRepo, baseLogger)
|
||||
eventService := service.NewEventService(eventRepo, eventRegistrationRepo, baseLogger)
|
||||
personalBestService := service.NewPersonalBestService(personalBestRepo, userStatsService)
|
||||
trainingPlanService := service.NewTrainingPlanService(*trainingPlanRepo)
|
||||
|
||||
// Инициализация обработчиков
|
||||
healthHandler := NewHealthHandler()
|
||||
@@ -72,6 +75,7 @@ func NewHandler(db *gorm.DB, cfg *config.Config) *Handler {
|
||||
eventHandler := NewEventHandler(eventService)
|
||||
eventRegistrationHandler := NewEventRegistrationHandler(eventRegistrationService)
|
||||
personalBestHandler := NewPersonalBestHandler(*personalBestService)
|
||||
trainingPlanHandler := NewTrainingPlanHandler(trainingPlanService)
|
||||
|
||||
return &Handler{
|
||||
healthHandler: healthHandler,
|
||||
@@ -86,10 +90,15 @@ func NewHandler(db *gorm.DB, cfg *config.Config) *Handler {
|
||||
eventHandler: eventHandler,
|
||||
eventRegistrationHandler: eventRegistrationHandler,
|
||||
personalBestHandler: personalBestHandler,
|
||||
trainingPlanHandler: trainingPlanHandler,
|
||||
}
|
||||
}
|
||||
|
||||
// Геттеры для обработчиков (опционально, для удобства)
|
||||
func (h *Handler) TrainingPlanHandler() *TrainingPlanHandler {
|
||||
return h.trainingPlanHandler
|
||||
}
|
||||
|
||||
func (h *Handler) PersonalBestHandler() *PersonalBestHandler {
|
||||
return h.personalBestHandler
|
||||
}
|
||||
|
||||
@@ -185,11 +185,12 @@ func (h *UserAchievementHandler) UpdateAchievement(w http.ResponseWriter, r *htt
|
||||
zap.Uint("achievement_id", uint(achievementID)),
|
||||
zap.Error(err),
|
||||
)
|
||||
if err == service.ErrAchievementNotFound {
|
||||
switch err {
|
||||
case service.ErrAchievementNotFound:
|
||||
utils.RespondWithError(w, http.StatusNotFound, "Achievement not found")
|
||||
} else if err == service.ErrAchievementAlreadyExists {
|
||||
case service.ErrAchievementAlreadyExists:
|
||||
utils.RespondWithError(w, http.StatusConflict, "Achievement with this title already exists")
|
||||
} else {
|
||||
default:
|
||||
utils.RespondWithError(w, http.StatusInternalServerError, "Failed to update achievement: "+err.Error())
|
||||
}
|
||||
return
|
||||
|
||||
@@ -160,6 +160,37 @@ func SetupRouter(db *gorm.DB, config *config.Config) http.Handler {
|
||||
r.Patch("/verify", h.PersonalBestHandler().VerifyPersonalBest)
|
||||
})
|
||||
})
|
||||
|
||||
// Маршруты для тренировочных планов (Training Plans)
|
||||
r.Route("/training-plans", func(r chi.Router) {
|
||||
// Создание нового тренировочного плана
|
||||
r.Post("/", h.TrainingPlanHandler().CreateTrainingPlan)
|
||||
|
||||
// Получение всех тренировочных планов пользователя
|
||||
r.Get("/", h.TrainingPlanHandler().GetTrainingPlans)
|
||||
|
||||
// Получение активного тренировочного плана
|
||||
r.Get("/active", h.TrainingPlanHandler().GetActiveTrainingPlan)
|
||||
|
||||
// Обновление текущей недели плана
|
||||
r.Patch("/current-week", h.TrainingPlanHandler().UpdateCurrentWeek)
|
||||
|
||||
// Операции с конкретным тренировочным планом
|
||||
r.Route("/{id}", func(r chi.Router) {
|
||||
// Получение тренировочного плана по ID
|
||||
r.Get("/", h.TrainingPlanHandler().GetTrainingPlanByID)
|
||||
|
||||
// Обновление тренировочного плана
|
||||
r.Put("/", h.TrainingPlanHandler().UpdateTrainingPlan)
|
||||
|
||||
// Удаление тренировочного плана
|
||||
r.Delete("/", h.TrainingPlanHandler().DeleteTrainingPlan)
|
||||
|
||||
// Пометить план как завершенный
|
||||
r.Patch("/complete", h.TrainingPlanHandler().MarkTrainingPlanAsCompleted)
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
r.Route("/news", func(r chi.Router) {
|
||||
|
||||
Reference in New Issue
Block a user