Skip to content

Commit

Permalink
fix: CCTV 삭제 조건 수정 (#63) (KAN-114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywonchae1 committed Nov 1, 2024
1 parent 65df9ab commit 026fb07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,21 @@ public class CctvService {
@Transactional
public void deleteById(Long userId, Long cctvId) {
// Device 테이블에서 userId를 조회하여 role 을 확인
if (deviceRepository.isMasterUserId(userId)) {
// MASTER 이면 CCTV 삭제 가능
CctvWithDeviceId cctv =
cctvRepository
.findByIdWithDeviceId(cctvId)
.orElseThrow(() -> new NotFoundException(CctvErrorType.NOT_FOUND));
// 1. KVS 시그널링 채널 삭제
kvsClient.deleteSignalingChannel(cctv.kvsChannelName());
// 2. CCTV 테이블에서 삭제
cctvRepository.deleteById(cctvId);
System.out.println("HWEHREWR");
// 3. Device 테이블에서 삭제
deviceRepository.deleteById(cctv.deviceId());
} else {
if (deviceRepository.isParcitipantUserId(userId)) {
// PARTICIPANT 이면 CCTV 삭제 실패
throw new BadRequestException(CctvErrorType.ONLY_MASTER_CAN_DELETE);
}
// CCTV 인 경우는 현재 MASTER 인 경우와 동일하므로 처리하지 않음
// MASTER 이거나, CCTV(자기자신)이면 CCTV 퇴출(나가기) 가능
CctvWithDeviceId cctv =
cctvRepository
.findByIdWithDeviceId(cctvId)
.orElseThrow(() -> new NotFoundException(CctvErrorType.NOT_FOUND));
// 1. KVS 시그널링 채널 삭제
kvsClient.deleteSignalingChannel(cctv.kvsChannelName());
// 2. CCTV 테이블에서 삭제
cctvRepository.deleteById(cctvId);
System.out.println("HWEHREWR");
// 3. Device 테이블에서 삭제
deviceRepository.deleteById(cctv.deviceId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface DeviceRepository {

GroupEntity findDevice(Long userId);

boolean isMasterUserId(Long userId);
boolean isParcitipantUserId(Long userId);

void deleteById(Long id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public GroupEntity findDevice(Long userId) {
}

@Override
public boolean isMasterUserId(Long userId) {
return !jpaQueryFactory
public boolean isParcitipantUserId(Long userId) {
return jpaQueryFactory
.select(deviceEntity.role)
.from(deviceEntity)
.where(
deviceEntity
.user
.id
.eq(userId)
.and(deviceEntity.role.eq(DeviceRole.ROLE_MASTER)))
.and(deviceEntity.role.eq(DeviceRole.ROLE_PARTICIPANT)))
.fetch()
.isEmpty();
}
Expand Down

0 comments on commit 026fb07

Please sign in to comment.