use of wooteco.prolog.studylog.domain.Studylog in project prolog by woowacourse.
the class StudylogAbilityService method updateStudylogAbilities.
@Transactional
public List<AbilityResponse> updateStudylogAbilities(Long memberId, Long studylogId, StudylogAbilityRequest studylogAbilityRequest) {
Studylog studylog = studylogService.findStudylogById(studylogId);
studylog.validateBelongTo(memberId);
List<Ability> abilities = abilityService.findByIdIn(memberId, studylogAbilityRequest.getAbilities());
// 자식 역량이 있는데 부모 역량이 있는 경우 예외처리
abilities.stream().filter(it -> !it.isParent()).filter(it -> abilities.contains(it.getParent())).findFirst().ifPresent(it -> {
throw new IllegalArgumentException("자식 역량이 존재하는 경우 부모 역량을 선택할 수 없습니다.");
});
List<StudylogAbility> studylogAbilities = abilities.stream().map(it -> new StudylogAbility(memberId, it, studylog)).collect(Collectors.toList());
studylogAbilityRepository.deleteByStudylogId(studylogId);
List<StudylogAbility> persistStudylogAbilities = studylogAbilityRepository.saveAll(studylogAbilities);
return persistStudylogAbilities.stream().map(it -> AbilityResponse.of(it.getAbility())).collect(Collectors.toList());
}
use of wooteco.prolog.studylog.domain.Studylog in project prolog by woowacourse.
the class PopularStudylogService method findPopularStudylogs.
public StudylogsResponse findPopularStudylogs(Pageable pageable, Long memberId, boolean isAnonymousMember) {
List<Studylog> studylogs = getSortedPopularStudyLogs();
PageImpl<Studylog> page = new PageImpl<>(studylogs, pageable, studylogs.size());
StudylogsResponse studylogsResponse = StudylogsResponse.of(page, memberId);
if (isAnonymousMember) {
return studylogsResponse;
}
List<StudylogResponse> data = studylogsResponse.getData();
studylogService.updateScrap(data, studylogService.findScrapIds(memberId));
studylogService.updateRead(data, studylogService.findReadIds(memberId));
return studylogsResponse;
}
use of wooteco.prolog.studylog.domain.Studylog in project prolog by woowacourse.
the class StudylogService method updateStudylogSession.
@Transactional
public void updateStudylogSession(Long memberId, Long studylogId, StudylogSessionRequest studylogSessionRequest) {
Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
studylog.validateBelongTo(memberId);
Session session = sessionService.findSessionById(studylogSessionRequest.getSessionId()).orElse(null);
studylog.updateSession(session);
}
use of wooteco.prolog.studylog.domain.Studylog in project prolog by woowacourse.
the class StudylogService method insertStudylog.
@Transactional
public StudylogResponse insertStudylog(Long memberId, StudylogRequest studylogRequest) {
Member member = memberService.findById(memberId);
Tags tags = tagService.findOrCreate(studylogRequest.getTags());
Session session = sessionService.findSessionById(studylogRequest.getSessionId()).orElse(null);
Mission mission = missionService.findMissionById(studylogRequest.getMissionId()).orElse(null);
Studylog persistStudylog = studylogRepository.save(new Studylog(member, studylogRequest.getTitle(), studylogRequest.getContent(), session, mission, tags.getList()));
onStudylogCreatedEvent(member, tags, persistStudylog);
deleteStudylogTemp(memberId);
return StudylogResponse.of(persistStudylog);
}
use of wooteco.prolog.studylog.domain.Studylog in project prolog by woowacourse.
the class StudylogService method updateStudylogMission.
@Transactional
public void updateStudylogMission(Long memberId, Long studylogId, StudylogMissionRequest studylogMissionRequest) {
Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
studylog.validateBelongTo(memberId);
Mission mission = missionService.findMissionById(studylogMissionRequest.getMissionId()).orElse(null);
studylog.updateMission(mission);
}
Aggregations