Search in sources :

Example 1 with StudylogAbilityRequest

use of wooteco.prolog.ability.application.dto.StudylogAbilityRequest 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 StudylogAbilityRequest

use of wooteco.prolog.ability.application.dto.StudylogAbilityRequest in project prolog by woowacourse.

the class StudylogAbilityStepDefinitions method 역량에학습로그를맵핑하면.

@When("{string} 학습로그에 {string} 역량을 맵핑하(면)(고)")
public void 역량에학습로그를맵핑하면(String studylogName, String abilityName) {
    HierarchyAbilityResponse ability = (HierarchyAbilityResponse) context.storage.get(abilityName);
    StudylogResponse studylog = (StudylogResponse) context.storage.get(studylogName);
    StudylogAbilityRequest requestBody = new StudylogAbilityRequest(Lists.newArrayList(ability.getId()));
    context.invokeHttpPutWithToken("/studylogs/" + studylog.getId() + "/abilities", requestBody);
}
Also used : HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse) AbilityStudylogResponse(wooteco.prolog.ability.application.dto.AbilityStudylogResponse) StudylogAbilityRequest(wooteco.prolog.ability.application.dto.StudylogAbilityRequest) When(io.cucumber.java.en.When)

Example 3 with StudylogAbilityRequest

use of wooteco.prolog.ability.application.dto.StudylogAbilityRequest in project prolog by woowacourse.

the class StudylogAbilityStepDefinitions method 학습로그에역량을맵핑하면.

@When("{string} 학습로그에 {string}, {string} 역량을 맵핑하(면)(고)")
public void 학습로그에역량을맵핑하면(String studylogName, String abilityName1, String abilityName2) {
    HierarchyAbilityResponse ability1 = (HierarchyAbilityResponse) context.storage.get(abilityName1);
    HierarchyAbilityResponse ability2 = (HierarchyAbilityResponse) context.storage.get(abilityName2);
    StudylogResponse studylog = (StudylogResponse) context.storage.get(studylogName);
    StudylogAbilityRequest requestBody = new StudylogAbilityRequest(Lists.newArrayList(ability1.getId(), ability2.getId()));
    context.invokeHttpPutWithToken("/studylogs/" + studylog.getId() + "/abilities", requestBody);
}
Also used : HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse) AbilityStudylogResponse(wooteco.prolog.ability.application.dto.AbilityStudylogResponse) StudylogAbilityRequest(wooteco.prolog.ability.application.dto.StudylogAbilityRequest) When(io.cucumber.java.en.When)

Aggregations

AbilityStudylogResponse (wooteco.prolog.ability.application.dto.AbilityStudylogResponse)3 StudylogAbilityRequest (wooteco.prolog.ability.application.dto.StudylogAbilityRequest)3 When (io.cucumber.java.en.When)2 HierarchyAbilityResponse (wooteco.prolog.ability.application.dto.HierarchyAbilityResponse)2 StudylogResponse (wooteco.prolog.studylog.application.dto.StudylogResponse)2 LocalDate (java.time.LocalDate)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)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 Transactional (org.springframework.transaction.annotation.Transactional)1 AbilityResponse (wooteco.prolog.ability.application.dto.AbilityResponse)1 Ability (wooteco.prolog.ability.domain.Ability)1 StudylogAbility (wooteco.prolog.ability.domain.StudylogAbility)1 StudylogAbilityRepository (wooteco.prolog.ability.domain.repository.StudylogAbilityRepository)1 PageableResponse (wooteco.prolog.common.PageableResponse)1 MemberService (wooteco.prolog.member.application.MemberService)1 Member (wooteco.prolog.member.domain.Member)1