From 130e17ff024f6fd656e3876b11225307359a0208 Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Fri, 22 Mar 2024 05:31:02 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20=EB=82=B4=EA=B0=80=20=EC=86=8D=ED=95=9C?= =?UTF-8?q?=20=EB=AA=A8=EC=9E=84=20=EC=A1=B0=ED=9A=8C=20API,=20401=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/common/exception/NoContentException.java | 14 ++++++++++++++ .../crew/main/common/response/ErrorStatus.java | 5 +++++ .../crew/main/entity/user/UserRepository.java | 7 ++++++- .../meeting/v2/service/MeetingV2ServiceImpl.java | 7 +++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 main/src/main/java/org/sopt/makers/crew/main/common/exception/NoContentException.java diff --git a/main/src/main/java/org/sopt/makers/crew/main/common/exception/NoContentException.java b/main/src/main/java/org/sopt/makers/crew/main/common/exception/NoContentException.java new file mode 100644 index 00000000..6c204e4c --- /dev/null +++ b/main/src/main/java/org/sopt/makers/crew/main/common/exception/NoContentException.java @@ -0,0 +1,14 @@ +package org.sopt.makers.crew.main.common.exception; + +import org.springframework.http.HttpStatus; + +public class NoContentException extends BaseException { + + public NoContentException() { + super(HttpStatus.NO_CONTENT); + } + + public NoContentException(String message) { + super(HttpStatus.NO_CONTENT, message); + } +} diff --git a/main/src/main/java/org/sopt/makers/crew/main/common/response/ErrorStatus.java b/main/src/main/java/org/sopt/makers/crew/main/common/response/ErrorStatus.java index 72c32673..b7311d2f 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/common/response/ErrorStatus.java +++ b/main/src/main/java/org/sopt/makers/crew/main/common/response/ErrorStatus.java @@ -7,6 +7,11 @@ @Getter @RequiredArgsConstructor(access = AccessLevel.PROTECTED) public enum ErrorStatus { + /** + * 204 NO_CONTENT + */ + NO_CONTENT_EXCEPTION("참여한 모임이 없습니다."), + /** * 400 BAD_REQUEST */ diff --git a/main/src/main/java/org/sopt/makers/crew/main/entity/user/UserRepository.java b/main/src/main/java/org/sopt/makers/crew/main/entity/user/UserRepository.java index 0cdeabcb..b886075f 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/entity/user/UserRepository.java +++ b/main/src/main/java/org/sopt/makers/crew/main/entity/user/UserRepository.java @@ -1,6 +1,9 @@ package org.sopt.makers.crew.main.entity.user; +import static org.sopt.makers.crew.main.common.response.ErrorStatus.NO_CONTENT_EXCEPTION; + import java.util.Optional; +import org.sopt.makers.crew.main.common.exception.NoContentException; import org.sopt.makers.crew.main.common.exception.UnAuthorizedException; import org.springframework.data.jpa.repository.JpaRepository; @@ -13,6 +16,8 @@ default User findByIdOrThrow(Integer userId) { } default User findByOrgIdOrThrow(Integer orgUserId) { - return findByOrgId(orgUserId).orElseThrow(() -> new UnAuthorizedException()); + return findByOrgId(orgUserId).orElseThrow( + () -> new NoContentException( + NO_CONTENT_EXCEPTION.getErrorCode())); //유저가 아직 모임 서비스를 이용 전이기 때문에 } } diff --git a/main/src/main/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceImpl.java b/main/src/main/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceImpl.java index c545403d..de71c3bd 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceImpl.java +++ b/main/src/main/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceImpl.java @@ -1,5 +1,7 @@ package org.sopt.makers.crew.main.meeting.v2.service; +import static org.sopt.makers.crew.main.common.response.ErrorStatus.NO_CONTENT_EXCEPTION; + import java.time.LocalDateTime; import java.util.Comparator; import java.util.List; @@ -7,6 +9,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import lombok.RequiredArgsConstructor; +import org.sopt.makers.crew.main.common.exception.NoContentException; import org.sopt.makers.crew.main.common.pagination.dto.PageMetaDto; import org.sopt.makers.crew.main.common.pagination.dto.PageOptionsDto; import org.sopt.makers.crew.main.entity.apply.Apply; @@ -53,6 +56,10 @@ public MeetingV2GetAllMeetingByOrgUserDto getAllMeetingByOrgUser( .sorted(Comparator.comparing(MeetingV2GetAllMeetingByOrgUserMeetingDto::getId).reversed()) .collect(Collectors.toList()); + if (userJoinedList.isEmpty()) { + throw new NoContentException(NO_CONTENT_EXCEPTION.getErrorCode()); + } + List pagedUserJoinedList = userJoinedList.stream().skip((long) (page - 1) * take) // 스킵할 아이템 수 계산 .limit(take) // 페이지당 아이템 수 제한