feat: 산책 메이트 목록에서 본인 강아지 제외
CI / build (push) Failing after 12m12s

GET /api/spots/{id}/mates?userId= 로 회원 소유 강아지를 제외.
본인 강아지가 메이트로 노출되던 혼란 해소.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
sb
2026-07-11 13:58:30 +09:00
parent 00af95bf6e
commit ea61eaf47e
2 changed files with 14 additions and 6 deletions
@@ -49,10 +49,11 @@ public class SpotController {
return ResponseEntity.status(HttpStatus.CREATED).body(body); return ResponseEntity.status(HttpStatus.CREATED).body(body);
} }
/** 스팟에 현재 체크인 중인 메이트 목록 */ /** 스팟에 현재 체크인 중인 메이트 목록 (userId 지정 시 본인 강아지 제외) */
@GetMapping("/{id}/mates") @GetMapping("/{id}/mates")
public List<MateResponse> mates(@PathVariable Long id) { public List<MateResponse> mates(@PathVariable Long id,
return spotService.activeMates(id).stream().map(MateResponse::from).toList(); @RequestParam(required = false) Long userId) {
return spotService.activeMates(id, userId).stream().map(MateResponse::from).toList();
} }
/** AI 궁합 메이트 추천 — 내 강아지(dogId)와 사이좋게 지낼 만한 스팟 내 강아지 목록 */ /** AI 궁합 메이트 추천 — 내 강아지(dogId)와 사이좋게 지낼 만한 스팟 내 강아지 목록 */
@@ -58,9 +58,12 @@ public class SpotService {
return saved; return saved;
} }
/** 스팟에 현재 체크인 중인 강아지(메이트) 목록 — 최근 24시간(Redis), 최신순. */ /**
* 스팟에 현재 체크인 중인 강아지(메이트) 목록 — 최근 24시간(Redis), 최신순.
* excludeUserId 가 주어지면 해당 회원 소유 강아지(=본인 강아지)는 제외한다.
*/
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<Dog> activeMates(Long spotId) { public List<Dog> activeMates(Long spotId, Long excludeUserId) {
List<Long> dogIds = checkInRedisStore.activeDogIds(spotId); List<Long> dogIds = checkInRedisStore.activeDogIds(spotId);
if (dogIds.isEmpty()) { if (dogIds.isEmpty()) {
return List.of(); return List.of();
@@ -68,7 +71,11 @@ public class SpotService {
// Redis 최신순 유지 — findAllById 는 순서를 보장하지 않으므로 매핑 후 재정렬. // Redis 최신순 유지 — findAllById 는 순서를 보장하지 않으므로 매핑 후 재정렬.
Map<Long, Dog> byId = dogRepository.findAllById(dogIds).stream() Map<Long, Dog> byId = dogRepository.findAllById(dogIds).stream()
.collect(Collectors.toMap(Dog::getId, Function.identity())); .collect(Collectors.toMap(Dog::getId, Function.identity()));
return dogIds.stream().map(byId::get).filter(Objects::nonNull).toList(); return dogIds.stream()
.map(byId::get)
.filter(Objects::nonNull)
.filter(d -> excludeUserId == null || !excludeUserId.equals(d.getUserId()))
.toList();
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)