From 93f99341849ebdef0524f5aa79b1f9ae35fbccd7 Mon Sep 17 00:00:00 2001 From: junho Date: Tue, 26 Mar 2024 04:48:51 +0900 Subject: [PATCH] =?UTF-8?q?entity=20=EA=B3=84=EC=B8=B5=20dto=EB=B3=80?= =?UTF-8?q?=ED=99=98=20=EB=A1=9C=EC=A7=81=20=EB=B6=84=EB=A6=AC=20calendar?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JWTLogIn/JWT/user/controller/EventController.java | 4 ++-- .../JWTLogIn/JWT/user/repository/EventRepository.java | 2 -- .../JWT/user/repository/EventRepositoryCustom.java | 3 +++ .../user/repository/EventRepositoryCustomImpl.java | 9 +++++++++ .../JWT/user/service/event/EventServiceImpl.java | 11 +---------- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/controller/EventController.java b/JWT/src/main/java/JWTLogIn/JWT/user/controller/EventController.java index 135b704..d8f9b42 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/controller/EventController.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/controller/EventController.java @@ -41,7 +41,7 @@ public ResponseEntity> calendar_main( } - // day==0 이면 일정보가 필요없어서 디폴트 값이 할당된것 + // day==0 이면 일정보가 필요없어서 디폴트 값이 할당된것 -> if(day == 0){ return ResponseEntity.ok(eventServiceImpl.findMonthlyEvents(year, month)); } @@ -83,7 +83,7 @@ public ResponseEntity calendar_put(@Valid @RequestBody UpdateEventDTO updateE public ResponseEntity calendar_delete(@PathVariable("event_id") Long id){ // 예외처리: event_id를 pk로 갖지 않으면 예외 if (!eventServiceImpl.checkById(id)){ - throw new NotFoundException("존재하지 않는 이벤트"); + throw new NotFoundException("존재하지 않는 이벤트 오류"); } eventServiceImpl.eventDelete(id); return ResponseEntity.ok().build(); diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepository.java b/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepository.java index b7590f1..d28c78f 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepository.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepository.java @@ -11,7 +11,5 @@ @Repository public interface EventRepository extends JpaRepository { - @Query("SELECT e FROM EventEntity e WHERE YEAR(e.startDate) = :year AND MONTH(e.startDate) = :month") - List findMonthEvents(int year, int month); } \ No newline at end of file diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepositoryCustom.java b/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepositoryCustom.java index 5357c57..2bbcf33 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepositoryCustom.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepositoryCustom.java @@ -1,9 +1,12 @@ package JWTLogIn.JWT.user.repository; import JWTLogIn.JWT.user.entity.EventEntity; +import org.springframework.data.jpa.repository.Query; import java.util.List; public interface EventRepositoryCustom { List findDayEvents(int year, int month, int day); + + List findMonthEvents(int year, int month); } diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepositoryCustomImpl.java b/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepositoryCustomImpl.java index 36a3003..fa12be1 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepositoryCustomImpl.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/repository/EventRepositoryCustomImpl.java @@ -19,4 +19,13 @@ public List findDayEvents(int year, int month, int day) { .setParameter("findDate", findDate) .getResultList(); } + + @Override + public List findMonthEvents(int year, int month) { + return em.createQuery("SELECT e FROM EventEntity e WHERE YEAR(e.startDate) = :year AND MONTH(e.startDate) = :month") + .setParameter("year", year) + .setParameter("month", month) + .getResultList(); + + } } diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/service/event/EventServiceImpl.java b/JWT/src/main/java/JWTLogIn/JWT/user/service/event/EventServiceImpl.java index 30dd624..013d4a5 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/service/event/EventServiceImpl.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/service/event/EventServiceImpl.java @@ -27,7 +27,7 @@ public class EventServiceImpl implements EventService{ @Override public List findMonthlyEvents(int year, int month) { - List monthlyEvents = eventRepository.findMonthEvents(year, month); + List monthlyEvents = eventRepositoryCustom.findMonthEvents(year, month); if(monthlyEvents == null){ return null; } @@ -68,7 +68,6 @@ public EventDetailDTO findDayEvent(Long id) { @Override public void eventSave(PostEventDTO postEventDTO) { EventEntity eventEntity = PostEventDTO.toEntity(postEventDTO); - validateDates(eventEntity.getStartDate(), eventEntity.getEndDate()); eventRepository.save(eventEntity); } @@ -78,7 +77,6 @@ public void eventUpdate(UpdateEventDTO updateEventDTO, Long id) { if(findEvent.isPresent()){ EventEntity eventEntity = findEvent.get(); updateEntityByPutEventDTO(eventEntity, updateEventDTO); - validateDates(eventEntity.getStartDate(), eventEntity.getEndDate()); } } @@ -95,13 +93,6 @@ public void eventDelete(Long id) { //----------------------------------------------------------------------------------------------------- - // start_date와 end_date의 선후 관계 검증을 위한 로직 - public void validateDates(LocalDateTime startDate, LocalDateTime endDate) { - if (startDate != null && endDate != null && endDate.isBefore(startDate)) { - throw new IllegalArgumentException("End date cannot be before start date"); - } - } - // EvenEntity를 EventDetailDTO로 변환하는 로직 public static EventDetailDTO entity2EventDetailDTO(EventEntity eventEntity){ EventDetailDTO eventDetailDTO = EventDetailDTO.builder()