From 6f626e2c6f6cbfbf241ab81204845f86981c89c4 Mon Sep 17 00:00:00 2001 From: arys Date: Sat, 21 Feb 2026 01:58:14 +0500 Subject: [PATCH] fix --- .../MarketingAnalysisV3Controller.java | 58 ++++++------------- 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/src/main/java/kz/konturai/parser/controller/MarketingAnalysisV3Controller.java b/src/main/java/kz/konturai/parser/controller/MarketingAnalysisV3Controller.java index 06cb24c..5306afd 100644 --- a/src/main/java/kz/konturai/parser/controller/MarketingAnalysisV3Controller.java +++ b/src/main/java/kz/konturai/parser/controller/MarketingAnalysisV3Controller.java @@ -20,7 +20,7 @@ import java.util.Map; import java.util.Optional; @RestController -@RequestMapping("/api/v3/marketing-analysis") +@RequestMapping("/api/marketing/v3") @RequiredArgsConstructor @Slf4j public class MarketingAnalysisV3Controller { @@ -30,15 +30,12 @@ public class MarketingAnalysisV3Controller { private String extractUserIdFromHeader(String authHeader) { if (authHeader == null || authHeader.isEmpty()) { - log.debug("Authorization header is null or empty"); return null; } try { - String userId = jwtService.extractUserIdFromHeader(authHeader); - log.debug("Extracted userId from header: {}", userId); - return userId; + return jwtService.extractUserIdFromHeader(authHeader); } catch (Exception e) { - log.error("Error extracting userId from header: {}", e.getMessage(), e); + log.error("Error extracting userId: {}", e.getMessage()); return null; } } @@ -49,18 +46,14 @@ public class MarketingAnalysisV3Controller { @RequestBody @Valid MarketingAnalysisV3Request request ) { String userId = extractUserIdFromHeader(authHeader); - if (userId == null) { - return unauthorizedResponse(); - } + if (userId == null) return unauthorizedResponse(); try { String analysisId = service.createAndStartAnalysis(request, userId); - Map responseData = Map.of( "analysisId", analysisId, - "message", "Analysis V3 started successfully" + "message", "Analysis V3 started" ); - return ResponseEntity.accepted().body(ApiResponse.success("Анализ запущен", responseData)); } catch (Exception e) { log.error("Failed to start analysis V3", e); @@ -74,21 +67,14 @@ public class MarketingAnalysisV3Controller { @PathVariable String id ) { String userId = extractUserIdFromHeader(authHeader); - if (userId == null) { - return unauthorizedResponse(); - } + if (userId == null) return unauthorizedResponse(); try { Optional analysisOpt = service.getAnalysisById(id); - - if (analysisOpt.isEmpty()) { - return notFoundResponse("Анализ не найден"); - } + if (analysisOpt.isEmpty()) return notFoundResponse("Анализ не найден"); MarketingAnalysisV3Document analysis = analysisOpt.get(); - if (!analysis.getUserId().equals(userId)) { - return forbiddenResponse(); - } + if (!analysis.getUserId().equals(userId)) return forbiddenResponse(); return ResponseEntity.ok(ApiResponse.success(analysis)); } catch (Exception e) { @@ -102,9 +88,7 @@ public class MarketingAnalysisV3Controller { @RequestHeader(value = "Authorization", required = false) String authHeader ) { String userId = extractUserIdFromHeader(authHeader); - if (userId == null) { - return unauthorizedResponse(); - } + if (userId == null) return unauthorizedResponse(); try { List analyses = service.getAllByUser(userId); @@ -121,33 +105,27 @@ public class MarketingAnalysisV3Controller { ex.getBindingResult().getFieldErrors().forEach(error -> details.put(error.getField(), error.getDefaultMessage()) ); - - ErrorResponse error = new ErrorResponse( - "VALIDATION_ERROR", - "Ошибка валидации входных данных", - details - ); - + ErrorResponse error = new ErrorResponse("VALIDATION_ERROR", "Ошибка валидации", details); return ResponseEntity.badRequest().body(ApiResponse.error("Ошибка валидации", error)); } private ResponseEntity> unauthorizedResponse() { - ErrorResponse error = new ErrorResponse("UNAUTHORIZED", "Требуется авторизация"); - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ApiResponse.error("Не авторизован", error)); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED) + .body(ApiResponse.error("Не авторизован", new ErrorResponse("UNAUTHORIZED", "Требуется авторизация"))); } private ResponseEntity> forbiddenResponse() { - ErrorResponse error = new ErrorResponse("FORBIDDEN", "Нет доступа к этому ресурсу"); - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(ApiResponse.error("Доступ запрещен", error)); + return ResponseEntity.status(HttpStatus.FORBIDDEN) + .body(ApiResponse.error("Доступ запрещен", new ErrorResponse("FORBIDDEN", "Нет доступа"))); } private ResponseEntity> notFoundResponse(String message) { - ErrorResponse error = new ErrorResponse("NOT_FOUND", message); - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.error("Не найдено", error)); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(ApiResponse.error("Не найдено", new ErrorResponse("NOT_FOUND", message))); } private ResponseEntity> internalErrorResponse(Exception e) { - ErrorResponse error = new ErrorResponse("INTERNAL_SERVER_ERROR", e.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.error("Ошибка сервера", error)); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(ApiResponse.error("Ошибка сервера", new ErrorResponse("INTERNAL_SERVER_ERROR", e.getMessage()))); } } \ No newline at end of file