GET /api/spots/{id}/mates?userId= 로 회원 소유 강아지를 제외.
본인 강아지가 메이트로 노출되던 혼란 해소.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -49,10 +49,11 @@ public class SpotController {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(body);
|
||||
}
|
||||
|
||||
/** 스팟에 현재 체크인 중인 메이트 목록 */
|
||||
/** 스팟에 현재 체크인 중인 메이트 목록 (userId 지정 시 본인 강아지 제외) */
|
||||
@GetMapping("/{id}/mates")
|
||||
public List<MateResponse> mates(@PathVariable Long id) {
|
||||
return spotService.activeMates(id).stream().map(MateResponse::from).toList();
|
||||
public List<MateResponse> mates(@PathVariable Long id,
|
||||
@RequestParam(required = false) Long userId) {
|
||||
return spotService.activeMates(id, userId).stream().map(MateResponse::from).toList();
|
||||
}
|
||||
|
||||
/** AI 궁합 메이트 추천 — 내 강아지(dogId)와 사이좋게 지낼 만한 스팟 내 강아지 목록 */
|
||||
|
||||
@@ -58,9 +58,12 @@ public class SpotService {
|
||||
return saved;
|
||||
}
|
||||
|
||||
/** 스팟에 현재 체크인 중인 강아지(메이트) 목록 — 최근 24시간(Redis), 최신순. */
|
||||
/**
|
||||
* 스팟에 현재 체크인 중인 강아지(메이트) 목록 — 최근 24시간(Redis), 최신순.
|
||||
* excludeUserId 가 주어지면 해당 회원 소유 강아지(=본인 강아지)는 제외한다.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public List<Dog> activeMates(Long spotId) {
|
||||
public List<Dog> activeMates(Long spotId, Long excludeUserId) {
|
||||
List<Long> dogIds = checkInRedisStore.activeDogIds(spotId);
|
||||
if (dogIds.isEmpty()) {
|
||||
return List.of();
|
||||
@@ -68,7 +71,11 @@ public class SpotService {
|
||||
// Redis 최신순 유지 — findAllById 는 순서를 보장하지 않으므로 매핑 후 재정렬.
|
||||
Map<Long, Dog> byId = dogRepository.findAllById(dogIds).stream()
|
||||
.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)
|
||||
|
||||
Reference in New Issue
Block a user