From d55b1620d5b55d8e7f32a3b785b9bfd0f426000c Mon Sep 17 00:00:00 2001 From: backdev-1 Date: Mon, 25 May 2026 14:16:39 +0700 Subject: [PATCH] dev add statistic complaints by status --- .../nocopy/configuration/HandlerConfig.java | 29 ++++++++++++++++ .../nocopy/controller/ApiController.java | 31 +++++++++++++++++ .../soune/nocopy/util/InternalApiFilter.java | 34 +++++++++++++++++++ src/main/resources/application.yaml | 1 + 4 files changed, 95 insertions(+) create mode 100644 src/main/java/ru/soune/nocopy/util/InternalApiFilter.java diff --git a/src/main/java/ru/soune/nocopy/configuration/HandlerConfig.java b/src/main/java/ru/soune/nocopy/configuration/HandlerConfig.java index 5c83aa6..f385f97 100644 --- a/src/main/java/ru/soune/nocopy/configuration/HandlerConfig.java +++ b/src/main/java/ru/soune/nocopy/configuration/HandlerConfig.java @@ -94,4 +94,33 @@ public class HandlerConfig { return map; } + + @Bean + public Map internalHandlers( + StatisticComplaintHandler statisticComplaintHandler, + StatisticUserFilesHandler statisticUserHandler, + StatisticTariffInfoFileHandler statisticTariffInfoFileHandler, + StatisticUserDynamicHandler statisticUserDynamicHandler, + StatisticProtectedFilesHandler statisticProtectedFilesHandler, + StatisticViolationHandler statisticViolationHandler, + StatisticSubscriberHandler statisticSubscriberHandler, + StatisticTokenHandler statisticTokenHandler, + StatisticIncomeHandler statisticIncomeHandler, + MonitoringStatisticHandler monitoringStatisticHandler + ) + { + Map map = new HashMap<>(); + map.put(30019, statisticUserHandler); + map.put(30020, statisticTariffInfoFileHandler); + map.put(30021, statisticUserDynamicHandler); + map.put(30022, statisticProtectedFilesHandler); + map.put(30023, statisticViolationHandler); + map.put(30024, statisticSubscriberHandler); + map.put(30025, statisticTokenHandler); + map.put(30026, statisticIncomeHandler); + map.put(30027, monitoringStatisticHandler); + map.put(30029, statisticComplaintHandler); + + return map; + } } diff --git a/src/main/java/ru/soune/nocopy/controller/ApiController.java b/src/main/java/ru/soune/nocopy/controller/ApiController.java index 716a797..69be2e0 100644 --- a/src/main/java/ru/soune/nocopy/controller/ApiController.java +++ b/src/main/java/ru/soune/nocopy/controller/ApiController.java @@ -59,6 +59,8 @@ public class ApiController { private final Map handlers; + private final Map internalHandlers; + private final FileEntityService fileEntityService; private final AuthService authService; @@ -126,6 +128,35 @@ public class ApiController { } } + @PostMapping("/internal/data") + public ResponseEntity handleInternalPostRequest(@RequestBody BaseRequest request) { + Integer msgId = request.getMsgId(); + BaseResponse response; + RequestHandler handler = internalHandlers.get(msgId); + + try { + if (handler == null) { + response = new BaseResponse(msgId, + MessageCode.MSG_ID_NOT_FOUND.getCode(), + MessageCode.MSG_ID_NOT_FOUND.getDescription(), + new HashMap<>()); + } else { + response = handler.handle(request); + } + + return ResponseEntity.ok().body(response); + } catch (Exception e) { + log.error("Handler execution failed for msgId: {}", msgId, e); + + BaseResponse errorResponse = new BaseResponse(msgId, + MessageCode.INVALID_JSON_BODY.getCode(), + MessageCode.INVALID_JSON_BODY.getDescription(), + new HashMap<>()); + + return ResponseEntity.ok().body(errorResponse); + } + } + @PostMapping("/v{version}/files/chunk") public ResponseEntity uploadChunk( @PathVariable("version") int version, diff --git a/src/main/java/ru/soune/nocopy/util/InternalApiFilter.java b/src/main/java/ru/soune/nocopy/util/InternalApiFilter.java new file mode 100644 index 0000000..9b9922a --- /dev/null +++ b/src/main/java/ru/soune/nocopy/util/InternalApiFilter.java @@ -0,0 +1,34 @@ +package ru.soune.nocopy.util; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; + +@Component +public class InternalApiFilter extends OncePerRequestFilter { + + @Value("${app.internal-api-key}") + private String internalApiKey; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) + throws ServletException, IOException { + + if (request.getRequestURI().startsWith("api/internal/")) { + String providedKey = request.getHeader("X-Internal-Key"); + + if (!internalApiKey.equals(providedKey)) { + response.sendError(403, "Access Denied: Internal API only"); + return; + } + } + + filterChain.doFilter(request, response); + } +} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 053c2de..e0a3021 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -135,6 +135,7 @@ yookassa: app: + internal-api-key: "tljzkXiEYF1klSHuG2hPZKjx6EsBX8RQP6UrzMdQanSKbRYuHuOBwrXejZkn7V4FICvIahoDmYD2hjNBPw61NFbGIt4scOzwZpyCiXEa1YKLAeJSPso4S43LIZlKjO4S" email: verification: standart-subject: NO COPY - Подтверждение email адреса