use of wooteco.prolog.member.exception.MemberNotFoundException in project prolog by woowacourse.
the class StudylogScrapService method registerScrap.
@Transactional
public MemberScrapResponse registerScrap(Long memberId, Long studylogId) {
if (studylogScrapRepository.countByMemberIdAndScrapStudylogId(memberId, studylogId) > 0) {
throw new StudylogScrapAlreadyRegisteredException();
}
Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
Member member = memberRepository.findById(memberId).orElseThrow(MemberNotFoundException::new);
StudylogScrap studylogScrap = new StudylogScrap(member, studylog);
studylogScrapRepository.save(studylogScrap);
return MemberScrapResponse.of(studylogScrap);
}
use of wooteco.prolog.member.exception.MemberNotFoundException in project prolog by woowacourse.
the class BadRequestCodeTest method findByTest.
@DisplayName("예외 코드와 메시지가 잘 바인딩되는지 확인한다.")
@Test
void findByTest() {
// given
MemberNotFoundException memberNotFoundException = new MemberNotFoundException();
GithubApiFailException githubApiFailException = new GithubApiFailException();
// when
int githubApiFailExceptionCode = githubApiFailException.getCode();
String githubApiFailExceptionMessage = githubApiFailException.getMessage();
int memberNotFoundExceptionCode = memberNotFoundException.getCode();
String memberNotFoundExceptionMessage = memberNotFoundException.getMessage();
// then
assertThat(githubApiFailExceptionCode).isEqualTo(BadRequestCode.GITHUB_API_FAIL.getCode());
assertThat(githubApiFailExceptionMessage).isEqualTo(BadRequestCode.GITHUB_API_FAIL.getMessage());
assertThat(memberNotFoundExceptionCode).isEqualTo(BadRequestCode.MEMBER_NOT_FOUND.getCode());
assertThat(memberNotFoundExceptionMessage).isEqualTo(BadRequestCode.MEMBER_NOT_FOUND.getMessage());
}
Aggregations