From e03e663866e7129a2c983b4f763ecf725ba842a8 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Sun, 7 Apr 2024 09:37:28 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20LocalDateTime=20=EC=9D=98=20Fake=20?= =?UTF-8?q?=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uniletter/time/service/TimeGenerator.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/unithon/uniletter/time/service/TimeGenerator.java diff --git a/src/main/java/unithon/uniletter/time/service/TimeGenerator.java b/src/main/java/unithon/uniletter/time/service/TimeGenerator.java new file mode 100644 index 0000000..e7c4e8d --- /dev/null +++ b/src/main/java/unithon/uniletter/time/service/TimeGenerator.java @@ -0,0 +1,23 @@ +package unithon.uniletter.time.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.util.Optional; + +@RequiredArgsConstructor +@Component +public class TimeGenerator { + + private LocalDate localDate; + + public LocalDate generate() { + return Optional.ofNullable(localDate) + .orElseGet(LocalDate::now); + } + + public void setLocalDate(final LocalDate localDate) { + this.localDate = localDate; + } +} From 9809dd205ca2ef8000c27a0614196c824c5b987c Mon Sep 17 00:00:00 2001 From: hong-sile Date: Sun, 7 Apr 2024 09:37:38 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=EC=84=9C=EB=B2=84=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EC=9D=84=20=EC=A1=B0=EC=9E=91=ED=95=98=EB=8A=94=20APi?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unithon/uniletter/time/TimeRequest.java | 6 ++++++ .../time/controller/TimeController.java | 21 +++++++++++++++++++ .../uniletter/time/service/TimeService.java | 17 +++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/main/java/unithon/uniletter/time/TimeRequest.java create mode 100644 src/main/java/unithon/uniletter/time/controller/TimeController.java create mode 100644 src/main/java/unithon/uniletter/time/service/TimeService.java diff --git a/src/main/java/unithon/uniletter/time/TimeRequest.java b/src/main/java/unithon/uniletter/time/TimeRequest.java new file mode 100644 index 0000000..8791685 --- /dev/null +++ b/src/main/java/unithon/uniletter/time/TimeRequest.java @@ -0,0 +1,6 @@ +package unithon.uniletter.time; + +import java.time.LocalDate; + +public record TimeRequest(LocalDate localDate) { +} diff --git a/src/main/java/unithon/uniletter/time/controller/TimeController.java b/src/main/java/unithon/uniletter/time/controller/TimeController.java new file mode 100644 index 0000000..e91a368 --- /dev/null +++ b/src/main/java/unithon/uniletter/time/controller/TimeController.java @@ -0,0 +1,21 @@ +package unithon.uniletter.time.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; +import unithon.uniletter.time.TimeRequest; +import unithon.uniletter.time.service.TimeService; + +@RestController +@RequiredArgsConstructor +public class TimeController { + + private final TimeService timeService; + + @PostMapping("/time") + public ResponseEntity setServerTime(final TimeRequest timeRequest) { + timeService.setServerTime(timeRequest.localDate()); + return ResponseEntity.ok().build(); + } +} diff --git a/src/main/java/unithon/uniletter/time/service/TimeService.java b/src/main/java/unithon/uniletter/time/service/TimeService.java new file mode 100644 index 0000000..9324e75 --- /dev/null +++ b/src/main/java/unithon/uniletter/time/service/TimeService.java @@ -0,0 +1,17 @@ +package unithon.uniletter.time.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; + +@RequiredArgsConstructor +@Service +public class TimeService { + + private final TimeGenerator timeGenerator; + + public void setServerTime(final LocalDate localDate) { + timeGenerator.setLocalDate(localDate); + } +} From 76efeec707829cccdce0c6d789a38de544684ea1 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Sun, 7 Apr 2024 09:38:22 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=EB=82=A0=EC=A7=9C=EA=B0=80=20?= =?UTF-8?q?=EC=A7=80=EB=82=9C=20=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A7=8C=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/repository/MessageRepository.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/unithon/uniletter/message/repository/MessageRepository.java b/src/main/java/unithon/uniletter/message/repository/MessageRepository.java index 4d37078..f50aa82 100644 --- a/src/main/java/unithon/uniletter/message/repository/MessageRepository.java +++ b/src/main/java/unithon/uniletter/message/repository/MessageRepository.java @@ -1,14 +1,25 @@ package unithon.uniletter.message.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import unithon.uniletter.common.error.NotFoundException; import unithon.uniletter.message.Message; +import java.time.LocalDate; import java.util.List; import java.util.UUID; public interface MessageRepository extends JpaRepository { - List findByReceiverIdAndIsReadOrderBySendPlannedAtAsc(UUID receiverId, Boolean isRead); + @Query(""" + select message + from Message message + join fetch Member member + on member.id = message.receiverId + where message.isRead = false + and message.sendPlannedAt <= :today + order by message.sendPlannedAt asc + """) + List readArriveMessage(final UUID receiverId, final Boolean isRead, final LocalDate today); List findByReceiverIdOrderBySendPlannedAtDesc(UUID receiverId); From da0ac083f31d789d7af034b42778a39ac405f42f Mon Sep 17 00:00:00 2001 From: hong-sile Date: Sun, 7 Apr 2024 09:38:33 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20timeGenrator=EB=A5=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EC=9D=84=20=EC=96=BB=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/unithon/uniletter/event/service/EventService.java | 4 +++- .../unithon/uniletter/message/service/MessageService.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/unithon/uniletter/event/service/EventService.java b/src/main/java/unithon/uniletter/event/service/EventService.java index 1797cae..d5a7c98 100644 --- a/src/main/java/unithon/uniletter/event/service/EventService.java +++ b/src/main/java/unithon/uniletter/event/service/EventService.java @@ -10,6 +10,7 @@ import unithon.uniletter.member.Member; import unithon.uniletter.message.dto.MessageResponse; import unithon.uniletter.message.repository.MessageRepository; +import unithon.uniletter.time.service.TimeGenerator; import java.time.LocalDate; import java.util.Arrays; @@ -22,6 +23,7 @@ public class EventService { private final EventRepository eventRepository; private final MessageRepository messageRepository; + private final TimeGenerator timeGenerator; @Transactional public String addEvent(final Member member, final LocalDate plannedAt, final String content, final EventType type) { @@ -37,7 +39,7 @@ public String addEvent(final Member member, final LocalDate plannedAt, final Str @Transactional(readOnly = true) public List findMemberEventAfterToday(final String nickName) { - return eventRepository.findEventsAfterToday(nickName, LocalDate.now()); + return eventRepository.findEventsAfterToday(nickName, timeGenerator.generate()); } public List findEventTypeAll() { diff --git a/src/main/java/unithon/uniletter/message/service/MessageService.java b/src/main/java/unithon/uniletter/message/service/MessageService.java index e9b8b71..cd941c0 100644 --- a/src/main/java/unithon/uniletter/message/service/MessageService.java +++ b/src/main/java/unithon/uniletter/message/service/MessageService.java @@ -12,6 +12,7 @@ import unithon.uniletter.message.dto.MessageRequest; import unithon.uniletter.message.dto.MessageResponse; import unithon.uniletter.message.repository.MessageRepository; +import unithon.uniletter.time.service.TimeGenerator; import java.util.List; import java.util.UUID; @@ -23,6 +24,7 @@ @Transactional public class MessageService { + private final TimeGenerator timeGenerator; private final MessageRepository messageRepository; private final MemberRepository memberRepository; private final EventRepository eventRepository; @@ -44,7 +46,7 @@ public void sendMessage(final MessageRequest request, final Member loginMember) @Transactional public List getUnreadMessages(final Member member) { - final List messages = messageRepository.findByReceiverIdAndIsReadOrderBySendPlannedAtAsc(member.getId(), false); + final List messages = messageRepository.readArriveMessage(member.getId(), false, timeGenerator.generate()); messages.forEach(Message::read); return getMessageWithEvent(messages); }