From e8c42b6e5d58284d656b57dbdcfd566eb3621ffa Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 25 Jul 2024 18:47:09 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[fix]=20Routine=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20notify=20->=20complete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/myveggiegarden/entity/Routine.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java index ad80c230..634db128 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java @@ -35,8 +35,8 @@ public class Routine extends BaseEntity { @Column(name = "period") private int period; - @Column(name = "notify") - private boolean notify; + @Column(name = "complete") + private boolean complete; @ManyToOne(fetch = FetchType.LAZY) @@ -44,13 +44,13 @@ public class Routine extends BaseEntity { private MyVeggie myVeggie; - public static Routine createRoutine(Date date, String content, int period, MyVeggie myVeggie, boolean notify){ + public static Routine createRoutine(Date date, String content, int period, MyVeggie myVeggie, boolean complete){ Routine newRoutine = Routine.builder() .date(date) .content(content) .period(period) .myVeggie(myVeggie) - .notify(notify) + .complete(complete) .build(); myVeggie.addRoutine(newRoutine); From b89b7644ab70c2c96ada1ceadfb5691700b4c74b Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 25 Jul 2024 19:25:10 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[fix]=20Routine=20=EC=B6=94=EA=B0=80,=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20=EC=82=AD=EC=A0=9C=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieRoutineController.java | 59 +++++++++++-------- .../controller/TestController.java | 4 -- ...{MyRoutineCheck.java => RoutineCheck.java} | 2 +- .../dto/request/RoutineDelete.java | 16 +++++ .../dto/request/RoutineUpdate.java | 21 +++++++ .../MyVeggieGardenExceptionHandler.java | 5 +- .../exception/RoutineNotFountException.java | 10 ---- .../custom/RoutineNotFoundException.java | 12 ++++ .../repository/RoutineRepository.java | 29 +++++++++ .../repository/TestRepository.java | 4 -- .../service/MyVeggieRoutineService.java | 46 ++++++++++----- .../myveggiegarden/service/TestService.java | 4 -- 12 files changed, 148 insertions(+), 64 deletions(-) delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/TestController.java rename src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/{MyRoutineCheck.java => RoutineCheck.java} (92%) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineDelete.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineUpdate.java delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/RoutineNotFountException.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/custom/RoutineNotFoundException.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/TestRepository.java delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/TestService.java 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 b44c8bc2..6a01d770 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 @@ -1,18 +1,16 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.controller; -import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; -import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.MyRoutineCheck; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineCheck; +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.SettingMyVeggieRoutineReqeuest; -import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyRoutineList; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyVeggieRoutine; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; -import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieRoutineService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.global.response.SuccessCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -27,18 +25,33 @@ public class MyVeggieRoutineController { private final MyVeggieRoutineService myVeggieRoutineService; - @PostMapping(value = "") - public BaseResponseDto settingMyVeggieRoutine( - @Validated @RequestBody SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest - ) { - return myVeggieRoutineService.settingMyVeggieRoutine(settingMyVeggieRoutineReqeuest); + @PostMapping() + public BaseResponseDto settingMyVeggieRoutine(@Validated @RequestBody SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest) { + myVeggieRoutineService.settingMyVeggieRoutine(settingMyVeggieRoutineReqeuest); + log.info("루틴 추가 완료"); + return BaseResponseDto.of(SuccessCode.SUCCESS,null); } + + @PatchMapping() + public BaseResponseDto modifyRoutine(@Validated @RequestBody RoutineUpdate routineUpdate) { + myVeggieRoutineService.modifyRoutine(routineUpdate); + log.info("루틴 수정 완료"); + return BaseResponseDto.of(SuccessCode.SUCCESS,null); + } + + @DeleteMapping + public BaseResponseDto eraseRoutine(@Validated @RequestBody RoutineDelete routineDelete) { + myVeggieRoutineService.eraseRoutine(routineDelete); + log.info("루틴 삭제 완료"); + return BaseResponseDto.of(SuccessCode.SUCCESS,null); + } + + @PostMapping(value = "/check") - public BaseResponseDto checkMyVeggieRoutine( - @Validated @RequestBody MyRoutineCheck myRoutineCheck - ) { - myVeggieRoutineService.checkMyVeggieRoutine(myRoutineCheck.getRoutineId()); + public BaseResponseDto checkVeggieRoutine(@Validated @RequestBody RoutineCheck routineCheck) { + myVeggieRoutineService.checkVeggieRoutine(routineCheck.getRoutineId()); + log.info("루틴 체킹 완료"); return BaseResponseDto.of(SuccessCode.SUCCESS, null); } @@ -48,17 +61,15 @@ public BaseResponseDto selectMyVeggieRoutineById( ) { MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build(); List result = myVeggieRoutineService.selectMyVeggieRoutineById(myVeggie); - return BaseResponseDto.of(SuccessCode.SUCCESS, result); } - @GetMapping(value = "/list") - public BaseResponseDto selectMyVeggieRoutine( - @AuthenticationPrincipal CustomUser user - ) { - - List result = myVeggieRoutineService.selectMyVeggieRoutine(user.getUserId()); - log.info("채소별 리스트 조회 종료"); - return BaseResponseDto.of(SuccessCode.SUCCESS, result); - } +// @GetMapping(value = "/list") +// public BaseResponseDto selectMyVeggieRoutine( +// @AuthenticationPrincipal CustomUser user +// ) { +// List result = myVeggieRoutineService.selectMyVeggieRoutine(user.getUserId()); +// log.info("채소별 리스트 조회 종료"); +// return BaseResponseDto.of(SuccessCode.SUCCESS, result); +// } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/TestController.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/TestController.java deleted file mode 100644 index 8d7db573..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/TestController.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.modernfarmer.farmusspring.domain.myveggiegarden.controller; - -public class TestController { -} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/MyRoutineCheck.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineCheck.java similarity index 92% rename from src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/MyRoutineCheck.java rename to src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineCheck.java index 4e4cd0f9..f7ae4f5d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/MyRoutineCheck.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineCheck.java @@ -10,7 +10,7 @@ @AllArgsConstructor @NoArgsConstructor -public class MyRoutineCheck { +public class RoutineCheck { @NotNull(message = "null 값을 가지면 안됩니다.") private Long routineId; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineDelete.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineDelete.java new file mode 100644 index 00000000..bbab0e08 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineDelete.java @@ -0,0 +1,16 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request; + + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class RoutineDelete { + + @NotNull(message = "null 값을 가지면 안됩니다.") + private Long routineId; +} \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineUpdate.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineUpdate.java new file mode 100644 index 00000000..ff9f6d3d --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineUpdate.java @@ -0,0 +1,21 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class RoutineUpdate { + + @NotNull(message = "null 값을 가지면 안됩니다.") + private String content; + + + private int period; + + @NotNull(message = "null 값을 가지면 안됩니다.") + private Long routineId; +} \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenExceptionHandler.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenExceptionHandler.java index f5fffef0..8170a089 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenExceptionHandler.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenExceptionHandler.java @@ -2,6 +2,7 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.custom.MyVeggieGardenBaseException; +import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.custom.RoutineNotFoundException; import com.modernfarmer.farmusspring.domain.test.exception.TestException; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import jakarta.servlet.http.HttpServletRequest; @@ -13,8 +14,8 @@ @RestControllerAdvice(basePackages = "com.modernfarmer.farmusspring.domain.myveggiegarden.controller") public class MyVeggieGardenExceptionHandler { - @ExceptionHandler(RoutineNotFountException.class) - public BaseResponseDto handleRoutineNotFoundException(RoutineNotFountException e, HttpServletRequest request) { + @ExceptionHandler(RoutineNotFoundException.class) + public BaseResponseDto handleRoutineNotFoundException(RoutineNotFoundException e, HttpServletRequest request) { log.error("RoutineException : {} {} errMessage={}\n", request.getMethod(), request.getRequestURI(), diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/RoutineNotFountException.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/RoutineNotFountException.java deleted file mode 100644 index 977af058..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/RoutineNotFountException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.modernfarmer.farmusspring.domain.myveggiegarden.exception; - -public class RoutineNotFountException extends RuntimeException { - - - public RoutineNotFountException(String message) { - super(message); - } - -} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/custom/RoutineNotFoundException.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/custom/RoutineNotFoundException.java new file mode 100644 index 00000000..7795cf59 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/custom/RoutineNotFoundException.java @@ -0,0 +1,12 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.exception.custom; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.MyVeggieGardenErrorCode; + +public class RoutineNotFoundException extends MyVeggieGardenBaseException { + + + public RoutineNotFoundException(String message, MyVeggieGardenErrorCode errorCode) { + super(message, errorCode); + } + +} \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java new file mode 100644 index 00000000..97cb2feb --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java @@ -0,0 +1,29 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.repository; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.Date; +import java.util.List; +import java.util.Optional; + +@Repository +public interface RoutineRepository extends JpaRepository { + + @Query("SELECT r FROM routine AS r WHERE r.id = :routineId ") + Optional findRoutineById(@Param("routineId") Long routineId); + + + @Modifying + @Query("UPDATE routine AS r SET r.content = :content, r.period = :period WHERE r.id = :routineId") + void updateRoutine(@Param("routineId") Long routineId, @Param("content") String content, @Param("period") int period); + + @Modifying + @Query("DELETE FROM routine AS r WHERE r.id = :routineId") + void deleteRoutine(@Param("routineId") Long routineId); +} \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/TestRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/TestRepository.java deleted file mode 100644 index 9e46b684..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/TestRepository.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.modernfarmer.farmusspring.domain.myveggiegarden.repository; - -public class TestRepository { -} 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 7d18fe35..060f6c63 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 @@ -1,23 +1,24 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; +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.SettingMyVeggieRoutineReqeuest; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyRoutineList; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyVeggieRoutine; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.MyVeggieGardenErrorCode; -import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.RoutineNotFountException; +import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.custom.RoutineNotFoundException; import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.MyVeggieRepository; +import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.RoutineRepository; import com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.global.response.SuccessCode; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Optional; @@ -30,21 +31,30 @@ public class MyVeggieRoutineService { private final MyVeggieGardenService myVeggieGardenService; private final MyVeggieRepository myVeggieRepository; private final DateManager dateManager; + private final RoutineRepository routineRepository; @Transactional - public BaseResponseDto settingMyVeggieRoutine( - SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest - ) { + public void settingMyVeggieRoutine(SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest) { addMyyVeggieRoutine(settingMyVeggieRoutineReqeuest); - return BaseResponseDto.of(SuccessCode.SUCCESS,null); } @Transactional - public List selectMyVeggieRoutineById(MyVeggie myVeggie) { + public void modifyRoutine(RoutineUpdate routineUpdate) { + verifyRoutine(routineRepository.findRoutineById(routineUpdate.getRoutineId())); + routineRepository.updateRoutine(routineUpdate.getRoutineId(), routineUpdate.getContent(), routineUpdate.getPeriod()); + } + + @Transactional + public void eraseRoutine(RoutineDelete routineDelete) { + verifyRoutine(routineRepository.findRoutineById(routineDelete.getRoutineId())); + routineRepository.deleteRoutine(routineDelete.getRoutineId()); + } + @Transactional + public List selectMyVeggieRoutineById(MyVeggie myVeggie) { List routineList = myVeggieRepository.findMyVeggieRoutineById(myVeggie); return MyVeggieRoutine.processData(routineList); } @@ -57,8 +67,9 @@ public List selectMyVeggieRoutine(Long userId) { } @Transactional - public void checkMyVeggieRoutine(Long routineId) { - Optional routine = selectRoutineByRoutineId(routineId); + public void checkVeggieRoutine(Long routineId) { + Optional routine = routineRepository.findRoutineById(routineId); + verifyRoutine(routine); Date addedDate = dateManager.addDate(routine.get().getDate(), routine.get().getPeriod()); myVeggieRepository.updateRoutinePeriod(routineId, addedDate); } @@ -67,13 +78,18 @@ public void checkMyVeggieRoutine(Long routineId) { + public void verifyRoutine(Optional routine){ + if(routine.isEmpty()) + throw new RoutineNotFoundException("존재하지 않는 루틴입니다.", MyVeggieGardenErrorCode.NOT_FOUND_ROUTINE); + } - public Optional selectRoutineByRoutineId(Long routineId){ - return Optional.ofNullable(myVeggieRepository.findRoutineById(routineId) - .orElseThrow(() -> new RoutineNotFountException("해당 루틴이 존재하지 않습니다."))); - } +// +// public Optional selectRoutineByRoutineId(Long routineId){ +// return Optional.ofNullable(myVeggieRepository.findRoutineById(routineId) +// .orElseThrow(() -> new RoutineNotFountException("해당 루틴이 존재하지 않습니다."))); +// } private void addMyyVeggieRoutine(SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest){ MyVeggie myVeggie = myVeggieGardenService.getMyVeggie(settingMyVeggieRoutineReqeuest.getMyVeggieId()); @@ -82,7 +98,7 @@ private void addMyyVeggieRoutine(SettingMyVeggieRoutineReqeuest settingMyVeggieR settingMyVeggieRoutineReqeuest.getContent(), settingMyVeggieRoutineReqeuest.getPeriod(), myVeggie, - settingMyVeggieRoutineReqeuest.isNotify() + false ); myVeggie.addRoutine(newRoutine); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/TestService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/TestService.java deleted file mode 100644 index 7cd1761a..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/TestService.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.modernfarmer.farmusspring.domain.myveggiegarden.service; - -public class TestService { -} From 5a29fb3a40ea584f69909bf517bd8d58fa057313 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 25 Jul 2024 19:54:27 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[fix]=20Routine=20=EC=B2=B4=ED=82=B9=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieRoutineController.java | 6 ++-- ...utineReqeuest.java => RoutineSetting.java} | 2 +- .../domain/myveggiegarden/entity/Routine.java | 3 +- .../repository/RoutineRepository.java | 6 ++++ .../service/MyVeggieRoutineService.java | 33 ++++++------------- 5 files changed, 22 insertions(+), 28 deletions(-) rename src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/{SettingMyVeggieRoutineReqeuest.java => RoutineSetting.java} (91%) 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 6a01d770..b35e9ffd 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 @@ -3,7 +3,7 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineCheck; 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.SettingMyVeggieRoutineReqeuest; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineSetting; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyVeggieRoutine; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieRoutineService; @@ -26,8 +26,8 @@ public class MyVeggieRoutineController { private final MyVeggieRoutineService myVeggieRoutineService; @PostMapping() - public BaseResponseDto settingMyVeggieRoutine(@Validated @RequestBody SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest) { - myVeggieRoutineService.settingMyVeggieRoutine(settingMyVeggieRoutineReqeuest); + public BaseResponseDto settingVeggieRoutine(@Validated @RequestBody RoutineSetting settingRoutine) { + myVeggieRoutineService.settingVeggieRoutine(settingRoutine.getMyVeggieId(), settingRoutine.getContent(), settingRoutine.getPeriod()); log.info("루틴 추가 완료"); return BaseResponseDto.of(SuccessCode.SUCCESS,null); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRoutineReqeuest.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineSetting.java similarity index 91% rename from src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRoutineReqeuest.java rename to src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineSetting.java index 8eea5845..062687bb 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRoutineReqeuest.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/RoutineSetting.java @@ -9,7 +9,7 @@ @Getter @AllArgsConstructor @NoArgsConstructor -public class SettingMyVeggieRoutineReqeuest { +public class RoutineSetting { @NotNull(message = "null 값을 가지면 안됩니다.") private String content; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java index 634db128..9dc03173 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java @@ -26,7 +26,8 @@ public class Routine extends BaseEntity { @Column(name = "routine_id") private Long id; - @Column(name = "date") + @Temporal(TemporalType.DATE) + @Column(name = "date", columnDefinition = "DATE") private Date date; @Column(name = "content") diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java index 97cb2feb..1420f429 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java @@ -26,4 +26,10 @@ public interface RoutineRepository extends JpaRepository { @Modifying @Query("DELETE FROM routine AS r WHERE r.id = :routineId") void deleteRoutine(@Param("routineId") Long routineId); + + + @Modifying + @Query("UPDATE routine AS r SET r.complete = true WHERE r.id = :routineId") + void updateRoutineComplete(@Param("routine") Routine routine, @Param("routineId") Long routineId); + } \ No newline at end of file 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 060f6c63..b1afb94c 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 @@ -2,7 +2,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.SettingMyVeggieRoutineReqeuest; +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.entity.MyVeggie; @@ -12,8 +12,6 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.MyVeggieRepository; import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.RoutineRepository; import com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager; -import com.modernfarmer.farmusspring.global.response.BaseResponseDto; -import com.modernfarmer.farmusspring.global.response.SuccessCode; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -36,8 +34,8 @@ public class MyVeggieRoutineService { @Transactional - public void settingMyVeggieRoutine(SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest) { - addMyyVeggieRoutine(settingMyVeggieRoutineReqeuest); + public void settingVeggieRoutine(Long veggieId, String content, int period) { + addVeggieRoutine(veggieId, content, period, new Date()); } @@ -71,32 +69,21 @@ public void checkVeggieRoutine(Long routineId) { Optional routine = routineRepository.findRoutineById(routineId); verifyRoutine(routine); Date addedDate = dateManager.addDate(routine.get().getDate(), routine.get().getPeriod()); - myVeggieRepository.updateRoutinePeriod(routineId, addedDate); + routineRepository.updateRoutineComplete(routine.get(), routineId); + addVeggieRoutine(routine.get().getMyVeggie().getId(), routine.get().getContent(), routine.get().getPeriod(), addedDate); } - - - - public void verifyRoutine(Optional routine){ if(routine.isEmpty()) throw new RoutineNotFoundException("존재하지 않는 루틴입니다.", MyVeggieGardenErrorCode.NOT_FOUND_ROUTINE); } - - -// -// public Optional selectRoutineByRoutineId(Long routineId){ -// return Optional.ofNullable(myVeggieRepository.findRoutineById(routineId) -// .orElseThrow(() -> new RoutineNotFountException("해당 루틴이 존재하지 않습니다."))); -// } - - private void addMyyVeggieRoutine(SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest){ - MyVeggie myVeggie = myVeggieGardenService.getMyVeggie(settingMyVeggieRoutineReqeuest.getMyVeggieId()); + private void addVeggieRoutine(Long veggieId, String content, int period, Date date){ + MyVeggie myVeggie = myVeggieGardenService.getMyVeggie(veggieId); Routine newRoutine = Routine.createRoutine( - new Date(), - settingMyVeggieRoutineReqeuest.getContent(), - settingMyVeggieRoutineReqeuest.getPeriod(), + date, + content, + period, myVeggie, false ); From 10570247ec5a4406ed8385395120794e9acb1d0c Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 25 Jul 2024 20:33:57 +0900 Subject: [PATCH 4/6] =?UTF-8?q?[feat]=20=EC=9B=94=EB=B3=84=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=20=EC=B2=B4=ED=82=B9=20=EC=83=81=ED=83=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieRoutineController.java | 32 ++++++++++++ .../dto/response/MyRoutineList.java | 49 ++++++------------- .../dto/response/RoutineMonthChecking.java | 27 ++++++++++ .../repository/RoutineRepository.java | 7 +++ .../service/MyVeggieRoutineService.java | 23 +++++++++ .../myveggiegarden/util/DateManager.java | 16 ++++++ 6 files changed, 121 insertions(+), 33 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/RoutineMonthChecking.java 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 b35e9ffd..9a92cb7b 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 @@ -1,19 +1,26 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.controller; +import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineCheck; 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.MyVeggieRoutine; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.RoutineMonthChecking; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieRoutineService; +import com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager; +import com.modernfarmer.farmusspring.domain.user.entity.User; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.global.response.SuccessCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.text.ParseException; +import java.util.Date; import java.util.List; @@ -24,6 +31,7 @@ public class MyVeggieRoutineController { private final MyVeggieRoutineService myVeggieRoutineService; + private final DateManager dateManager; @PostMapping() public BaseResponseDto settingVeggieRoutine(@Validated @RequestBody RoutineSetting settingRoutine) { @@ -71,5 +79,29 @@ public BaseResponseDto selectMyVeggieRoutineById( // List result = myVeggieRoutineService.selectMyVeggieRoutine(user.getUserId()); // log.info("채소별 리스트 조회 종료"); // return BaseResponseDto.of(SuccessCode.SUCCESS, result); +// } + + @GetMapping("/month/{month}") + public BaseResponseDto selectRoutineCheckingAccordingToMonth( + @AuthenticationPrincipal CustomUser user, + @PathVariable("month") String month + ) throws ParseException { + User userObject = User.builder().id(user.getUserId()).build(); + Date parsingDate = dateManager.formatMonthStringToDate(month); + RoutineMonthChecking routineMonthChecking = myVeggieRoutineService.selectRoutineCheckingAccordingToMonth(userObject,parsingDate); + log.info("월 기준 날짜 체킹 상태 조회 완료"); + return BaseResponseDto.of(SuccessCode.SUCCESS, routineMonthChecking); + } + + +// @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 01d622c4..05a9f41b 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,20 +1,18 @@ 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 @@ -23,54 +21,39 @@ public class MyRoutineList { private String nickname; private String veggieName; + 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(), + myVeggie.getId(), myVeggieRoutineList ); } - 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() .map(routine -> { boolean check; - check = signRoutineCheck(routine.getDate()); - return new MyVeggieRoutine(check, routine.getContent(), routine.getPeriod(), routine.getId() ); - }) + // check = signRoutineCheck(routine.getDate()); + check = true; + return new MyVeggieRoutine(check, routine.getContent(), routine.getPeriod(), routine.getId()); + }) .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; - } - -} +} \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/RoutineMonthChecking.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/RoutineMonthChecking.java new file mode 100644 index 00000000..7fb135dc --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/RoutineMonthChecking.java @@ -0,0 +1,27 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import java.util.Date; +import java.util.List; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Slf4j +public class RoutineMonthChecking { + + private List date; + + public static RoutineMonthChecking of(List date){ + return new RoutineMonthChecking(date); + } + + + + +} \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java index 1420f429..7a875755 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java @@ -2,6 +2,7 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; +import com.modernfarmer.farmusspring.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -32,4 +33,10 @@ public interface RoutineRepository extends JpaRepository { @Query("UPDATE routine AS r SET r.complete = true WHERE r.id = :routineId") void updateRoutineComplete(@Param("routine") Routine routine, @Param("routineId") Long routineId); + @Query("SELECT r FROM routine AS r " + + "JOIN FETCH r.myVeggie AS mv " + + "WHERE mv.user = :user AND " + + "FUNCTION('YEAR', r.date) = FUNCTION('YEAR', :month) AND FUNCTION('MONTH', r.date) = FUNCTION('MONTH', :month)") + List findRoutineAndRoutineAndMyVeggieByMonthWithUser(@Param("month") Date month, @Param("user") User user ); + } \ No newline at end of file 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 b1afb94c..711df267 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 @@ -5,6 +5,7 @@ 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; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.MyVeggieGardenErrorCode; @@ -12,6 +13,7 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.MyVeggieRepository; import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.RoutineRepository; import com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager; +import com.modernfarmer.farmusspring.domain.user.entity.User; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -64,6 +66,19 @@ public List selectMyVeggieRoutine(Long userId) { return MyRoutineList.processData(myVeggieList); } + @Transactional + public RoutineMonthChecking selectRoutineCheckingAccordingToMonth(User user, Date month) { + List routineTimeList = routineRepository.findRoutineAndRoutineAndMyVeggieByMonthWithUser(month, user); + return RoutineMonthChecking.of(extractDate(routineTimeList)); + } + + +// @Transactional +// public List selectRoutineAccordingToDate(User user, Date day) { +// List myVeggieList = myVeggieRepository.findMyVeggieAndRoutineTimeAndRoutineByUserWithDate(user, day); +// return mappingMyVeggieListData(myVeggieList, day); +// } + @Transactional public void checkVeggieRoutine(Long routineId) { Optional routine = routineRepository.findRoutineById(routineId); @@ -91,4 +106,12 @@ private void addVeggieRoutine(Long veggieId, String content, int period, Date da } + public List extractDate(List routineList){ + return routineList.stream() + .map(Routine::getDate) + .distinct() + .toList(); + } + + } 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 38f78cbe..2fb809b9 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 @@ -2,6 +2,7 @@ import org.springframework.stereotype.Component; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -48,4 +49,19 @@ public Date addDate(Date date, int addDate){ return cal.getTime(); } + public Date formatMonthStringToDate(String month) throws ParseException { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM"); + return dateFormat.parse(month); + } + + public Date formatDayStringToDate(String day) throws ParseException { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + return dateFormat.parse(day); + } + + public String formatDayDateToString(Date day) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + return dateFormat.format(day); + } + } From b7b01f059c3ce4db1616d0b98b1396d2e25343f4 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 25 Jul 2024 21:59:46 +0900 Subject: [PATCH 5/6] =?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) { From 5515ba7cce4cedb1543a74d7679ed6f9627cd778 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 25 Jul 2024 22:36:21 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[fix]=20DateManager=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?static=ED=99=94,=20=EB=93=A4=EC=97=AC=EC=93=B0=EA=B8=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieRoutineController.java | 7 ++--- .../dto/response/MyRoutineList.java | 4 +-- .../dto/response/MyVeggieRoutine.java | 27 +------------------ .../service/MyVeggieDiaryService.java | 5 ++-- .../service/MyVeggieGardenService.java | 6 ++--- .../service/MyVeggieRoutineService.java | 19 +++---------- .../myveggiegarden/util/DateManager.java | 14 +++++----- .../domain/user/util/DateManager.java | 2 +- 8 files changed, 19 insertions(+), 65 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 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); }