Skip to content

Commit

Permalink
refactor : getSubgoalInfoByUserId 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
soHyn committed Jan 12, 2024
1 parent 2dff71a commit 83b6c2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ public class SubgoalResponse {
private String goalName;
private Long goalId;
private LocalDate goalCreateDate;
private List<SubgoalInfo> Subgoals;
private List<SubgoalInfo> SubgoalList;

@Data
@NoArgsConstructor
public static class SubgoalInfo {
private Long subgoalId;
private String subgoalName;
private List<LocalDate> doneDateList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import tenten.blooming.domain.user.repository.UserRepository;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -52,10 +53,23 @@ public List<Goal> getGoalByUserId(Long userId) {

public SubgoalResponse getSubgoalInfoByUserId(Long userId) {
List<Goal> goals = getGoalByUserId(userId);
// Goal goal = goals.get(goals.size() - 1);
Goal goal = goals.get(goals.size() - 1);
List<Subgoal> subgoals = goal.getSubgoals();
SubgoalResponse subgoalResponse = new SubgoalResponse();
List<SubgoalResponse.SubgoalInfo> subgoalInfoList = new ArrayList<>();

for(Subgoal subgoal : subgoals) {
SubgoalResponse.SubgoalInfo subgoalInfo = new SubgoalResponse.SubgoalInfo();
subgoalInfo.setSubgoalId(subgoal.getSubgoalId());
subgoalInfo.setSubgoalName(subgoal.getSubgoalName());
subgoalInfo.setDoneDateList(subgoal.getDoneDates());
subgoalInfoList.add(subgoalInfo);
}

SubgoalResponse subgoalResponse = new SubgoalResponse();
subgoalResponse.setGoalName(goal.getGoalName());
subgoalResponse.setGoalId(goal.getGoalId());
subgoalResponse.setGoalCreateDate(goal.getCreatedAt());
subgoalResponse.setSubgoalList(subgoalInfoList);

return subgoalResponse;
}
Expand Down

0 comments on commit 83b6c2f

Please sign in to comment.