Search in sources :

Example 1 with StudylogNotFoundException

use of wooteco.prolog.studylog.exception.StudylogNotFoundException 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 2 with StudylogNotFoundException

use of wooteco.prolog.studylog.exception.StudylogNotFoundException 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 3 with StudylogNotFoundException

use of wooteco.prolog.studylog.exception.StudylogNotFoundException 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 4 with StudylogNotFoundException

use of wooteco.prolog.studylog.exception.StudylogNotFoundException 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 5 with StudylogNotFoundException

use of wooteco.prolog.studylog.exception.StudylogNotFoundException 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)

Aggregations

StudylogNotFoundException (wooteco.prolog.studylog.exception.StudylogNotFoundException)10 Studylog (wooteco.prolog.studylog.domain.Studylog)9 Transactional (org.springframework.transaction.annotation.Transactional)7 Member (wooteco.prolog.member.domain.Member)7 LoginMember (wooteco.prolog.login.ui.LoginMember)3 Mission (wooteco.prolog.session.domain.Mission)2 Session (wooteco.prolog.session.domain.Session)2 StudylogLikeResponse (wooteco.prolog.studylog.application.dto.StudylogLikeResponse)2 Tags (wooteco.prolog.studylog.domain.Tags)2 MemberNotFoundException (wooteco.prolog.member.exception.MemberNotFoundException)1 StudylogAbilityResponse (wooteco.prolog.report.application.dto.report.response.studylogs.StudylogAbilityResponse)1 StudylogResponse (wooteco.prolog.report.application.dto.report.response.studylogs.StudylogResponse)1 ReportedStudylog (wooteco.prolog.report.domain.report.studylog.ReportedStudylog)1 StudylogRead (wooteco.prolog.studylog.domain.StudylogRead)1 StudylogScrap (wooteco.prolog.studylog.domain.StudylogScrap)1 StudylogDeleteEvent (wooteco.prolog.studylog.event.StudylogDeleteEvent)1 StudylogScrapAlreadyRegisteredException (wooteco.prolog.studylog.exception.StudylogScrapAlreadyRegisteredException)1