Search in sources :

Example 1 with AbilityResponse

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

the class AbilityServiceTest method updateAbilityParentChangeChildrenColors.

@DisplayName("역량 정보를 수정할 때 부모 역량의 경우 자식 역량의 색상이 모두 변경된다.")
@Test
void updateAbilityParentChangeChildrenColors() {
    // given
    AbilityCreateRequest createParentRequest = new AbilityCreateRequest("부모 프로그래밍", "프로그래밍 역량입니다.", "#111111", null);
    abilityService.createAbility(member.getId(), createParentRequest);
    HierarchyAbilityResponse createdParentResponse = abilityService.findParentAbilitiesByMemberId(member.getId()).get(0);
    AbilityCreateRequest createChildRequest = new AbilityCreateRequest("자식 프로그래밍", "부모 프로그래밍의 자식입니다.", createdParentResponse.getColor(), createdParentResponse.getId());
    abilityService.createAbility(member.getId(), createChildRequest);
    String newColor = "#ffffff";
    AbilityUpdateRequest request = new AbilityUpdateRequest(createdParentResponse.getId(), "완전히 새로운 이름", "완전히 새로운건데요?!", newColor);
    // when
    abilityService.updateAbility(member.getId(), request.getId(), request);
    // then
    List<HierarchyAbilityResponse> abilityResponses = abilityService.findAbilitiesByMemberId(member.getId());
    HierarchyAbilityResponse updatedParentResponse = abilityResponses.stream().filter(response -> response.getId().equals(createdParentResponse.getId())).findAny().orElseThrow(AbilityNotFoundException::new);
    AbilityResponse updatedChildResponse = updatedParentResponse.getChildren().get(0);
    assertThat(updatedParentResponse.getColor()).isEqualTo(newColor);
    assertThat(updatedChildResponse.getColor()).isEqualTo(newColor);
}
Also used : AbilityCreateRequest(wooteco.prolog.ability.application.dto.AbilityCreateRequest) AbilityResponse(wooteco.prolog.ability.application.dto.AbilityResponse) HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) AbilityNotFoundException(wooteco.prolog.report.exception.AbilityNotFoundException) DefaultAbilityNotFoundException(wooteco.prolog.report.exception.DefaultAbilityNotFoundException) AbilityUpdateRequest(wooteco.prolog.ability.application.dto.AbilityUpdateRequest) HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with AbilityResponse

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

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

the class AbilityServiceTest method updateAbilityChildCanNotChangeColor.

@DisplayName("역량 정보를 수정할 때 자식 역량의 경우 색상이 변경되지 않는다.")
@Test
void updateAbilityChildCanNotChangeColor() {
    // given
    String legacyColor = "#111111";
    AbilityCreateRequest createParentRequest1 = new AbilityCreateRequest("부모 프로그래밍", "프로그래밍 역량입니다.", legacyColor, null);
    abilityService.createAbility(member.getId(), createParentRequest1);
    HierarchyAbilityResponse createdParentResponse = abilityService.findParentAbilitiesByMemberId(member.getId()).get(0);
    AbilityCreateRequest createChildRequest1 = new AbilityCreateRequest("자식 프로그래밍", "부모 프로그래밍의 자식입니다.", createdParentResponse.getColor(), createdParentResponse.getId());
    abilityService.createAbility(member.getId(), createChildRequest1);
    AbilityResponse childAbilityDto = abilityService.findParentAbilitiesByMemberId(member.getId()).get(0).getChildren().get(0);
    String newColor = "#ffffff";
    String newName = "완전히 새로운 이름";
    String newDescription = "완전히 새로운건데요?!";
    AbilityUpdateRequest request = new AbilityUpdateRequest(childAbilityDto.getId(), newName, newDescription, newColor);
    // when
    abilityService.updateAbility(member.getId(), request.getId(), request);
    // then
    Ability ability = abilityService.findAbilityById(childAbilityDto.getId());
    assertThat(ability.getName()).isEqualTo(newName);
    assertThat(ability.getDescription()).isEqualTo(newDescription);
    assertThat(ability.getColor()).isEqualTo(legacyColor);
}
Also used : AbilityCreateRequest(wooteco.prolog.ability.application.dto.AbilityCreateRequest) AbilityResponse(wooteco.prolog.ability.application.dto.AbilityResponse) HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability) AbilityUpdateRequest(wooteco.prolog.ability.application.dto.AbilityUpdateRequest) HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

AbilityResponse (wooteco.prolog.ability.application.dto.AbilityResponse)3 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 AbilityCreateRequest (wooteco.prolog.ability.application.dto.AbilityCreateRequest)2 AbilityUpdateRequest (wooteco.prolog.ability.application.dto.AbilityUpdateRequest)2 HierarchyAbilityResponse (wooteco.prolog.ability.application.dto.HierarchyAbilityResponse)2 Ability (wooteco.prolog.ability.domain.Ability)2 IntegrationTest (wooteco.support.utils.IntegrationTest)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 AbilityStudylogResponse (wooteco.prolog.ability.application.dto.AbilityStudylogResponse)1 StudylogAbilityRequest (wooteco.prolog.ability.application.dto.StudylogAbilityRequest)1 DefaultAbility (wooteco.prolog.ability.domain.DefaultAbility)1 StudylogAbility (wooteco.prolog.ability.domain.StudylogAbility)1