From 806c110b2c4645f3bc97f4fbbe944474b0494854 Mon Sep 17 00:00:00 2001 From: gsd Date: Fri, 4 Apr 2025 01:30:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D0=BB=D1=8C=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=8C=20=D0=B0=D0=BF=D0=B4=D0=B5=D0=B9=D1=82=203.5.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/user/MessagesController.java | 10 +++------ .../MessageSearch.java => SearchFilter.java} | 22 +++++-------------- .../messages/MessageSearchFilter.java | 14 ++++++++++++ 3 files changed, 23 insertions(+), 23 deletions(-) rename src/main/java/app/entities/{messages/MessageSearch.java => SearchFilter.java} (70%) create mode 100644 src/main/java/app/entities/messages/MessageSearchFilter.java diff --git a/src/main/java/app/controllers/user/MessagesController.java b/src/main/java/app/controllers/user/MessagesController.java index 7aaec32..20820ad 100644 --- a/src/main/java/app/controllers/user/MessagesController.java +++ b/src/main/java/app/controllers/user/MessagesController.java @@ -5,7 +5,7 @@ import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CollectStatistic; import app.annotations.interfaces.WaitAfterNext; import app.entities.messages.Message; -import app.entities.messages.MessageSearch; +import app.entities.messages.MessageSearchFilter; import app.entities.other.SteamID; import app.repositories.GametimeRepository; import app.repositories.MessageRepository; @@ -15,16 +15,12 @@ import app.utils.SteamIDConverter; import jakarta.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.Map; - /** * котроллер для пользователя, чтоб смотреть сообщения */ @@ -67,8 +63,8 @@ public class MessagesController { @WaitAfterNext(order = "messages") @CollectStatistic public Page getMessagesWithFilters(Pageable pageable, - @RequestBody(required = false) MessageSearch filter) { - if (filter == null) filter = new MessageSearch(); + @RequestBody(required = false) MessageSearchFilter filter) { + if (filter == null) filter = new MessageSearchFilter(); Page messages = messageRepository.getMessages( pageable, filter.getAccounts(profileService), diff --git a/src/main/java/app/entities/messages/MessageSearch.java b/src/main/java/app/entities/SearchFilter.java similarity index 70% rename from src/main/java/app/entities/messages/MessageSearch.java rename to src/main/java/app/entities/SearchFilter.java index 170d690..d2bb65f 100644 --- a/src/main/java/app/entities/messages/MessageSearch.java +++ b/src/main/java/app/entities/SearchFilter.java @@ -1,23 +1,17 @@ -package app.entities.messages; +package app.entities; import app.services.ProfileService; -import lombok.Getter; import java.time.LocalDateTime; import java.time.ZoneId; -import java.util.ArrayList; import java.util.List; import java.util.Objects; -public class MessageSearch { - private List accounts; - private LocalDateTime begin; - private LocalDateTime end; - private String message; - private String serverId; - - public MessageSearch() { - } +public abstract class SearchFilter { + private List accounts = null; + private LocalDateTime begin = null; + private LocalDateTime end = null; + private String serverId = null; public List getAccounts(ProfileService profileService) { if (accounts == null || accounts.isEmpty()) return null; @@ -39,10 +33,6 @@ public class MessageSearch { return end == null ? null : end.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond(); } - public String getMessage() { - return message == null || message.isEmpty() ? null : "%"+message+"%"; - } - public String getServerId() { return serverId == null || serverId.isEmpty() ? null : serverId; } diff --git a/src/main/java/app/entities/messages/MessageSearchFilter.java b/src/main/java/app/entities/messages/MessageSearchFilter.java new file mode 100644 index 0000000..937e000 --- /dev/null +++ b/src/main/java/app/entities/messages/MessageSearchFilter.java @@ -0,0 +1,14 @@ +package app.entities.messages; + +import app.entities.SearchFilter; + +public class MessageSearchFilter extends SearchFilter { + private String message; + public MessageSearchFilter() { + } + + public String getMessage() { + return message == null || message.isEmpty() ? null : "%"+message+"%"; + } + +}