Search in sources :

Example 1 with StudylogRead

use of wooteco.prolog.studylog.domain.StudylogRead in project prolog by woowacourse.

the class StudylogService method insertStudylogRead.

private void insertStudylogRead(Long id, Long memberId) {
    Member readMember = memberService.findById(memberId);
    Studylog readStudylog = studylogRepository.findById(id).orElseThrow(StudylogNotFoundException::new);
    studylogReadRepository.save(new StudylogRead(readMember, readStudylog));
}
Also used : StudylogRead(wooteco.prolog.studylog.domain.StudylogRead) StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) LoginMember(wooteco.prolog.login.ui.LoginMember) Member(wooteco.prolog.member.domain.Member) Studylog(wooteco.prolog.studylog.domain.Studylog)

Example 2 with StudylogRead

use of wooteco.prolog.studylog.domain.StudylogRead in project prolog by woowacourse.

the class StudylogReadRepositoryTest method findByMemberId.

@DisplayName("멤버 아이디로 조회한 글목록을 가져온다.")
@Test
void findByMemberId() {
    // given
    StudylogRead studylogRead = new StudylogRead(bada, studylog);
    studylogReadRepository.save(studylogRead);
    List<StudylogRead> expected = Collections.singletonList(studylogRead);
    // when
    List<StudylogRead> actual = studylogReadRepository.findByMemberId(bada.getId());
    // then
    assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
}
Also used : StudylogRead(wooteco.prolog.studylog.domain.StudylogRead) Test(org.junit.jupiter.api.Test) RepositoryTest(wooteco.support.utils.RepositoryTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with StudylogRead

use of wooteco.prolog.studylog.domain.StudylogRead in project prolog by woowacourse.

the class StudylogService method checkScrapedOrRead.

private void checkScrapedOrRead(Long memberId, Long studylogId) {
    if (studylogScrapRepository.existsByMemberIdAndStudylogId(memberId, studylogId)) {
        StudylogScrap studylogScrap = studylogScrapRepository.findByMemberIdAndStudylogId(memberId, studylogId).orElseThrow(StudylogScrapNotExistException::new);
        studylogScrapRepository.delete(studylogScrap);
    }
    if (studylogReadRepository.existsByMemberIdAndStudylogId(memberId, studylogId)) {
        StudylogRead studylogRead = studylogReadRepository.findByMemberIdAndStudylogId(memberId, studylogId).orElseThrow(StudylogReadNotExistException::new);
        studylogReadRepository.delete(studylogRead);
    }
}
Also used : StudylogRead(wooteco.prolog.studylog.domain.StudylogRead) StudylogScrapNotExistException(wooteco.prolog.studylog.exception.StudylogScrapNotExistException) StudylogScrap(wooteco.prolog.studylog.domain.StudylogScrap) StudylogReadNotExistException(wooteco.prolog.studylog.exception.StudylogReadNotExistException)

Example 4 with StudylogRead

use of wooteco.prolog.studylog.domain.StudylogRead in project prolog by woowacourse.

the class StudylogReadRepositoryTest method existsByMemberIdAndStudylogId.

@DisplayName("멤버 아이디와 스터디로그 아이디로 조회한 적이 있다면 true, 없다면 false를 반환한다.")
@Test
void existsByMemberIdAndStudylogId() {
    // given
    StudylogRead studylogRead = new StudylogRead(bada, studylog);
    // when
    studylogReadRepository.save(studylogRead);
    boolean expectTrue = studylogReadRepository.existsByMemberIdAndStudylogId(bada.getId(), studylog.getId());
    boolean expectFalse = studylogReadRepository.existsByMemberIdAndStudylogId(member.getId(), studylog.getId());
    // then
    assertThat(expectTrue).isTrue();
    assertThat(expectFalse).isFalse();
}
Also used : StudylogRead(wooteco.prolog.studylog.domain.StudylogRead) Test(org.junit.jupiter.api.Test) RepositoryTest(wooteco.support.utils.RepositoryTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

StudylogRead (wooteco.prolog.studylog.domain.StudylogRead)4 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 RepositoryTest (wooteco.support.utils.RepositoryTest)2 LoginMember (wooteco.prolog.login.ui.LoginMember)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 StudylogReadNotExistException (wooteco.prolog.studylog.exception.StudylogReadNotExistException)1 StudylogScrapNotExistException (wooteco.prolog.studylog.exception.StudylogScrapNotExistException)1