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) // 페이지당 아이템 수 제한