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));
}
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);
}
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);
}
}
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();
}
Aggregations