Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#50 [REFACTOR] Project 관련 response 리팩토링 #51

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public ProjectVerifyResponseDto verifyProjectCode(String invitationCode) {
@Transactional
public List<ProjectResponseDto> getProjectAll(Long memberId) {
List<UserProject> userProjects = userProjectRepository.findAllByMemberIdOrderByCreatedAtDesc(memberId);

if (userProjects.isEmpty()) {
throw new NotFoundException(ErrorStatus.NOT_FOUND_USER_PROJECT.getMessage());
}

return userProjects.stream()
.flatMap(userProject -> projectRepository.findAllById(userProject.getProject().getId()).stream())
.map(project -> ProjectResponseDto.of(project))
Expand All @@ -70,6 +75,10 @@ public ProjectOwnPuzzleResponseDto getMyPuzzles(Long memberId, Long projectId, S
Page<Review> pageReviews = reviewRepository.findTop15ByMemberIdAndProjectId(memberId, projectId, pageable);
List<Review> top15Reviews = pageReviews.getContent();

if (top15Reviews.isEmpty()) {
throw new NotFoundException(ErrorStatus.NOT_FOUND_USER_PROJECT.getMessage());
}

Boolean isReviewDay = checkTodayIsReviewDay(today, findProjectById(projectId).getReviewCycle());
Boolean hasTodayReview = reviewRepository.existsReviewByReviewDate(today);

Expand Down Expand Up @@ -223,7 +232,7 @@ private String getReviewMemberPercent(Long projectId, int reviewCount) {

private Member findMemberById(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new BadRequestException(ErrorStatus.INVALID_MEMBER.getMessage()));
.orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_MEMBER.getMessage()));
}

private Project findProjectById(Long projectId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public enum ErrorStatus {
VALIDATION_REQUEST_MISSING_EXCEPTION("요청값이 입력되지 않았습니다."),
VALIDATION_NAMING_EXCEPTION("이모지 및 특수기호 입력은 불가능합니다. 제외하여 입력해 주세요."),
NO_TOKEN("토큰을 넣어주세요."),
INVALID_MEMBER("유효하지 않은 유저입니다."),
ANOTHER_ACCESS_TOKEN("지원하지 않는 소셜 플랫폼입니다."),
VALIDATION_PATH_MISSING_EXCEPTION("요청하는 path에 넘겨주는 variable이 입력되지 않았습니다."),

/**
* 401 UNAUTHORIZED
*/
UNAUTHORIZED_TOKEN("유효하지 않은 토큰입니다."),
INVALID_MEMBER("유효하지 않은 유저입니다."),
KAKAO_UNAUTHORIZED_USER("카카오 로그인 실패. 만료되었거나 잘못된 카카오 토큰입니다."),
SIGNIN_REQUIRED("access, refreshToken 모두 만료되었습니다. 재로그인이 필요합니다."),
VALID_ACCESS_TOKEN("아직 유효한 accessToken 입니다."),
Expand All @@ -32,6 +32,8 @@ public enum ErrorStatus {
*/
NOT_FOUND_PROJECT_CODE("유효하지 않은 초대코드에요. 코드를 확인해 주세요."),
NOT_FOUND_PROJECT("해당하는 프로젝트가 없습니다"),
NOT_FOUND_MEMBER("해당하는 유저가 없습니다."),
NOT_FOUND_USER_PROJECT("해당하는 멤버가 참여하는 프로젝트가 아닙니다."),


/**
Expand Down
Loading