Skip to content

Commit 9ee00c1

Browse files
authored
Merge pull request #110 from prgrms-web-devcourse-final-project/feature/EA3-122-study-crud
[EA3-122] refactor: BusinessException 메서드 변경
2 parents 6571d4f + d3d577c commit 9ee00c1

File tree

9 files changed

+21
-21
lines changed

9 files changed

+21
-21
lines changed

src/main/java/grep/neogul_coder/domain/prtemplate/service/PrTemplateService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ public void deleteByUserId(Long userId) {
4040

4141
public void update(Long id, String location) {
4242
PrTemplate prTemplate = prTemplateRepository.findById(id).orElseThrow(
43-
() -> new NotFoundException(PrTemplateErrorCode.TEMPLATE_NOT_FOUND, "템플릿이 존재하지 않습니다."));
43+
() -> new NotFoundException(PrTemplateErrorCode.TEMPLATE_NOT_FOUND));
4444
prTemplate.update(location);
4545
}
4646

4747
public void updateIntroduction(Long id, String introduction) {
4848
PrTemplate prTemplate = prTemplateRepository.findById(id).orElseThrow(
49-
() -> new NotFoundException(PrTemplateErrorCode.TEMPLATE_NOT_FOUND, "템플릿이 존재하지 않습니다."));
49+
() -> new NotFoundException(PrTemplateErrorCode.TEMPLATE_NOT_FOUND));
5050
prTemplate.updateIntroduction(introduction);
5151
}
5252

5353
public PrPageResponse toResponse(Long userId) {
5454

5555
User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(
56-
UserErrorCode.USER_NOT_FOUND, "회원이 존재하지 않습니다."));
56+
UserErrorCode.USER_NOT_FOUND));
5757
PrTemplate prTemplate = prTemplateRepository.findByUserId(userId);
5858
List<Link> links = linkRepository.findAllByPrIdAndActivatedTrue(prTemplate.getId());
5959
List<ReviewEntity> reviews = reviewRepository.findAllByTargetUserId(userId);
@@ -94,7 +94,7 @@ public PrPageResponse toResponse(Long userId) {
9494
.limit(5)
9595
.map(review -> {
9696
User writer = userRepository.findById(review.getWriteUserId())
97-
.orElseThrow(() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND, "작성자를 찾을 수 없습니다."));
97+
.orElseThrow(() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND));
9898
return PrPageResponse.ReviewContentDto.builder()
9999
.reviewUserId(writer.getId())
100100
.reviewUserImgUrl(writer.getProfileImageUrl())

src/main/java/grep/neogul_coder/domain/recruitment/post/service/RecruitmentPostService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public void delete(long recruitmentPostId, long userId) {
5252

5353
private RecruitmentPost findRecruitmentPost(long recruitmentPostId, long userId) {
5454
RecruitmentPost recruitmentPost = recruitmentPostRepository.findById(recruitmentPostId)
55-
.orElseThrow(() -> new NotFoundException(NOT_FOUND, NOT_FOUND.getMessage()));
55+
.orElseThrow(() -> new NotFoundException(NOT_FOUND));
5656

5757
if (recruitmentPost.isNotOwnedBy(userId)) {
58-
throw new BusinessException(NOT_OWNER, NOT_OWNER.getMessage());
58+
throw new BusinessException(NOT_OWNER);
5959
}
6060
return recruitmentPost;
6161
}

src/main/java/grep/neogul_coder/domain/review/ReviewTags.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ReviewType ensureSingleReviewType() {
3030
.anyMatch(tag -> firstReviewType.isNotSameType(tag.getReviewType()));
3131

3232
if (hasNotSingleType) {
33-
throw new BusinessException(NOT_SINGLE_REVIEW_TYPE, NOT_SINGLE_REVIEW_TYPE.getMessage());
33+
throw new BusinessException(NOT_SINGLE_REVIEW_TYPE);
3434
}
3535
return firstReviewType;
3636
}

src/main/java/grep/neogul_coder/domain/review/service/ReviewService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public ReviewTargetUsersInfo getReviewTargetUsersInfo(long studyId, String myNic
5959
@Transactional
6060
public void save(ReviewSaveServiceRequest request, long writeUserId) {
6161
if(isAlreadyWrittenReviewBy(request.getStudyId(), request.getTargetUserId(), writeUserId)){
62-
throw new BusinessException(ALREADY_REVIEW_WRITE_USER, ALREADY_REVIEW_WRITE_USER.getMessage());
62+
throw new BusinessException(ALREADY_REVIEW_WRITE_USER);
6363
}
6464

6565
Study study = findValidStudy(request.getStudyId());
@@ -91,14 +91,14 @@ public ReviewContentsPagingInfo getMyReviewContents(Pageable pageable, long user
9191

9292
private Study findValidStudy(long studyId){
9393
return studyRepository.findById(studyId)
94-
.orElseThrow(() -> new NotFoundException(STUDY_NOT_FOUND, STUDY_NOT_FOUND.getMessage()));
94+
.orElseThrow(() -> new NotFoundException(STUDY_NOT_FOUND));
9595
}
9696

9797
private List<StudyMember> findValidStudyMember(long studyId) {
9898
List<StudyMember> studyMembers = studyMemberRepository.findByStudyIdFetchStudy(studyId);
9999

100100
if (studyMembers.isEmpty()) {
101-
throw new NotFoundException(STUDY_MEMBER_EMPTY, STUDY_MEMBER_EMPTY.getMessage());
101+
throw new NotFoundException(STUDY_MEMBER_EMPTY);
102102
}
103103
return studyMembers;
104104
}

src/main/java/grep/neogul_coder/domain/study/exception/NotStudyLeaderException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
public class NotStudyLeaderException extends BusinessException {
77

8-
public NotStudyLeaderException(ErrorCode errorCode, String message) {
9-
super(errorCode, message);
8+
public NotStudyLeaderException(ErrorCode errorCode) {
9+
super(errorCode);
1010
}
1111
}

src/main/java/grep/neogul_coder/domain/study/service/StudyService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public List<StudyItemResponse> getMyStudies(Long userId) {
3434

3535
public StudyHeaderResponse getStudyHeader(Long studyId) {
3636
Study study = studyRepository.findById(studyId)
37-
.orElseThrow(() -> new NotFoundException(STUDY_NOT_FOUND, STUDY_NOT_FOUND.getMessage()));
37+
.orElseThrow(() -> new NotFoundException(STUDY_NOT_FOUND));
3838

3939
return StudyHeaderResponse.from(study);
4040
}
@@ -49,11 +49,11 @@ public List<StudyImageResponse> getStudyImages(Long userId) {
4949

5050
public StudyInfoResponse getStudyInfo(Long studyId, Long userId) {
5151
Study study = studyRepository.findById(studyId)
52-
.orElseThrow(() -> new NotFoundException(STUDY_NOT_FOUND, STUDY_NOT_FOUND.getMessage()));
52+
.orElseThrow(() -> new NotFoundException(STUDY_NOT_FOUND));
5353

5454
StudyMemberRole role = studyQueryRepository.findMyRole(studyId, userId);
5555
if (!role.equals(LEADER)) {
56-
throw new NotStudyLeaderException(STUDY_NOT_LEADER, STUDY_NOT_FOUND.getMessage());
56+
throw new NotStudyLeaderException(STUDY_NOT_LEADER);
5757
}
5858

5959
List<StudyMemberResponse> members = studyQueryRepository.findStudyMembers(studyId);

src/main/java/grep/neogul_coder/domain/users/service/UserService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ public void deleteUser(Long id, String password) {
9595
private User findUser(Long id) {
9696
return userRepository.findById(id)
9797
.orElseThrow(
98-
() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND, "회원이 존재하지 않습니다."));
98+
() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND));
9999
}
100100

101101
private User findUser(String email) {
102102
return userRepository.findByEmail(email)
103103
.orElseThrow(
104-
() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND, "회원이 존재하지 않습니다."));
104+
() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND));
105105
}
106106

107107
private boolean duplicationCheck(String email, String nickname) {

src/main/java/grep/neogul_coder/global/exception/business/BusinessException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ public class BusinessException extends RuntimeException {
66

77
private ErrorCode errorCode;
88

9-
public BusinessException(ErrorCode errorCode, String message) {
10-
super(message);
9+
public BusinessException(ErrorCode errorCode) {
10+
super(errorCode.getMessage());
1111
this.errorCode = errorCode;
1212
}
1313

src/main/java/grep/neogul_coder/global/exception/business/NotFoundException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import grep.neogul_coder.global.response.code.ErrorCode;
44

55
public class NotFoundException extends BusinessException{
6-
public NotFoundException(ErrorCode errorcode, String message) {
7-
super(errorcode, message);
6+
public NotFoundException(ErrorCode errorcode) {
7+
super(errorcode);
88
}
99
}

0 commit comments

Comments
 (0)