diff --git a/api/index.go b/api/index.go index d46697f..d7c4822 100644 --- a/api/index.go +++ b/api/index.go @@ -112,7 +112,7 @@ func Handler(w http.ResponseWriter, r *http.Request) { api.HandleFunc("/torrents/anime", torrentsHandler.SearchAnime).Methods("GET") api.HandleFunc("/torrents/seasons", torrentsHandler.GetAvailableSeasons).Methods("GET") api.HandleFunc("/torrents/search", torrentsHandler.SearchByQuery).Methods("GET") - + // Реакции (публичные) api.HandleFunc("/reactions/{mediaType}/{mediaId}/counts", reactionsHandler.GetReactionCounts).Methods("GET") @@ -153,7 +153,9 @@ func Handler(w http.ResponseWriter, r *http.Request) { // Пользовательские данные protected.HandleFunc("/auth/profile", authHandler.GetProfile).Methods("GET") protected.HandleFunc("/auth/profile", authHandler.UpdateProfile).Methods("PUT") - + // Новый маршрут удаления аккаунта + protected.HandleFunc("/auth/profile", authHandler.DeleteAccount).Methods("DELETE") + // Реакции (приватные) protected.HandleFunc("/reactions/{mediaType}/{mediaId}/my-reaction", reactionsHandler.GetMyReaction).Methods("GET") protected.HandleFunc("/reactions/{mediaType}/{mediaId}", reactionsHandler.SetReaction).Methods("POST") diff --git a/main.go b/main.go index e05a774..4e167e2 100644 --- a/main.go +++ b/main.go @@ -104,7 +104,8 @@ func main() { api.HandleFunc("/movies/upcoming", movieHandler.Upcoming).Methods("GET") api.HandleFunc("/movies/now-playing", movieHandler.NowPlaying).Methods("GET") api.HandleFunc("/movies/{id}", movieHandler.GetByID).Methods("GET") - api.HandleFunc("/movies/{id}/recommendations", movieHandler.GetRecommendations).Methods("GET") + +api.HandleFunc("/movies/{id}/recommendations", movieHandler.GetRecommendations).Methods("GET") api.HandleFunc("/movies/{id}/similar", movieHandler.GetSimilar).Methods("GET") api.HandleFunc("/movies/{id}/external-ids", movieHandler.GetExternalIDs).Methods("GET") @@ -131,6 +132,8 @@ func main() { // Пользовательские данные protected.HandleFunc("/auth/profile", authHandler.GetProfile).Methods("GET") protected.HandleFunc("/auth/profile", authHandler.UpdateProfile).Methods("PUT") + // Новый маршрут удаления аккаунта + protected.HandleFunc("/auth/profile", authHandler.DeleteAccount).Methods("DELETE") // Реакции (приватные) protected.HandleFunc("/reactions/{mediaType}/{mediaId}/my-reaction", reactionsHandler.GetMyReaction).Methods("GET") @@ -140,7 +143,8 @@ func main() { // CORS middleware corsHandler := handlers.CORS( - handlers.AllowedOrigins([]string{"*"}), + +handlers.AllowedOrigins([]string{"*"}), handlers.AllowedMethods([]string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}), handlers.AllowedHeaders([]string{"Authorization", "Content-Type", "Accept", "Origin", "X-Requested-With"}), handlers.AllowCredentials(), @@ -177,4 +181,4 @@ func main() { fmt.Printf("❌ Server failed to start: %v\n", err) os.Exit(1) } -} +} \ No newline at end of file diff --git a/pkg/handlers/auth.go b/pkg/handlers/auth.go index 8dfbc29..af35e34 100644 --- a/pkg/handlers/auth.go +++ b/pkg/handlers/auth.go @@ -122,7 +122,26 @@ func (h *AuthHandler) UpdateProfile(w http.ResponseWriter, r *http.Request) { }) } -// Верификация email +// Удаление аккаунта +func (h *AuthHandler) DeleteAccount(w http.ResponseWriter, r *http.Request) { + userID, ok := middleware.GetUserIDFromContext(r.Context()) + if !ok { + http.Error(w, "User ID not found in context", http.StatusInternalServerError) + return + } + + if err := h.authService.DeleteAccount(r.Context(), userID); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(models.APIResponse{ + Success: true, + Message: "Account deleted successfully", + }) +} +// Подтверждение email func (h *AuthHandler) VerifyEmail(w http.ResponseWriter, r *http.Request) { var req models.VerifyEmailRequest if err := json.NewDecoder(r.Body).Decode(&req); err != nil {