From 78ed63c5c7e96eaebf49c091f9088c0af2d38354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Sat, 11 May 2024 17:36:35 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20api=20(=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=BB=D0=B5=D1=80=D1=8B)=20=D0=B2=20=D0=BF=D0=B0=D0=BF=D0=BA?= =?UTF-8?q?=D1=83=20core?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/core/api/GlobalController.java | 15 +++++++++++++++ .../backend/core/api/PageAttributesMapper.java | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 backend/src/main/java/com/example/backend/core/api/GlobalController.java create mode 100644 backend/src/main/java/com/example/backend/core/api/PageAttributesMapper.java diff --git a/backend/src/main/java/com/example/backend/core/api/GlobalController.java b/backend/src/main/java/com/example/backend/core/api/GlobalController.java new file mode 100644 index 0000000..4486ffc --- /dev/null +++ b/backend/src/main/java/com/example/backend/core/api/GlobalController.java @@ -0,0 +1,15 @@ +package com.example.backend.core.api; + +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ModelAttribute; + +import jakarta.servlet.http.HttpServletRequest; + +@ControllerAdvice +public class GlobalController { + + @ModelAttribute("servletPath") + String getRequestServletPath(HttpServletRequest request) { + return request.getServletPath(); + } +} diff --git a/backend/src/main/java/com/example/backend/core/api/PageAttributesMapper.java b/backend/src/main/java/com/example/backend/core/api/PageAttributesMapper.java new file mode 100644 index 0000000..cf2598a --- /dev/null +++ b/backend/src/main/java/com/example/backend/core/api/PageAttributesMapper.java @@ -0,0 +1,18 @@ +package com.example.backend.core.api; + +import java.util.Map; +import java.util.function.Function; + +import org.springframework.data.domain.Page; + +public class PageAttributesMapper { + private PageAttributesMapper() { + } + + public static Map toAttributes(Page page, Function mapper) { + return Map.of( + "items", page.getContent().stream().map(mapper::apply).toList(), + "currentPage", page.getNumber(), + "totalPages", page.getTotalPages()); + } +}