From b7b01f059c3ce4db1616d0b98b1396d2e25343f4 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 25 Jul 2024 21:59:46 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EB=82=A0=EC=A7=9C=EB=B3=84=20?= =?UTF-8?q?=EC=B1=84=EC=86=8C=EB=93=A4=EC=9D=98=20=EB=A3=A8=ED=8B=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieRoutineController.java | 21 +++++++------ .../dto/response/MyRoutineList.java | 28 +++++++++-------- .../dto/response/MyVeggieRoutine.java | 8 ++--- .../repository/MyVeggieRepository.java | 6 ++++ .../service/MyVeggieRoutineService.java | 31 ++++++++++++++----- 5 files changed, 59 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java index 9a92cb7b..549fc1b7 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java @@ -5,6 +5,7 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineDelete; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineUpdate; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineSetting; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyRoutineList; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyVeggieRoutine; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.RoutineMonthChecking; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; @@ -94,14 +95,14 @@ public BaseResponseDto selectRoutineCheckingAccordingToMonth( } -// @GetMapping("/date/{date}") -// public BaseResponseDto selectRoutineAccordingToDate( -// @AuthenticationPrincipal CustomUser user, -// @PathVariable("date") String date) throws ParseException { -// User userObject = User.builder().id(user.getUserId()).build(); -// Date parsingDate = dateManager.formatDayStringToDate(date); -// List myRoutineLists = myVeggieRoutineService.selectRoutineAccordingToDate(userObject, parsingDate); -// log.info("날짜별 루틴 조회 완료"); -// return BaseResponseDto.of(SuccessCode.SUCCESS, myRoutineLists); -// } + @GetMapping("/date/{date}") + public BaseResponseDto selectRoutineAccordingToDate( + @AuthenticationPrincipal CustomUser user, + @PathVariable("date") String date) throws ParseException { + User userObject = User.builder().id(user.getUserId()).build(); + Date parsingDate = dateManager.formatDayStringToDate(date); + List myRoutineLists = myVeggieRoutineService.selectRoutineAccordingToDate(userObject, parsingDate); + log.info("날짜별 루틴 조회 완료"); + return BaseResponseDto.of(SuccessCode.SUCCESS, myRoutineLists); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyRoutineList.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyRoutineList.java index 05a9f41b..d6b0c424 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyRoutineList.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyRoutineList.java @@ -1,18 +1,19 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; - import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; - +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; - +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; - +import java.util.Date; import java.util.List; - @AllArgsConstructor @NoArgsConstructor @Getter @@ -24,8 +25,7 @@ public class MyRoutineList { private Long myVeggieId; private List myVeggieRoutineList; - - public static MyRoutineList of(MyVeggie myVeggie, List myVeggieRoutineList) { + public static MyRoutineList of(MyVeggie myVeggie, List myVeggieRoutineList){ return new MyRoutineList( myVeggie.getNickname(), myVeggie.getVeggieName(), @@ -34,17 +34,17 @@ public static MyRoutineList of(MyVeggie myVeggie, List myVeggie ); } - - public static List processData(List myVeggieList) { + public static List processData(List myVeggieList){ return myVeggieList.stream() .map(myVeggie -> { - return MyRoutineList.of(myVeggie, checkRoutine(myVeggie)); + return MyRoutineList.of(myVeggie,checkRoutine(myVeggie)); }) .toList(); } - private static List checkRoutine(MyVeggie myVeggie) { - if (myVeggie.getRoutines().isEmpty()) { + private static List checkRoutine(MyVeggie myVeggie){ + + if(myVeggie.getRoutines().isEmpty()){ return new ArrayList<>(); } return myVeggie.getRoutines().stream() @@ -52,8 +52,10 @@ private static List checkRoutine(MyVeggie myVeggie) { boolean check; // check = signRoutineCheck(routine.getDate()); check = true; - return new MyVeggieRoutine(check, routine.getContent(), routine.getPeriod(), routine.getId()); + return new MyVeggieRoutine(check, routine.getContent(), routine.getPeriod(), routine.getId() ); }) .toList(); } + + } \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieRoutine.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieRoutine.java index 7784ed5a..77cc80fe 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieRoutine.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieRoutine.java @@ -23,15 +23,15 @@ @Slf4j public class MyVeggieRoutine { - private Boolean check; + private Boolean complete; private String content; private int period; private Long routineId; - public static MyVeggieRoutine of(Routine routine, Boolean check){ + public static MyVeggieRoutine of(Routine routine){ return new MyVeggieRoutine( - check, + routine.isComplete(), routine.getContent(), routine.getPeriod(), routine.getId() @@ -47,7 +47,7 @@ public static List processData(List routineList){ log.info(String.valueOf(routine.getDate())); log.info("true/false 체크"); check = signRoutineCheck(routine.getDate()); - return MyVeggieRoutine.of(routine, check); + return MyVeggieRoutine.of(routine); }) .toList(); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java index 14dbc1e9..2384b01b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java @@ -73,4 +73,10 @@ void updateMyVeggie(@Param("myVeggieId") Long myVeggieId, @Modifying @Query("UPDATE routine AS r SET r.date = :date WHERE r.id = :routineId") void updateRoutinePeriod(@Param("routineId") Long routineId, @Param("date") Date date); + + @Query("SELECT mv FROM my_veggie AS mv " + + "LEFT JOIN mv.routines AS r " + + "WHERE mv.user= :user " + ) + List findMyVeggieAndRoutineByUserWithDate(@Param("user") User user); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java index 711df267..7a5afc2f 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java @@ -19,9 +19,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Date; -import java.util.List; -import java.util.Optional; +import java.util.*; @Slf4j @AllArgsConstructor @@ -73,11 +71,28 @@ public RoutineMonthChecking selectRoutineCheckingAccordingToMonth(User user, Dat } -// @Transactional -// public List selectRoutineAccordingToDate(User user, Date day) { -// List myVeggieList = myVeggieRepository.findMyVeggieAndRoutineTimeAndRoutineByUserWithDate(user, day); -// return mappingMyVeggieListData(myVeggieList, day); -// } + @Transactional + public List selectRoutineAccordingToDate(User user, Date day) { + List myVeggieList = myVeggieRepository.findMyVeggieAndRoutineByUserWithDate(user); + return mappingMyVeggieListData(myVeggieList, day); + } + + public List mappingMyVeggieListData(List myVeggieList, Date day){ + return myVeggieList.stream() + .map(myVeggie -> MyRoutineList.of(myVeggie, mappingRoutineListData(myVeggie, day))) + .toList(); + } + + + private List mappingRoutineListData(MyVeggie myVeggie, Date day) { + return myVeggie.getRoutines().stream() + .filter(routine -> Objects.equals(dateManager.formatDayDateToString(day), routine.getDate().toString())) + .map(MyVeggieRoutine::of) + .toList(); + } + + + @Transactional public void checkVeggieRoutine(Long routineId) {