Search in sources :

Example 1 with Studylog

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

the class ReportRepositoryTest method createReport.

private Report createReport(Member member) {
    Ability ability1 = abilityRepository.save(AbilityFixture.parentAbility1(member));
    Ability ability2 = abilityRepository.save(AbilityFixture.parentAbility2(member));
    Ability ability3 = abilityRepository.save(AbilityFixture.parentAbility3(member));
    GraphAbilities graphAbilities = new GraphAbilities(Arrays.asList(new GraphAbility(ability1, 1L, true), new GraphAbility(ability2, 2L, true), new GraphAbility(ability3, 3L, true)));
    Level level1 = levelRepository.save(LevelFixture.level1());
    Mission mission = missionRepository.save(MissionFixture.mission1(level1));
    Ability ability4 = abilityRepository.save(AbilityFixture.childAbility1(member, ability1));
    Ability ability5 = abilityRepository.save(AbilityFixture.childAbility2(member, ability2));
    Studylog studylog = studylogRepository.save(createStudylog(member, mission));
    ReportedStudylogs reportedStudylogs = new ReportedStudylogs(Arrays.asList(new ReportedStudylog(studylog.getId(), Arrays.asList(new ReportedStudylogAbility(ability4), new ReportedStudylogAbility(ability5))), new ReportedStudylog(studylog.getId(), Arrays.asList(new ReportedStudylogAbility(ability4), new ReportedStudylogAbility(ability5)))));
    return ReportFixture.builder().member(member).title("test report").description("test report").graph(new AbilityGraph(graphAbilities)).member(member).studylogs(reportedStudylogs).build();
}
Also used : GraphAbility(wooteco.prolog.report.domain.report.abilitygraph.GraphAbility) ReportedStudylogAbility(wooteco.prolog.report.domain.report.studylog.ReportedStudylogAbility) Ability(wooteco.prolog.report.domain.ablity.Ability) GraphAbilities(wooteco.prolog.report.domain.report.abilitygraph.GraphAbilities) ReportedStudylog(wooteco.prolog.report.domain.report.studylog.ReportedStudylog) ReportedStudylogs(wooteco.prolog.report.domain.report.studylog.ReportedStudylogs) AbilityGraph(wooteco.prolog.report.domain.report.abilitygraph.AbilityGraph) GraphAbility(wooteco.prolog.report.domain.report.abilitygraph.GraphAbility) Level(wooteco.prolog.studylog.domain.Level) Mission(wooteco.prolog.studylog.domain.Mission) ReportedStudylog(wooteco.prolog.report.domain.report.studylog.ReportedStudylog) Studylog(wooteco.prolog.studylog.domain.Studylog) ReportedStudylogAbility(wooteco.prolog.report.domain.report.studylog.ReportedStudylogAbility)

Example 2 with Studylog

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

the class ReportAssembler method of.

private StudylogResponse of(ReportedStudylog reportedStudylog) {
    List<StudylogAbilityResponse> abilityResponses = reportedStudylog.getAbilities().stream().map(this::of).collect(toList());
    Studylog studylog = studylogRepository.findById(reportedStudylog.getStudylogId()).orElseThrow(StudylogNotFoundException::new);
    return new StudylogResponse(studylog.getId(), studylog.getCreatedAt(), studylog.getUpdatedAt(), studylog.getTitle(), abilityResponses);
}
Also used : StudylogAbilityResponse(wooteco.prolog.report.application.dto.report.response.studylogs.StudylogAbilityResponse) StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) StudylogResponse(wooteco.prolog.report.application.dto.report.response.studylogs.StudylogResponse) ReportedStudylog(wooteco.prolog.report.domain.report.studylog.ReportedStudylog) Studylog(wooteco.prolog.studylog.domain.Studylog)

Example 3 with Studylog

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

the class StudylogLikeService method unlikeStudylog.

@Transactional
public StudylogLikeResponse unlikeStudylog(Long memberId, Long studylogId, boolean isMember) {
    validIfMember(isMember);
    Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
    Member member = memberService.findById(memberId);
    studylog.unlike(member.getId());
    return new StudylogLikeResponse(false, studylog.getLikeCount());
}
Also used : StudylogLikeResponse(wooteco.prolog.studylog.application.dto.StudylogLikeResponse) StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) Member(wooteco.prolog.member.domain.Member) Studylog(wooteco.prolog.studylog.domain.Studylog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Studylog

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

the class StudylogLikeService method likeStudylog.

@Transactional
public StudylogLikeResponse likeStudylog(Long memberId, Long studylogId, boolean isMember) {
    validIfMember(isMember);
    Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
    Member member = memberService.findById(memberId);
    studylog.like(member.getId());
    return new StudylogLikeResponse(true, studylog.getLikeCount());
}
Also used : StudylogLikeResponse(wooteco.prolog.studylog.application.dto.StudylogLikeResponse) StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) Member(wooteco.prolog.member.domain.Member) Studylog(wooteco.prolog.studylog.domain.Studylog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Studylog

use of wooteco.prolog.studylog.domain.Studylog 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)

Aggregations

Studylog (wooteco.prolog.studylog.domain.Studylog)29 Member (wooteco.prolog.member.domain.Member)13 Mission (wooteco.prolog.session.domain.Mission)12 Session (wooteco.prolog.session.domain.Session)12 Transactional (org.springframework.transaction.annotation.Transactional)11 StudylogNotFoundException (wooteco.prolog.studylog.exception.StudylogNotFoundException)9 DisplayName (org.junit.jupiter.api.DisplayName)8 Test (org.junit.jupiter.api.Test)8 LoginMember (wooteco.prolog.login.ui.LoginMember)7 RepositoryTest (wooteco.support.utils.RepositoryTest)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 StudylogResponse (wooteco.prolog.studylog.application.dto.StudylogResponse)5 Tag (wooteco.prolog.studylog.domain.Tag)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)3 Pageable (org.springframework.data.domain.Pageable)3 StudylogTag (wooteco.prolog.studylog.domain.StudylogTag)3 Tags (wooteco.prolog.studylog.domain.Tags)3 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2