Search in sources :

Example 1 with MemberNotFoundException

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);
}
Also used : StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) StudylogScrapAlreadyRegisteredException(wooteco.prolog.studylog.exception.StudylogScrapAlreadyRegisteredException) StudylogScrap(wooteco.prolog.studylog.domain.StudylogScrap) Member(wooteco.prolog.member.domain.Member) MemberNotFoundException(wooteco.prolog.member.exception.MemberNotFoundException) Studylog(wooteco.prolog.studylog.domain.Studylog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with MemberNotFoundException

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());
}
Also used : GithubApiFailException(wooteco.prolog.login.excetpion.GithubApiFailException) MemberNotFoundException(wooteco.prolog.member.exception.MemberNotFoundException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

MemberNotFoundException (wooteco.prolog.member.exception.MemberNotFoundException)2 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1 GithubApiFailException (wooteco.prolog.login.excetpion.GithubApiFailException)1 Member (wooteco.prolog.member.domain.Member)1 Studylog (wooteco.prolog.studylog.domain.Studylog)1 StudylogScrap (wooteco.prolog.studylog.domain.StudylogScrap)1 StudylogNotFoundException (wooteco.prolog.studylog.exception.StudylogNotFoundException)1 StudylogScrapAlreadyRegisteredException (wooteco.prolog.studylog.exception.StudylogScrapAlreadyRegisteredException)1