Skip to content

Commit

Permalink
feat: Plan 날짜별로 조회 기능 자료형 변경(#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
heej-ng committed Jun 14, 2022
1 parent d515248 commit f5f7fb9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import planshare.server.planshare.domain.Plan;
import planshare.server.planshare.plan.dto.PlanDate;
import planshare.server.planshare.plan.dto.PlanEx;
import planshare.server.planshare.plan.dto.PlanForm;
import planshare.server.planshare.plan.dto.PlanName;
Expand Down Expand Up @@ -48,10 +49,10 @@ public List<Plan> readPlansByGoal(@AuthenticationPrincipal CustomUserDetailsVO u

@ApiOperation(value = "해당 goal에 속하고 months에 해당하는 달의 plan 목록 조회 API", notes = "일별로 정렬한 plan 리스트 반환")
@GetMapping("/users/{memberId}/goals/plans/years/{year}/months/{month}")
public Map<String, List<PlanEx>> readPlanByDate(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@PathVariable(name = "memberId") Long memberId,
@PathVariable(name = "year") int year,
@PathVariable(name = "month") int month){
public List<PlanDate> readPlanByDate(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@PathVariable(name = "memberId") Long memberId,
@PathVariable(name = "year") int year,
@PathVariable(name = "month") int month){
return planService.findPlanByDate(userDetailsVO, memberId, year, month);
}

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/planshare/server/planshare/plan/dto/PlanDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package planshare.server.planshare.plan.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.List;

@Getter
@Setter
@JsonNaming(value = PropertyNamingStrategy.SnakeCaseStrategy.class)
public class PlanDate {

private String date;

private List<PlanEx> planExList;

public static PlanDate createPlanDate(String date, List<PlanEx> planExList){
PlanDate planDate = new PlanDate();
planDate.date = date;
planDate.planExList = planExList;

return planDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import planshare.server.planshare.domain.Member;
import planshare.server.planshare.domain.Plan;
import planshare.server.planshare.goal.repository.GoalRepository;
import planshare.server.planshare.plan.dto.PlanDate;
import planshare.server.planshare.plan.dto.PlanEx;
import planshare.server.planshare.plan.dto.PlanForm;
import planshare.server.planshare.plan.repository.PlanRepository;
Expand Down Expand Up @@ -84,13 +85,13 @@ public List<Plan> findPlansOfGoal(CustomUserDetailsVO userDetailsVO, Long goalId
* select plan list by date
* 일별로 묶어서 반환
*/
public Map<String, List<PlanEx>> findPlanByDate(CustomUserDetailsVO userDetailsVO, Long memberId, int year, int month){
public List<PlanDate> findPlanByDate(CustomUserDetailsVO userDetailsVO, Long memberId, int year, int month){

Optional<Member> user = memberRepository.findByEmail(userDetailsVO.getUsername()); // 요청한 사용자
Optional<Member> member = memberRepository.findById(memberId); // 요청된 멤버
List<Goal> goalList = goalRepository.findByMember(member.get());

Map<String, List<PlanEx>> planDate = new HashMap<>();
Map<String, List<PlanEx>> planMap = new HashMap<>();
List<Plan> planList = new ArrayList<>();

for (Goal goal : goalList){
Expand All @@ -104,14 +105,21 @@ public Map<String, List<PlanEx>> findPlanByDate(CustomUserDetailsVO userDetailsV
String convertedDate = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

List<PlanEx> planExes = new ArrayList<>();
List<PlanEx> planExList = planDate.getOrDefault(convertedDate, planExes);
List<PlanEx> planExList = planMap.getOrDefault(convertedDate, planExes);

PlanEx planEx = PlanEx.createPlanEx(plan.getId(), plan.getName(), plan.isCheckStatus(), plan.getGoal());
planExList.add(planEx);
planDate.put(convertedDate, planExList);
planMap.put(convertedDate, planExList);
}
}
return planDate;

List<PlanDate> planDateList = new ArrayList<>();
for (String key : planMap.keySet()){
PlanDate planDate = PlanDate.createPlanDate(key, planMap.get(key));
planDateList.add(planDate);
}

return planDateList;
}

/**
Expand Down

0 comments on commit f5f7fb9

Please sign in to comment.