Skip to content

Commit

Permalink
[feat] 날짜별 채소들의 루틴 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryeolee committed Jul 25, 2024
1 parent 1057024 commit b7b01f0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MyRoutineList> 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<MyRoutineList> myRoutineLists = myVeggieRoutineService.selectRoutineAccordingToDate(userObject, parsingDate);
log.info("날짜별 루틴 조회 완료");
return BaseResponseDto.of(SuccessCode.SUCCESS, myRoutineLists);
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,8 +25,7 @@ public class MyRoutineList {
private Long myVeggieId;
private List<MyVeggieRoutine> myVeggieRoutineList;


public static MyRoutineList of(MyVeggie myVeggie, List<MyVeggieRoutine> myVeggieRoutineList) {
public static MyRoutineList of(MyVeggie myVeggie, List<MyVeggieRoutine> myVeggieRoutineList){
return new MyRoutineList(
myVeggie.getNickname(),
myVeggie.getVeggieName(),
Expand All @@ -34,26 +34,28 @@ public static MyRoutineList of(MyVeggie myVeggie, List<MyVeggieRoutine> myVeggie
);
}


public static List<MyRoutineList> processData(List<MyVeggie> myVeggieList) {
public static List<MyRoutineList> processData(List<MyVeggie> myVeggieList){
return myVeggieList.stream()
.map(myVeggie -> {
return MyRoutineList.of(myVeggie, checkRoutine(myVeggie));
return MyRoutineList.of(myVeggie,checkRoutine(myVeggie));
})
.toList();
}

private static List<MyVeggieRoutine> checkRoutine(MyVeggie myVeggie) {
if (myVeggie.getRoutines().isEmpty()) {
private static List<MyVeggieRoutine> checkRoutine(MyVeggie myVeggie){

if(myVeggie.getRoutines().isEmpty()){
return new ArrayList<>();
}
return myVeggie.getRoutines().stream()
.map(routine -> {
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();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -47,7 +47,7 @@ public static List<MyVeggieRoutine> processData(List<Routine> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyVeggie> findMyVeggieAndRoutineByUserWithDate(@Param("user") User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,11 +71,28 @@ public RoutineMonthChecking selectRoutineCheckingAccordingToMonth(User user, Dat
}


// @Transactional
// public List<MyRoutineList> selectRoutineAccordingToDate(User user, Date day) {
// List<MyVeggie> myVeggieList = myVeggieRepository.findMyVeggieAndRoutineTimeAndRoutineByUserWithDate(user, day);
// return mappingMyVeggieListData(myVeggieList, day);
// }
@Transactional
public List<MyRoutineList> selectRoutineAccordingToDate(User user, Date day) {
List<MyVeggie> myVeggieList = myVeggieRepository.findMyVeggieAndRoutineByUserWithDate(user);
return mappingMyVeggieListData(myVeggieList, day);
}

public List<MyRoutineList> mappingMyVeggieListData(List<MyVeggie> myVeggieList, Date day){
return myVeggieList.stream()
.map(myVeggie -> MyRoutineList.of(myVeggie, mappingRoutineListData(myVeggie, day)))
.toList();
}


private List<MyVeggieRoutine> 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) {
Expand Down

0 comments on commit b7b01f0

Please sign in to comment.