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