From 2c4598242999d88603a04e9075ca5741c54d4bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cadashkdy9960?= <â€vjftmxmwlwhs@gmail.com> Date: Wed, 31 Jan 2024 18:42:44 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor=20:=20Hive=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=ED=83=88=ED=87=B4=EC=8B=9C=20=ED=98=B8=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=8A=94=20=ED=83=88=ED=87=B4=EB=B6=88=EA=B0=80=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/HHive/hhive/domain/hive/entity/Hive.java | 5 ----- .../com/HHive/hhive/domain/hive/service/HiveService.java | 5 +++++ .../HHive/hhive/global/exception/common/ErrorCode.java | 1 + .../exception/hive/HostNotResignHiveException.java | 9 +++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/HHive/hhive/global/exception/hive/HostNotResignHiveException.java diff --git a/src/main/java/com/HHive/hhive/domain/hive/entity/Hive.java b/src/main/java/com/HHive/hhive/domain/hive/entity/Hive.java index e24f984..425ddef 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/entity/Hive.java +++ b/src/main/java/com/HHive/hhive/domain/hive/entity/Hive.java @@ -59,11 +59,6 @@ public class Hive extends BaseTimeEntity { @JoinColumn(name = "user_id") private User user; -// @ManyToOne -// @JoinColumn(name = "category_id") -// private Category category; - - public void updateHiveTitle(UpdateHiveTitleRequestDTO updateHiveTitleRequestDTO) { if (updateHiveTitleRequestDTO.getTitle() != null) { this.title = updateHiveTitleRequestDTO.getTitle(); diff --git a/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java b/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java index fe431bf..99acd06 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java +++ b/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java @@ -16,6 +16,7 @@ import com.HHive.hhive.domain.user.repository.UserRepository; import com.HHive.hhive.domain.user.service.UserService; import com.HHive.hhive.global.exception.hive.AlreadyExistHiveException; +import com.HHive.hhive.global.exception.hive.HostNotResignHiveException; import com.HHive.hhive.global.exception.hive.NotFoundHiveException; import com.HHive.hhive.global.exception.user.AlreadyExistEmailException; import com.HHive.hhive.global.exception.user.NotFoundUserException; @@ -129,6 +130,10 @@ public void deleteHiveUser(User user, Long hiveId, String username) { Hive hive = getHiveAndCheckAuth(user, hiveId); User hiveUser = userService.findUserByUsername(username); + if (user.getId().equals(hive.getId())) { + throw new HostNotResignHiveException(); + } + if (!hiveUserService.isExistedUser(hiveUser, hive)) { throw new NotFoundUserException(); } diff --git a/src/main/java/com/HHive/hhive/global/exception/common/ErrorCode.java b/src/main/java/com/HHive/hhive/global/exception/common/ErrorCode.java index cc32ee3..7a19baa 100644 --- a/src/main/java/com/HHive/hhive/global/exception/common/ErrorCode.java +++ b/src/main/java/com/HHive/hhive/global/exception/common/ErrorCode.java @@ -25,6 +25,7 @@ public enum ErrorCode { ALREADY_EXIST_HIVE_EXCEPTION(401, "중복된 타이틀입니다."), FORBIDDEN_ABOUT_HIVE_EXCEPTION(403, "해당 하이브에 대한 권한이 없습니다."), NOT_FOUND_HIVE_EXCEPTION(404, "해당 하이브를 찾을 수 없습니다."), + HIVE_HOST_NOT_RESIGN_EXCEPTION(403,"호스트는 하이브 탈퇴가 불가능합니다."), //Party PARTY_NOT_FOUND_EXCEPTION(404, "해당 파티를 찾을 수 없습니다."), diff --git a/src/main/java/com/HHive/hhive/global/exception/hive/HostNotResignHiveException.java b/src/main/java/com/HHive/hhive/global/exception/hive/HostNotResignHiveException.java new file mode 100644 index 0000000..432e63d --- /dev/null +++ b/src/main/java/com/HHive/hhive/global/exception/hive/HostNotResignHiveException.java @@ -0,0 +1,9 @@ +package com.HHive.hhive.global.exception.hive; + +import com.HHive.hhive.global.exception.common.CustomException; +import com.HHive.hhive.global.exception.common.ErrorCode; + +public class HostNotResignHiveException extends CustomException { + + public HostNotResignHiveException() { super(ErrorCode.HIVE_HOST_NOT_RESIGN_EXCEPTION);} +} From 19ecd2e007c6ecf259be899e12dc018ed0da2cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cadashkdy9960?= <â€vjftmxmwlwhs@gmail.com> Date: Wed, 31 Jan 2024 19:09:29 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor=20:=20Hive=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=ED=83=88=ED=87=B4=EC=8B=9C=20=ED=98=B8=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=8A=94=20=ED=83=88=ED=87=B4=EB=B6=88=EA=B0=80=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/HHive/hhive/domain/hive/service/HiveService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java b/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java index 99acd06..4159b46 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java +++ b/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java @@ -130,7 +130,7 @@ public void deleteHiveUser(User user, Long hiveId, String username) { Hive hive = getHiveAndCheckAuth(user, hiveId); User hiveUser = userService.findUserByUsername(username); - if (user.getId().equals(hive.getId())) { + if (user.getId().equals(hive.getCreatorId())) { throw new HostNotResignHiveException(); }