Skip to content

Commit

Permalink
[FIX] 내가 속한 모임 조회 API, 401 에러 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Mar 22, 2024
1 parent 0c21790 commit 130e17f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
@Getter
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public enum ErrorStatus {
/**
* 204 NO_CONTENT
*/
NO_CONTENT_EXCEPTION("참여한 모임이 없습니다."),

/**
* 400 BAD_REQUEST
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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())); //유저가 아직 모임 서비스를 이용 전이기 때문에
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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;
import java.util.Optional;
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;
Expand Down Expand Up @@ -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<MeetingV2GetAllMeetingByOrgUserMeetingDto> pagedUserJoinedList =
userJoinedList.stream().skip((long) (page - 1) * take) // 스킵할 아이템 수 계산
.limit(take) // 페이지당 아이템 수 제한
Expand Down

0 comments on commit 130e17f

Please sign in to comment.