diff --git a/src/main/java/vom/spring/domain/webcam/controller/WebcamController.java b/src/main/java/vom/spring/domain/webcam/controller/WebcamController.java index 801b665..02a5f69 100644 --- a/src/main/java/vom/spring/domain/webcam/controller/WebcamController.java +++ b/src/main/java/vom/spring/domain/webcam/controller/WebcamController.java @@ -45,6 +45,24 @@ public ResponseEntity createWebcamRoom(@Reque WebcamResponseDto.CreateWebcamDto response = webcamServcie.createWebcamRoom(request); return ResponseEntity.status(HttpStatus.OK).body(response); } + + /** + * 방 입장 후 상대방 memberId 받기 + */ + @Operation(summary = "화상채팅 상대방 정보를 조회합니다", description = "상대방의 memberId를 조회합니다", + responses = { + @ApiResponse(responseCode = "200", description = "화상채팅 방을 생성했습니다."), + @ApiResponse(responseCode = "400", description = "채팅 방을 생성하지 못했습니다.", + content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "409", description = "올바르지 않은 닉네임, 올바르지 않은 이메일", + content = @Content(schema = @Schema(implementation = ErrorResponse.class))) + }) + @GetMapping("/api/webcam/{webcamId}/remote") + public ResponseEntity getRemoteMember(@PathVariable(value = "webcamId") Long webcamId) { + WebcamResponseDto.GetRemoteMemberDto response = webcamServcie.getRemoteMemberId(webcamId); + return ResponseEntity.status(HttpStatus.OK).body(response); + } + /** * offer 정보를 주고받기 - step 5에서 offer를 받고 구독하고 있는 client들에게 전송 */ diff --git a/src/main/java/vom/spring/domain/webcam/dto/WebcamResponseDto.java b/src/main/java/vom/spring/domain/webcam/dto/WebcamResponseDto.java index 6e51ddd..57560a8 100644 --- a/src/main/java/vom/spring/domain/webcam/dto/WebcamResponseDto.java +++ b/src/main/java/vom/spring/domain/webcam/dto/WebcamResponseDto.java @@ -10,4 +10,12 @@ public class WebcamResponseDto { public static class CreateWebcamDto { private Long webcamId; //화상채팅 방생성 id } + + @Builder + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static class GetRemoteMemberDto { + private Long memberId; + } } diff --git a/src/main/java/vom/spring/domain/webcam/repository/MemberWebcamRepository.java b/src/main/java/vom/spring/domain/webcam/repository/MemberWebcamRepository.java index a0844e9..0f14617 100644 --- a/src/main/java/vom/spring/domain/webcam/repository/MemberWebcamRepository.java +++ b/src/main/java/vom/spring/domain/webcam/repository/MemberWebcamRepository.java @@ -9,4 +9,5 @@ public interface MemberWebcamRepository extends JpaRepository { void deleteByWebcam(Webcam webcam); + List> findByWebcam(Webcam webcam); } diff --git a/src/main/java/vom/spring/domain/webcam/service/WebcamServcie.java b/src/main/java/vom/spring/domain/webcam/service/WebcamServcie.java index a72aa22..f2bcc1f 100644 --- a/src/main/java/vom/spring/domain/webcam/service/WebcamServcie.java +++ b/src/main/java/vom/spring/domain/webcam/service/WebcamServcie.java @@ -6,4 +6,5 @@ public interface WebcamServcie { WebcamResponseDto.CreateWebcamDto createWebcamRoom(WebcamRequestDto.CreateWebcamDto request); void deleteWebcamRoom(WebcamRequestDto.DeleteWebcamDto request); + WebcamResponseDto.GetRemoteMemberDto getRemoteMemberId(Long webcamId); } diff --git a/src/main/java/vom/spring/domain/webcam/service/WebcamServiceImpl.java b/src/main/java/vom/spring/domain/webcam/service/WebcamServiceImpl.java index f8ba1d8..dfc031e 100644 --- a/src/main/java/vom/spring/domain/webcam/service/WebcamServiceImpl.java +++ b/src/main/java/vom/spring/domain/webcam/service/WebcamServiceImpl.java @@ -15,6 +15,8 @@ import vom.spring.domain.webcam.repository.WebcamRepository; import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -43,6 +45,9 @@ public WebcamResponseDto.CreateWebcamDto createWebcamRoom(WebcamRequestDto.Creat return WebcamResponseDto.CreateWebcamDto.builder().webcamId(newWebcam.getId()).build(); } + /** + * 화상채팅 방 삭제 + */ @Transactional @Override public void deleteWebcamRoom(WebcamRequestDto.DeleteWebcamDto request) { @@ -55,4 +60,25 @@ public void deleteWebcamRoom(WebcamRequestDto.DeleteWebcamDto request) { //해당 방 삭제 webcamRepository.deleteById(webcam.getId()); } + + /** + * 상대방 정보 조회 + */ + @Override + public WebcamResponseDto.GetRemoteMemberDto getRemoteMemberId(Long webcamId) { + String email = SecurityContextHolder.getContext().getAuthentication().getName(); //현재 접속 유저 정보 가져오기 + Member currentMember = memberRepository.findByEmail(email).orElseThrow(() -> new RuntimeException("존재하지 않은 유저입니다")); + Webcam webcam = webcamRepository.findById(webcamId).orElseThrow(() -> new IllegalArgumentException("존재하지 않은 webcam 입니다")); + List> memberWebcams = memberWebcamRepository.findByWebcam(webcam); + Member remoteMember= null; + for (Optional memberWebcam : memberWebcams) { + if (memberWebcam.get().getMember() != currentMember) { + remoteMember = memberWebcam.get().getMember(); + } + } + if (remoteMember == null){ + throw new IllegalArgumentException("존재하지 않은 유저입니다"); + } + return WebcamResponseDto.GetRemoteMemberDto.builder().memberId(remoteMember.getId()).build(); + } }