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