Search in sources :

Example 6 with Studylog

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

the class StudylogService method retrieveStudylogById.

@Transactional
public StudylogResponse retrieveStudylogById(LoginMember loginMember, Long studylogId) {
    Studylog studylog = findStudylogById(studylogId);
    onStudylogRetrieveEvent(loginMember, studylog);
    return toStudylogResponse(loginMember, studylog);
}
Also used : Studylog(wooteco.prolog.studylog.domain.Studylog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Studylog

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

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

the class StudylogService method updateStudylog.

@Transactional
public void updateStudylog(Long memberId, Long studylogId, StudylogRequest studylogRequest) {
    Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
    studylog.validateBelongTo(memberId);
    Session session = sessionService.findSessionById(studylogRequest.getSessionId()).orElse(null);
    Mission mission = missionService.findMissionById(studylogRequest.getMissionId()).orElse(null);
    final Member foundMember = memberService.findById(memberId);
    final Tags originalTags = tagService.findByStudylogsAndMember(studylog, foundMember);
    Tags newTags = tagService.findOrCreate(studylogRequest.getTags());
    studylog.update(studylogRequest.getTitle(), studylogRequest.getContent(), session, mission, newTags);
    memberTagService.updateMemberTag(originalTags, newTags, foundMember);
    studylogDocumentService.update(studylog.toStudylogDocument());
}
Also used : StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) Mission(wooteco.prolog.session.domain.Mission) LoginMember(wooteco.prolog.login.ui.LoginMember) Member(wooteco.prolog.member.domain.Member) Studylog(wooteco.prolog.studylog.domain.Studylog) Tags(wooteco.prolog.studylog.domain.Tags) Session(wooteco.prolog.session.domain.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Studylog

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

the class StudylogService method deleteStudylog.

@Transactional
public void deleteStudylog(Long memberId, Long studylogId) {
    final Member foundMember = memberService.findById(memberId);
    Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
    studylog.validateBelongTo(memberId);
    final Tags tags = tagService.findByStudylogsAndMember(studylog, foundMember);
    studylogDocumentService.delete(studylog.toStudylogDocument());
    checkScrapedOrRead(memberId, studylogId);
    memberTagService.removeMemberTag(tags, foundMember);
    studylog.delete();
    eventPublisher.publishEvent(new StudylogDeleteEvent(studylogId));
}
Also used : StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) StudylogDeleteEvent(wooteco.prolog.studylog.event.StudylogDeleteEvent) LoginMember(wooteco.prolog.login.ui.LoginMember) Member(wooteco.prolog.member.domain.Member) Studylog(wooteco.prolog.studylog.domain.Studylog) Tags(wooteco.prolog.studylog.domain.Tags) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with Studylog

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

the class StudylogService method findStudylogs.

public StudylogsResponse findStudylogs(StudylogsSearchRequest request, Long memberId) {
    if (Objects.nonNull(request.getIds())) {
        Pageable pageable = request.getPageable();
        List<Long> ids = request.getIds();
        Page<Studylog> studylogs = studylogRepository.findByIdInAndDeletedFalseOrderByIdAsc(ids, pageable);
        return StudylogsResponse.of(studylogs, memberId);
    }
    if (request.getKeyword() == null || request.getKeyword().isEmpty()) {
        return findStudylogsWithoutKeyword(request.getSessions(), request.getMissions(), request.getTags(), request.getUsernames(), request.getMembers(), request.getStartDate(), request.getEndDate(), request.getPageable(), memberId);
    }
    final StudylogDocumentResponse response = studylogDocumentService.findBySearchKeyword(request.getKeyword(), request.getTags(), request.getMissions(), request.getSessions(), request.getUsernames(), request.getStartDate(), request.getEndDate(), request.getPageable());
    final List<Studylog> studylogs = studylogRepository.findByIdInAndDeletedFalseOrderByIdDesc(response.getStudylogIds());
    return StudylogsResponse.of(studylogs, response.getTotalSize(), response.getTotalPage(), response.getCurrPage(), memberId);
}
Also used : Pageable(org.springframework.data.domain.Pageable) StudylogDocumentResponse(wooteco.prolog.studylog.application.dto.StudylogDocumentResponse) Studylog(wooteco.prolog.studylog.domain.Studylog)

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