Search in sources :

Example 1 with StudylogAbility

use of wooteco.prolog.ability.domain.StudylogAbility 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 2 with StudylogAbility

use of wooteco.prolog.ability.domain.StudylogAbility in project prolog by woowacourse.

the class StudylogAbilityService method findAbilityStudylogsMappingOnlyByAbilityIds.

public PageableResponse<AbilityStudylogResponse> findAbilityStudylogsMappingOnlyByAbilityIds(String username, List<Long> abilityIds, Pageable pageable) {
    if (abilityIds != null && !abilityIds.isEmpty()) {
        Page<StudylogAbility> studylogAbilities = studylogAbilityRepository.findByAbilityIdIn(abilityIds, pageable);
        List<AbilityStudylogResponse> abilityStudylogResponses = AbilityStudylogResponse.listOf(studylogAbilities.getContent());
        return PageableResponse.of(abilityStudylogResponses, studylogAbilities);
    }
    Member member = memberService.findByUsername(username);
    Page<StudylogAbility> studylogAbilities = studylogAbilityRepository.findByMemberId(member.getId(), pageable);
    List<AbilityStudylogResponse> abilityStudylogResponses = AbilityStudylogResponse.listOf(studylogAbilities.getContent());
    return PageableResponse.of(abilityStudylogResponses, studylogAbilities);
}
Also used : StudylogAbility(wooteco.prolog.ability.domain.StudylogAbility) AbilityStudylogResponse(wooteco.prolog.ability.application.dto.AbilityStudylogResponse) Member(wooteco.prolog.member.domain.Member)

Example 3 with StudylogAbility

use of wooteco.prolog.ability.domain.StudylogAbility in project prolog by woowacourse.

the class ReportService method createReport.

@Transactional
public ReportResponse createReport(LoginMember loginMember, ReportRequest reportRequest) {
    Report report = reportRepository.save(new Report(reportRequest.getTitle(), reportRequest.getDescription(), loginMember.getId(), LocalDate.parse(reportRequest.getStartDate()), LocalDate.parse(reportRequest.getEndDate())));
    List<HierarchyAbilityResponse> abilities = abilityService.findParentAbilitiesByMemberId(loginMember.getId());
    List<ReportAbility> reportAbilities = reportAbilityRepository.saveAll(abilities.stream().map(it -> new ReportAbility(it.getName(), it.getDescription(), it.getColor(), reportRequest.findWeight(it.getId()), it.getId(), report.getId())).collect(Collectors.toList()));
    List<StudylogAbility> studylogAbilities = studylogAbilityService.findStudylogAbilitiesInPeriod(loginMember.getId(), LocalDate.parse(reportRequest.getStartDate()), LocalDate.parse(reportRequest.getEndDate()));
    List<ReportStudylog> reportStudylogs = reportStudylogRepository.saveAll(studylogAbilities.stream().map(it -> new ReportStudylog(report.getId(), findReportAbilityByAbility(it.getAbility(), reportAbilities), it.getStudylog(), it.getAbility().getName(), it.getAbility().getColor())).collect(Collectors.toList()));
    return ReportResponse.of(report, reportAbilities, reportStudylogs);
}
Also used : StudylogAbility(wooteco.prolog.ability.domain.StudylogAbility) Report(wooteco.prolog.report.domain.Report) HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) ReportAbility(wooteco.prolog.report.domain.ReportAbility) ReportStudylog(wooteco.prolog.report.domain.ReportStudylog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with StudylogAbility

use of wooteco.prolog.ability.domain.StudylogAbility in project prolog by woowacourse.

the class AbilityStudylogResponse method of.

public static AbilityStudylogResponse of(Studylog studylog, List<StudylogAbility> studylogAbilities) {
    StudylogResponse studylogResponse = StudylogResponse.of(studylog);
    List<AbilityResponse> abilityResponses = studylogAbilities.stream().map(it -> AbilityResponse.of(it.getAbility())).collect(Collectors.toList());
    return new AbilityStudylogResponse(studylogResponse, abilityResponses);
}
Also used : Ability(wooteco.prolog.ability.domain.Ability) StudylogAbility(wooteco.prolog.ability.domain.StudylogAbility) List(java.util.List) Getter(lombok.Getter) StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse) Studylog(wooteco.prolog.studylog.domain.Studylog) AllArgsConstructor(lombok.AllArgsConstructor) Collectors(java.util.stream.Collectors) StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse)

Aggregations

StudylogAbility (wooteco.prolog.ability.domain.StudylogAbility)4 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Transactional (org.springframework.transaction.annotation.Transactional)2 AbilityStudylogResponse (wooteco.prolog.ability.application.dto.AbilityStudylogResponse)2 Ability (wooteco.prolog.ability.domain.Ability)2 Member (wooteco.prolog.member.domain.Member)2 Studylog (wooteco.prolog.studylog.domain.Studylog)2 LocalDate (java.time.LocalDate)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Getter (lombok.Getter)1 EventListener (org.springframework.context.event.EventListener)1 Page (org.springframework.data.domain.Page)1 Pageable (org.springframework.data.domain.Pageable)1 Service (org.springframework.stereotype.Service)1 AbilityResponse (wooteco.prolog.ability.application.dto.AbilityResponse)1 HierarchyAbilityResponse (wooteco.prolog.ability.application.dto.HierarchyAbilityResponse)1 StudylogAbilityRequest (wooteco.prolog.ability.application.dto.StudylogAbilityRequest)1 StudylogAbilityRepository (wooteco.prolog.ability.domain.repository.StudylogAbilityRepository)1 PageableResponse (wooteco.prolog.common.PageableResponse)1