From 026fb075a98d93ad4ff1152f5fa1a39c0e2fefe9 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Fri, 1 Nov 2024 21:28:30 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20CCTV=20=EC=82=AD=EC=A0=9C=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=88=98=EC=A0=95=20(#63)=20(KAN-114)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cctv/service/CctvService.java | 28 +++++++++---------- .../device/repository/DeviceRepository.java | 2 +- .../repository/DeviceRepositoryImpl.java | 6 ++-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java b/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java index 03005cac..a0a6543a 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java @@ -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()); } } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/device/repository/DeviceRepository.java b/src/main/java/org/ioteatime/meonghanyangserver/device/repository/DeviceRepository.java index da9c3ece..0ae0ada6 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/device/repository/DeviceRepository.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/device/repository/DeviceRepository.java @@ -13,7 +13,7 @@ public interface DeviceRepository { GroupEntity findDevice(Long userId); - boolean isMasterUserId(Long userId); + boolean isParcitipantUserId(Long userId); void deleteById(Long id); diff --git a/src/main/java/org/ioteatime/meonghanyangserver/device/repository/DeviceRepositoryImpl.java b/src/main/java/org/ioteatime/meonghanyangserver/device/repository/DeviceRepositoryImpl.java index 01838786..5c7c3236 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/device/repository/DeviceRepositoryImpl.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/device/repository/DeviceRepositoryImpl.java @@ -42,8 +42,8 @@ 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( @@ -51,7 +51,7 @@ public boolean isMasterUserId(Long userId) { .user .id .eq(userId) - .and(deviceEntity.role.eq(DeviceRole.ROLE_MASTER))) + .and(deviceEntity.role.eq(DeviceRole.ROLE_PARTICIPANT))) .fetch() .isEmpty(); }