11package kb_hack .backend .domain .sos .service ;
22
33import kb_hack .backend .domain .business .mapper .BusinessMapper ;
4+ import kb_hack .backend .domain .chat .mapper .ChatRoomMapper ;
45import kb_hack .backend .domain .sos .dto .SosCreateRequest ;
56import kb_hack .backend .domain .sos .dto .SosCreateResponse ;
67import 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
0 commit comments