Search in sources :

Example 16 with Studylog

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());
}
Also used : Ability(wooteco.prolog.ability.domain.Ability) StudylogAbility(wooteco.prolog.ability.domain.StudylogAbility) MemberService(wooteco.prolog.member.application.MemberService) EventListener(org.springframework.context.event.EventListener) Member(wooteco.prolog.member.domain.Member) Page(org.springframework.data.domain.Page) StudylogAbilityRepository(wooteco.prolog.ability.domain.repository.StudylogAbilityRepository) StudylogDeleteEvent(wooteco.prolog.studylog.event.StudylogDeleteEvent) Collectors(java.util.stream.Collectors) StudylogService(wooteco.prolog.studylog.application.StudylogService) PageableResponse(wooteco.prolog.common.PageableResponse) Ability(wooteco.prolog.ability.domain.Ability) StudylogAbility(wooteco.prolog.ability.domain.StudylogAbility) List(java.util.List) AbilityResponse(wooteco.prolog.ability.application.dto.AbilityResponse) StudylogAbilityRequest(wooteco.prolog.ability.application.dto.StudylogAbilityRequest) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) AbilityStudylogResponse(wooteco.prolog.ability.application.dto.AbilityStudylogResponse) Pageable(org.springframework.data.domain.Pageable) Studylog(wooteco.prolog.studylog.domain.Studylog) Transactional(org.springframework.transaction.annotation.Transactional) StudylogAbility(wooteco.prolog.ability.domain.StudylogAbility) Studylog(wooteco.prolog.studylog.domain.Studylog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with Studylog

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;
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) StudylogsResponse(wooteco.prolog.studylog.application.dto.StudylogsResponse) StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse) PopularStudylog(wooteco.prolog.studylog.domain.PopularStudylog) Studylog(wooteco.prolog.studylog.domain.Studylog)

Example 18 with Studylog

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);
}
Also used : StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) Studylog(wooteco.prolog.studylog.domain.Studylog) Session(wooteco.prolog.session.domain.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with Studylog

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);
}
Also used : Mission(wooteco.prolog.session.domain.Mission) LoginMember(wooteco.prolog.login.ui.LoginMember) Member(wooteco.prolog.member.domain.Member) Tags(wooteco.prolog.studylog.domain.Tags) Studylog(wooteco.prolog.studylog.domain.Studylog) Session(wooteco.prolog.session.domain.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with Studylog

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);
}
Also used : StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) Mission(wooteco.prolog.session.domain.Mission) 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