use of wooteco.prolog.studylog.domain.StudylogScrap 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.studylog.domain.StudylogScrap in project prolog by woowacourse.
the class StudylogScrapRepositoryTest method countMemberScrapTest.
@DisplayName("count기능을 테스트한다.")
@Test
void countMemberScrapTest() {
// given
StudylogScrap studylogScrap = new StudylogScrap(member, studylog);
// when
int countBefore = studylogScrapRepository.countByMemberIdAndScrapStudylogId(member.getId(), studylog.getId());
studylogScrapRepository.save(studylogScrap);
int countAfter = studylogScrapRepository.countByMemberIdAndScrapStudylogId(member.getId(), studylog.getId());
// then
assertThat(countBefore).isEqualTo(0);
assertThat(countAfter).isEqualTo(1);
}
use of wooteco.prolog.studylog.domain.StudylogScrap in project prolog by woowacourse.
the class StudylogScrapService method unregisterScrap.
@Transactional
public void unregisterScrap(Long memberId, Long studylogId) {
StudylogScrap scrap = studylogScrapRepository.findByMemberIdAndStudylogId(memberId, studylogId).orElseThrow(StudylogScrapNotExistException::new);
studylogScrapRepository.delete(scrap);
}
use of wooteco.prolog.studylog.domain.StudylogScrap 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.StudylogScrap in project prolog by woowacourse.
the class StudylogScrapRepositoryTest method findByMemberIdAndStudylogIdTest.
@DisplayName("멤버 아이디와 스터디로그 아이디로 찾아오기 기능을 테스트한다.")
@Test
void findByMemberIdAndStudylogIdTest() {
// given
StudylogScrap expectedStudylogScrap = new StudylogScrap(member, studylog);
// when
studylogScrapRepository.save(expectedStudylogScrap);
StudylogScrap studylogScrap = studylogScrapRepository.findByMemberIdAndStudylogId(member.getId(), studylog.getId()).get();
// then
assertThat(expectedStudylogScrap).isEqualTo(studylogScrap);
}
Aggregations