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 549fc1b7..d019f8ae 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 @@ -32,7 +32,6 @@ public class MyVeggieRoutineController { private final MyVeggieRoutineService myVeggieRoutineService; - private final DateManager dateManager; @PostMapping() public BaseResponseDto settingVeggieRoutine(@Validated @RequestBody RoutineSetting settingRoutine) { @@ -41,7 +40,6 @@ public BaseResponseDto settingVeggieRoutine(@Validated @RequestBody RoutineSe return BaseResponseDto.of(SuccessCode.SUCCESS,null); } - @PatchMapping() public BaseResponseDto modifyRoutine(@Validated @RequestBody RoutineUpdate routineUpdate) { myVeggieRoutineService.modifyRoutine(routineUpdate); @@ -56,7 +54,6 @@ public BaseResponseDto eraseRoutine(@Validated @RequestBody RoutineDelete rou return BaseResponseDto.of(SuccessCode.SUCCESS,null); } - @PostMapping(value = "/check") public BaseResponseDto checkVeggieRoutine(@Validated @RequestBody RoutineCheck routineCheck) { myVeggieRoutineService.checkVeggieRoutine(routineCheck.getRoutineId()); @@ -88,7 +85,7 @@ public BaseResponseDto selectRoutineCheckingAccordingToMonth( @PathVariable("month") String month ) throws ParseException { User userObject = User.builder().id(user.getUserId()).build(); - Date parsingDate = dateManager.formatMonthStringToDate(month); + Date parsingDate = DateManager.formatMonthStringToDate(month); RoutineMonthChecking routineMonthChecking = myVeggieRoutineService.selectRoutineCheckingAccordingToMonth(userObject,parsingDate); log.info("월 기준 날짜 체킹 상태 조회 완료"); return BaseResponseDto.of(SuccessCode.SUCCESS, routineMonthChecking); @@ -100,7 +97,7 @@ 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); + 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 d6b0c424..d3ef231e 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 @@ -30,8 +30,7 @@ public static MyRoutineList of(MyVeggie myVeggie, List myVeggie myVeggie.getNickname(), myVeggie.getVeggieName(), myVeggie.getId(), - myVeggieRoutineList - ); + myVeggieRoutineList); } public static List processData(List myVeggieList){ @@ -43,7 +42,6 @@ public static List processData(List myVeggieList){ } private static List checkRoutine(MyVeggie myVeggie){ - if(myVeggie.getRoutines().isEmpty()){ return new ArrayList<>(); } 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 77cc80fe..fb586635 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 @@ -34,39 +34,14 @@ public static MyVeggieRoutine of(Routine routine){ routine.isComplete(), routine.getContent(), routine.getPeriod(), - routine.getId() - ); + routine.getId()); } - - public static List processData(List routineList){ return routineList.stream() .map(routine -> { - boolean check; - log.info(String.valueOf(routine.getDate())); - log.info("true/false 체크"); - check = signRoutineCheck(routine.getDate()); return MyVeggieRoutine.of(routine); }) .toList(); } - - - private static Boolean signRoutineCheck(Date date){ - boolean check = true; - String date1 = String.valueOf(date); - LocalDate currentDate = LocalDate.now(); - LocalTime fixedTime = LocalTime.of(0, 0, 0, 0); - LocalDateTime dateTime = LocalDateTime.of(currentDate, fixedTime); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"); - String formattedDateTime = dateTime.format(formatter); - if (date1.equals(formattedDateTime)) { - check = false; - } - log.info(String.valueOf(date1)); - log.info(String.valueOf(formattedDateTime)); - return check; - } - } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java index a1bc13a4..e34426c9 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java @@ -36,7 +36,6 @@ public class MyVeggieDiaryService { private final MyVeggieRepository myVeggieRepository; private final UserService userService; private final DiaryRepository diaryRepository; - private final DateManager dateManager; @Transactional public BaseResponseDto settingMyVeggieDiary( @@ -84,7 +83,7 @@ private List proccessFarmClubData(List diaryList){ return FarmClubDiary.of( diary, user, - dateManager.dotDateTime(diary.getCreatedDate()), + DateManager.dotDateTime(diary.getCreatedDate()), diary.getDiaryComments().size(), diary.getDiaryLikes().size() );}).toList(); @@ -153,7 +152,7 @@ public BaseResponseDto selectDiaryOne( SelectDiaryOneResponse.of( diaryList.get(0).getImage(), diaryList.get(0).getContent(), - dateManager.formatDate(diaryList.get(0).getCreatedDate()) + DateManager.formatDate(diaryList.get(0).getCreatedDate()) )); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieGardenService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieGardenService.java index ebb5fdca..1fee0f02 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieGardenService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieGardenService.java @@ -27,9 +27,7 @@ public class MyVeggieGardenService { private final MyVeggieRepository myVeggieRepository; - private final DateManager dateManager; private final MyDetailMyVeggieDto myDetailMyVeggieDto; - private final VeggieInfoHelper veggieInfoHelper; @@ -63,8 +61,8 @@ public BaseResponseDto selectMyVeggieProfile(Long myVeggie.getNickname(), myVeggie.getVeggieName(), myVeggie.getVeggieImage(), - dateManager.parsingDotDate(myVeggie.getBirth()), - dateManager.calculateDay(myVeggie.getBirth(), new Date()), + DateManager.parsingDotDate(myVeggie.getBirth()), + DateManager.calculateDay(myVeggie.getBirth(), new Date()), checkFarmClubAffiliation(myVeggie) )); } 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 7a5afc2f..16eb71d0 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 @@ -32,13 +32,11 @@ public class MyVeggieRoutineService { private final RoutineRepository routineRepository; - @Transactional public void settingVeggieRoutine(Long veggieId, String content, int period) { addVeggieRoutine(veggieId, content, period, new Date()); } - @Transactional public void modifyRoutine(RoutineUpdate routineUpdate) { verifyRoutine(routineRepository.findRoutineById(routineUpdate.getRoutineId())); @@ -70,7 +68,6 @@ public RoutineMonthChecking selectRoutineCheckingAccordingToMonth(User user, Dat return RoutineMonthChecking.of(extractDate(routineTimeList)); } - @Transactional public List selectRoutineAccordingToDate(User user, Date day) { List myVeggieList = myVeggieRepository.findMyVeggieAndRoutineByUserWithDate(user); @@ -86,19 +83,16 @@ public List mappingMyVeggieListData(List myVeggieList, private List mappingRoutineListData(MyVeggie myVeggie, Date day) { return myVeggie.getRoutines().stream() - .filter(routine -> Objects.equals(dateManager.formatDayDateToString(day), routine.getDate().toString())) + .filter(routine -> Objects.equals(DateManager.formatDayDateToString(day), routine.getDate().toString())) .map(MyVeggieRoutine::of) .toList(); } - - - @Transactional public void checkVeggieRoutine(Long routineId) { Optional routine = routineRepository.findRoutineById(routineId); verifyRoutine(routine); - Date addedDate = dateManager.addDate(routine.get().getDate(), routine.get().getPeriod()); + Date addedDate = DateManager.addDate(routine.get().getDate(), routine.get().getPeriod()); routineRepository.updateRoutineComplete(routine.get(), routineId); addVeggieRoutine(routine.get().getMyVeggie().getId(), routine.get().getContent(), routine.get().getPeriod(), addedDate); } @@ -110,17 +104,10 @@ public void verifyRoutine(Optional routine){ private void addVeggieRoutine(Long veggieId, String content, int period, Date date){ MyVeggie myVeggie = myVeggieGardenService.getMyVeggie(veggieId); - Routine newRoutine = Routine.createRoutine( - date, - content, - period, - myVeggie, - false - ); + Routine newRoutine = Routine.createRoutine(date,content,period, myVeggie, false); myVeggie.addRoutine(newRoutine); } - public List extractDate(List routineList){ return routineList.stream() .map(Routine::getDate) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/util/DateManager.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/util/DateManager.java index 2fb809b9..3e16d5cb 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/util/DateManager.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/util/DateManager.java @@ -13,7 +13,7 @@ @Component public class DateManager { - public String parsingDotDate(Date date){ + public static String parsingDotDate(Date date){ SimpleDateFormat format = new SimpleDateFormat("yy.MM.dd"); return format.format(date); } @@ -24,11 +24,11 @@ public static String parsingDotDateTime(LocalDateTime date){ return date.format(formatter); } - public String dotDateTime(LocalDateTime date){ + public static String dotDateTime(LocalDateTime date){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy.MM.dd HH:mm"); return date.format(formatter); } - public int calculateDay(Date startDate, Date endDate) { + public static int calculateDay(Date startDate, Date endDate) { long differenceMillis = endDate.getTime() - startDate.getTime(); long differenceDays = differenceMillis / (1000 * 60 * 60 * 24); return (int) differenceDays; @@ -42,24 +42,24 @@ public static String formatDate(LocalDateTime date) { } - public Date addDate(Date date, int addDate){ + public static Date addDate(Date date, int addDate){ Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DAY_OF_MONTH, addDate); // 3일을 더함 return cal.getTime(); } - public Date formatMonthStringToDate(String month) throws ParseException { + public static Date formatMonthStringToDate(String month) throws ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM"); return dateFormat.parse(month); } - public Date formatDayStringToDate(String day) throws ParseException { + public static Date formatDayStringToDate(String day) throws ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); return dateFormat.parse(day); } - public String formatDayDateToString(Date day) { + public static String formatDayDateToString(Date day) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); return dateFormat.format(day); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/util/DateManager.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/util/DateManager.java index 20f6b8a6..f2f047f4 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/util/DateManager.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/util/DateManager.java @@ -25,7 +25,7 @@ public static String parsingDotDateTime(LocalDateTime date){ return date.format(formatter); } - public String dotDateTime(LocalDateTime date){ + public static String dotDateTime(LocalDateTime date){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy.MM.dd HH:mm"); return date.format(formatter); }