Skip to content

Commit

Permalink
Merge pull request #51 from Team-Puzzling/refactor/#50-project-api
Browse files Browse the repository at this point in the history
#50 [REFACTOR] Project 관련 API 리팩토링
  • Loading branch information
yeseul106 authored Jul 18, 2023
2 parents 2d2fef9 + 50bd32b commit 3e8b6be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 3e8b6be

Please sign in to comment.