Skip to content

Commit

Permalink
feat: 화상채팅 접속시 상대방 프로필 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
Ojimin committed Jun 11, 2024
1 parent c653bb5 commit c5cef24
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ public ResponseEntity<WebcamResponseDto.CreateWebcamDto> 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<WebcamResponseDto.GetRemoteMemberDto> getRemoteMember(@PathVariable(value = "webcamId") Long webcamId) {
WebcamResponseDto.GetRemoteMemberDto response = webcamServcie.getRemoteMemberId(webcamId);
return ResponseEntity.status(HttpStatus.OK).body(response);
}

/**
* offer 정보를 주고받기 - step 5에서 offer를 받고 구독하고 있는 client들에게 전송
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

public interface MemberWebcamRepository extends JpaRepository<MemberWebcam, Long> {
void deleteByWebcam(Webcam webcam);
List<Optional<MemberWebcam>> findByWebcam(Webcam webcam);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
public interface WebcamServcie {
WebcamResponseDto.CreateWebcamDto createWebcamRoom(WebcamRequestDto.CreateWebcamDto request);
void deleteWebcamRoom(WebcamRequestDto.DeleteWebcamDto request);
WebcamResponseDto.GetRemoteMemberDto getRemoteMemberId(Long webcamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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<Optional<MemberWebcam>> memberWebcams = memberWebcamRepository.findByWebcam(webcam);
Member remoteMember= null;
for (Optional<MemberWebcam> 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();
}
}

0 comments on commit c5cef24

Please sign in to comment.