Skip to content

Commit 7f43e38

Browse files
authored
Merge pull request #132 from KB-Hackerton/feature/49
Feature/49
2 parents 5d249e7 + 5009b80 commit 7f43e38

7 files changed

Lines changed: 39 additions & 18 deletions

File tree

.DS_Store

8 KB
Binary file not shown.

.github/.DS_Store

6 KB
Binary file not shown.

src/.DS_Store

6 KB
Binary file not shown.

src/main/java/kb_hack/backend/domain/chat/mapper/ChatRoomMapper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,11 @@ SELECT MAX(chat_message_id)
6161

6262
Optional<ChatRoomDetailQueryResult> findChatRoomDetail(Long roomId, Long memberId);
6363

64+
@Select("""
65+
SELECT COUNT(*)
66+
FROM chat_room
67+
WHERE sos_id = #{sosId}
68+
""")
69+
int countChatRoomsBySosId(Long sosId);
70+
6471
}

src/main/java/kb_hack/backend/domain/sos/dto/SosDetailResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public class SosDetailResponse {
5555

5656
private List<Long> imageIds;
5757

58+
private int chatRoomCount;
59+
5860

5961

6062
}

src/main/java/kb_hack/backend/domain/sos/service/SosServiceImpl.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package kb_hack.backend.domain.sos.service;
22

33
import kb_hack.backend.domain.business.mapper.BusinessMapper;
4+
import kb_hack.backend.domain.chat.mapper.ChatRoomMapper;
45
import kb_hack.backend.domain.sos.dto.SosCreateRequest;
56
import kb_hack.backend.domain.sos.dto.SosCreateResponse;
67
import kb_hack.backend.domain.sos.dto.SosDetailResponse;
@@ -36,6 +37,7 @@ public class SosServiceImpl implements SosService {
3637
private final SosImageMapper sosImageMapper;
3738
private final StorageService storageService;
3839
private final BusinessMapper businessMapper;
40+
private final ChatRoomMapper chatRoomMapper;
3941

4042
// 지원하는 날짜 포맷
4143
private static final List<DateTimeFormatter> EXPIRES_FORMATS = List.of(
@@ -168,6 +170,7 @@ public SosDetailResponse getSosDetail(Long sosId) {
168170
if (rows.isEmpty()) {
169171
throw new IllegalArgumentException("존재하지 않는 SOS ID: " + sosId);
170172
}
173+
171174
List<Long> imageIds = rows.stream()
172175
.map(SosDetailRow::getSosImageId)
173176
.filter(Objects::nonNull)
@@ -176,28 +179,30 @@ public SosDetailResponse getSosDetail(Long sosId) {
176179
SosDetailRow first = rows.get(0);
177180
List<String> imageKeys = rows.stream()
178181
.map(SosDetailRow::getImageKey)
179-
.filter(k -> k != null)
182+
.filter(Objects::nonNull)
180183
.toList();
181184

182185
String minorName = businessMapper.findMinorNameByBusinessId(first.getBusinessId());
183186

184-
SosDetailResponse result = SosDetailResponse.builder()
185-
.sosId(first.getSosId())
186-
.businessName(first.getBusinessName())
187-
.badge(first.getBadge())
188-
.businessAddr(first.getBusinessAddr())
189-
.businessAddrDetail(first.getBusinessAddrDetail())
190-
.sosTitle(first.getSosTitle())
191-
.sosType(first.getSosType())
192-
.sosContent(first.getSosContent())
193-
.expiresAt(first.getExpiresAt())
194-
.createdAt(first.getCreatedAt())
195-
.imageKeys(imageKeys)
196-
.imageIds(imageIds)
197-
.minorName(minorName)
198-
.build();
199-
200-
return result;
187+
// 🔥 sosId로 채팅방 개수 조회
188+
int chatRoomCount = chatRoomMapper.countChatRoomsBySosId(sosId);
189+
190+
return SosDetailResponse.builder()
191+
.sosId(first.getSosId())
192+
.businessName(first.getBusinessName())
193+
.badge(first.getBadge())
194+
.businessAddr(first.getBusinessAddr())
195+
.businessAddrDetail(first.getBusinessAddrDetail())
196+
.sosTitle(first.getSosTitle())
197+
.sosType(first.getSosType())
198+
.sosContent(first.getSosContent())
199+
.expiresAt(first.getExpiresAt())
200+
.createdAt(first.getCreatedAt())
201+
.imageKeys(imageKeys)
202+
.imageIds(imageIds)
203+
.minorName(minorName)
204+
.chatRoomCount(chatRoomCount) // ✅ 추가됨
205+
.build();
201206
}
202207

203208

src/main/resources/kb_hack/backend/domain/chat/mapper/ChatRoomMapper.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,12 @@
157157
WHERE
158158
cr.chat_room_id = #{roomId};
159159
</select>
160+
161+
162+
<!-- <select id="countChatRoomsBySosId" resultType="int">-->
163+
<!-- SELECT COUNT(*)-->
164+
<!-- FROM chat_room-->
165+
<!-- WHERE sos_id = #{sosId}-->
166+
<!-- </select>-->
160167
</mapper>
161168

0 commit comments

Comments
 (0)