|
10 | 10 | import com.haapyProcess.domain.condition.entity.Condition; |
11 | 11 | import com.haapyProcess.domain.condition.repository.ConditionRepository; |
12 | 12 | import com.haapyProcess.domain.family.dto.AddFamilyRequest; |
| 13 | +import com.haapyProcess.domain.family.dto.FamilyListResponse; |
13 | 14 | import com.haapyProcess.domain.family.dto.FamilyMemberResponse; |
14 | 15 | import com.haapyProcess.domain.family.entity.Family; |
15 | 16 | import com.haapyProcess.domain.family.repository.FamilyRepository; |
@@ -73,59 +74,83 @@ public Long addFamily(AddFamilyRequest request) { |
73 | 74 | return familyRepository.save(family).getFamilyId(); |
74 | 75 | } |
75 | 76 |
|
76 | | - // 2. 가족 목록 조회 (위험도 + 지역 + 알림 시간 포함) |
| 77 | + // 2-1. 가족 목록 조회 (가벼운 버전: 이름 + 질병 + 알림 시간만) |
77 | 78 | @Transactional(readOnly = true) |
78 | | - public List<FamilyMemberResponse> getMyFamilies() { |
| 79 | + public List<FamilyListResponse> getMyFamilies() { |
79 | 80 | Member me = memberService.getCurrentMember(); |
80 | 81 | List<Family> families = familyRepository.findAllByUser(me); |
81 | 82 |
|
82 | 83 | return families.stream().map(family -> { |
83 | 84 | Member relative = family.getRelative(); |
84 | 85 |
|
85 | | - int age = relative.getBirth() != null |
86 | | - ? Period.between(relative.getBirth(), LocalDate.now()).getYears() |
87 | | - : 0; |
88 | | - |
89 | 86 | List<String> conditionNames = relative.getHealthConditions().stream() |
90 | 87 | .map(hc -> hc.getCondition().getConditionName()) |
91 | 88 | .toList(); |
92 | 89 |
|
93 | | - // 날씨 위험도 분석 (가족이 위치 미등록이거나 기상청 에러 시 방어) |
94 | | - RiskAnalysisResult riskResult; |
95 | | - try { |
96 | | - riskResult = riskAnalysisService.analyzeRiskForMember(relative); |
97 | | - } catch (Exception e) { |
98 | | - riskResult = new RiskAnalysisResult(false, null); |
99 | | - } |
100 | | - |
101 | | - List<String> causeDiseaseNames = riskResult.getRiskDetails() == null ? List.of() |
102 | | - : riskResult.getRiskDetails().stream() |
103 | | - .map(RiskAnalysisResult.RiskDetail::getDiseaseName) |
104 | | - .toList(); |
105 | | - |
106 | | - List<LocationResponse> locations = locationRepository.findAllByMember(relative).stream() |
107 | | - .map(LocationResponse::from) |
108 | | - .toList(); |
109 | | - |
110 | | - List<AlertResponse> alerts = alertRepository.findAllByMemberOrderByAlertTimeAsc(relative).stream() |
111 | | - .map(AlertResponse::from) |
| 90 | + List<String> alertTimes = alertRepository.findAllByMemberOrderByAlertTimeAsc(relative).stream() |
| 91 | + .map(Alert::getAlertTime) |
112 | 92 | .toList(); |
113 | 93 |
|
114 | | - return FamilyMemberResponse.builder() |
| 94 | + return FamilyListResponse.builder() |
115 | 95 | .familyId(family.getFamilyId()) |
116 | | - .relativeId(relative.getMemberId()) |
117 | 96 | .name(relative.getName()) |
118 | | - .age(age) |
119 | | - .isAlertEnabled(family.isAlertEnabled()) |
120 | 97 | .healthConditionNames(conditionNames) |
121 | | - .isRisk(riskResult.isRisk()) |
122 | | - .causeDiseaseNames(causeDiseaseNames) |
123 | | - .locations(locations) |
124 | | - .alerts(alerts) |
| 98 | + .alertTimes(alertTimes) |
125 | 99 | .build(); |
126 | 100 | }).toList(); |
127 | 101 | } |
128 | 102 |
|
| 103 | + // 2-2. 가족 상세 조회 (위험도 + 지역 + 알림 시간 전부 포함) |
| 104 | + @Transactional(readOnly = true) |
| 105 | + public FamilyMemberResponse getFamilyDetail(Long familyId) { |
| 106 | + Member me = memberService.getCurrentMember(); |
| 107 | + Family family = familyRepository.findByFamilyIdAndUser(familyId, me) |
| 108 | + .orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND)); |
| 109 | + Member relative = family.getRelative(); |
| 110 | + |
| 111 | + int age = relative.getBirth() != null |
| 112 | + ? Period.between(relative.getBirth(), LocalDate.now()).getYears() |
| 113 | + : 0; |
| 114 | + |
| 115 | + List<String> conditionNames = relative.getHealthConditions().stream() |
| 116 | + .map(hc -> hc.getCondition().getConditionName()) |
| 117 | + .toList(); |
| 118 | + |
| 119 | + // 날씨 위험도 분석 (가족이 위치 미등록이거나 기상청 에러 시 방어) |
| 120 | + RiskAnalysisResult riskResult; |
| 121 | + try { |
| 122 | + riskResult = riskAnalysisService.analyzeRiskForMember(relative); |
| 123 | + } catch (Exception e) { |
| 124 | + riskResult = new RiskAnalysisResult(false, null); |
| 125 | + } |
| 126 | + |
| 127 | + List<String> causeDiseaseNames = riskResult.getRiskDetails() == null ? List.of() |
| 128 | + : riskResult.getRiskDetails().stream() |
| 129 | + .map(RiskAnalysisResult.RiskDetail::getDiseaseName) |
| 130 | + .toList(); |
| 131 | + |
| 132 | + List<LocationResponse> locations = locationRepository.findAllByMember(relative).stream() |
| 133 | + .map(LocationResponse::from) |
| 134 | + .toList(); |
| 135 | + |
| 136 | + List<AlertResponse> alerts = alertRepository.findAllByMemberOrderByAlertTimeAsc(relative).stream() |
| 137 | + .map(AlertResponse::from) |
| 138 | + .toList(); |
| 139 | + |
| 140 | + return FamilyMemberResponse.builder() |
| 141 | + .familyId(family.getFamilyId()) |
| 142 | + .relativeId(relative.getMemberId()) |
| 143 | + .name(relative.getName()) |
| 144 | + .age(age) |
| 145 | + .isAlertEnabled(family.isAlertEnabled()) |
| 146 | + .healthConditionNames(conditionNames) |
| 147 | + .isRisk(riskResult.isRisk()) |
| 148 | + .causeDiseaseNames(causeDiseaseNames) |
| 149 | + .locations(locations) |
| 150 | + .alerts(alerts) |
| 151 | + .build(); |
| 152 | + } |
| 153 | + |
129 | 154 | // 3. 가족 건강 상태(질환) 수정 (덮어쓰기) |
130 | 155 | @Transactional |
131 | 156 | public void updateFamilyConditions(Long familyId, UpdateConditionsRequest request) { |
|
0 commit comments