From 9192bead3f9b9d60b0505d699039d034c9b997c8 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 4 May 2024 11:56:58 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20dateform=20=ED=95=A8=EC=88=98=20->=20ut?= =?UTF-8?q?il=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/myveggiegarden/dto/response/AllDairy.java | 11 ++--------- .../dto/response/MyDetailMyVeggieDto.java | 4 ++-- .../dto/response/SelectMyVeggieListDto.java | 2 +- .../service/MyVeggieGardenService.java | 8 ++++---- .../domain/myveggiegarden/util/DateManager.java | 12 ++++++++++-- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java index 6d6f308c..9e20eaa3 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java @@ -4,12 +4,10 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; - -import java.text.SimpleDateFormat; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.List; +import static com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager.formatDate; + @AllArgsConstructor @NoArgsConstructor @Getter @@ -34,11 +32,6 @@ public static List processData(List diaryList){ .map(diary -> AllDairy.of(diary, formatDate(diary.getCreatedDate()))) .toList(); } - public static String formatDate(LocalDateTime date) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일"); - String formattedDate = date.format(formatter); - return formattedDate; - } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyDetailMyVeggieDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyDetailMyVeggieDto.java index 7b371b13..c11ed6bf 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyDetailMyVeggieDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyDetailMyVeggieDto.java @@ -27,8 +27,8 @@ public List processData(List myVeggieList){ myVeggie.getNickname(), myVeggie.getVeggieImage(), myVeggie.getVeggieName(), - dateManager.dateParsing(myVeggie.getBirth()), - dateManager.dayBetween(myVeggie.getBirth(), new Date()), + dateManager.parsingDotDate(myVeggie.getBirth()), + dateManager.calculateDay(myVeggie.getBirth(), new Date()), myVeggie.getId() )).toList(); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListDto.java index 3a5324ae..ec95b0ac 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListDto.java @@ -14,7 +14,7 @@ @Getter public class SelectMyVeggieListDto { - public List processData(List myVeggieList){ + public static List processData(List myVeggieList){ return myVeggieList.stream() .map(myVeggie -> SelectMyVeggieListResponse.of(myVeggie.getVeggieInfoId(),myVeggie.getNickname())) .toList(); 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 7fb638c2..b723b90e 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,7 +27,7 @@ public class MyVeggieGardenService { private final MyVeggieRepository myVeggieRepository; private final DateManager dateManager; private final MyDetailMyVeggieDto myDetailMyVeggieDto; - private final SelectMyVeggieListDto selectMyVeggieListDto; + @Transactional @@ -40,7 +40,7 @@ public BaseResponseDto settingMyVeggie(Long userId, SettingMyVeggieRequest @Transactional public BaseResponseDto> selectMyVeggieList(Long userId) { List myVeggieList = bringMyVeggieData(userId); - List selectMyVeggieLists = selectMyVeggieListDto.processData(myVeggieList); + List selectMyVeggieLists = SelectMyVeggieListDto.processData(myVeggieList); return BaseResponseDto.of(SuccessCode.SUCCESS,selectMyVeggieLists); } @@ -57,8 +57,8 @@ public BaseResponseDto selectMyVeggieProfile(Long SelectMyVeggieProfileResponse.of( myVeggie.getVeggieName(), myVeggie.getVeggieImage(), - dateManager.dateParsing(myVeggie.getBirth()), - dateManager.dayBetween(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/util/DateManager.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/util/DateManager.java index 9145d96a..605d18fa 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 @@ -3,6 +3,7 @@ import org.springframework.stereotype.Component; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Date; @@ -10,14 +11,21 @@ @Component public class DateManager { - public String dateParsing(Date date){ + public String parsingDotDate(Date date){ SimpleDateFormat format = new SimpleDateFormat("yy.MM.dd"); return format.format(date); } - public int dayBetween(Date startDate, Date endDate) { + public int calculateDay(Date startDate, Date endDate) { long differenceMillis = endDate.getTime() - startDate.getTime(); long differenceDays = differenceMillis / (1000 * 60 * 60 * 24); return (int) differenceDays; } + public static String formatDate(LocalDateTime date) { + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일"); + String formattedDate = date.format(formatter); + return formattedDate; + } + }