Skip to content

Commit

Permalink
[fix] DateManager 함수 static화, 들여쓰기 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryeolee committed Jul 25, 2024
1 parent b7b01f0 commit 5515ba7
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
public class MyVeggieRoutineController {

private final MyVeggieRoutineService myVeggieRoutineService;
private final DateManager dateManager;

@PostMapping()
public BaseResponseDto<?> settingVeggieRoutine(@Validated @RequestBody RoutineSetting settingRoutine) {
Expand All @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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<MyRoutineList> myRoutineLists = myVeggieRoutineService.selectRoutineAccordingToDate(userObject, parsingDate);
log.info("날짜별 루틴 조회 완료");
return BaseResponseDto.of(SuccessCode.SUCCESS, myRoutineLists);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static MyRoutineList of(MyVeggie myVeggie, List<MyVeggieRoutine> myVeggie
myVeggie.getNickname(),
myVeggie.getVeggieName(),
myVeggie.getId(),
myVeggieRoutineList
);
myVeggieRoutineList);
}

public static List<MyRoutineList> processData(List<MyVeggie> myVeggieList){
Expand All @@ -43,7 +42,6 @@ public static List<MyRoutineList> processData(List<MyVeggie> myVeggieList){
}

private static List<MyVeggieRoutine> checkRoutine(MyVeggie myVeggie){

if(myVeggie.getRoutines().isEmpty()){
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,14 @@ public static MyVeggieRoutine of(Routine routine){
routine.isComplete(),
routine.getContent(),
routine.getPeriod(),
routine.getId()
);
routine.getId());
}



public static List<MyVeggieRoutine> processData(List<Routine> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> settingMyVeggieDiary(
Expand Down Expand Up @@ -84,7 +83,7 @@ private List<FarmClubDiary> proccessFarmClubData(List<Diary> diaryList){
return FarmClubDiary.of(
diary,
user,
dateManager.dotDateTime(diary.getCreatedDate()),
DateManager.dotDateTime(diary.getCreatedDate()),
diary.getDiaryComments().size(),
diary.getDiaryLikes().size()
);}).toList();
Expand Down Expand Up @@ -153,7 +152,7 @@ public BaseResponseDto<SelectDiaryOneResponse> selectDiaryOne(
SelectDiaryOneResponse.of(
diaryList.get(0).getImage(),
diaryList.get(0).getContent(),
dateManager.formatDate(diaryList.get(0).getCreatedDate())
DateManager.formatDate(diaryList.get(0).getCreatedDate())
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
public class MyVeggieGardenService {

private final MyVeggieRepository myVeggieRepository;
private final DateManager dateManager;
private final MyDetailMyVeggieDto myDetailMyVeggieDto;

private final VeggieInfoHelper veggieInfoHelper;


Expand Down Expand Up @@ -63,8 +61,8 @@ public BaseResponseDto<SelectMyVeggieProfileResponse> 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)
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -70,7 +68,6 @@ public RoutineMonthChecking selectRoutineCheckingAccordingToMonth(User user, Dat
return RoutineMonthChecking.of(extractDate(routineTimeList));
}


@Transactional
public List<MyRoutineList> selectRoutineAccordingToDate(User user, Date day) {
List<MyVeggie> myVeggieList = myVeggieRepository.findMyVeggieAndRoutineByUserWithDate(user);
Expand All @@ -86,19 +83,16 @@ public List<MyRoutineList> mappingMyVeggieListData(List<MyVeggie> myVeggieList,

private List<MyVeggieRoutine> 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> 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);
}
Expand All @@ -110,17 +104,10 @@ public void verifyRoutine(Optional<Routine> 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<Date> extractDate(List<Routine> routineList){
return routineList.stream()
.map(Routine::getDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 5515ba7

Please sign in to comment.