Search in sources :

Example 6 with Ability

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

the class AbilityService method extractChildAbility.

private Ability extractChildAbility(Member member, List<Ability> abilities, String name, String description, String color, Long parentId) {
    Ability parentAbility = findAbilityById(parentId);
    Ability childAbility = Ability.child(name, description, color, parentAbility, member);
    childAbility.validateDuplicateName(abilities);
    childAbility.validateColorWithParent(abilities, parentAbility);
    return childAbility;
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability)

Example 7 with Ability

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

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

the class AbilityRepositoryTest method findByMemberAndParentIsNull.

@DisplayName("Member가 가진 부모역량만을 조회한다")
@Test
void findByMemberAndParentIsNull() {
    // given
    Member member = memberRepository.save(new Member("bperhaps", "손너잘", Role.CREW, 1L, "imageUrl"));
    Ability parentAbility = abilityRepository.save(Ability.parent("메타버스", "폴리곤 덩어리들", "123456", member));
    Ability childAbility = abilityRepository.save(Ability.child("마자용", "마자아아아~용", "하늘색", parentAbility, member));
    // when
    List<Ability> parentAbilities = abilityRepository.findByMemberIdAndParentIsNull(member.getId());
    // then
    assertThat(parentAbilities).containsExactly(parentAbility);
}
Also used : Ability(wooteco.prolog.ability.domain.Ability) Member(wooteco.prolog.member.domain.Member) Test(org.junit.jupiter.api.Test) RepositoryTest(wooteco.support.utils.RepositoryTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with Ability

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

the class AbilityTest method colorDifferentBetweenParentAndChildException.

@DisplayName("부모 자식 역량끼리 색상이 다른 경우 예외가 발생한다.")
@Test
void colorDifferentBetweenParentAndChildException() {
    // given
    Ability parentAbility = Ability.parent(1L, "역량1", "너잘의 3인칭 역량", "색상1", member);
    Ability anotherParentAbility = Ability.parent(2L, "역량2", "아따따뚜겐", "색상2", member);
    Ability childAbility = Ability.child(3L, "역량1의 자식역량", "너잘의 3인칭 역량", "색상3", parentAbility, member);
    // when, then
    assertThatThrownBy(() -> childAbility.validateColorWithParent(Collections.singletonList(anotherParentAbility), parentAbility)).isExactlyInstanceOf(AbilityParentChildColorDifferentException.class);
}
Also used : Ability(wooteco.prolog.ability.domain.Ability) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with Ability

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

the class AbilityTest method updateAbility.

@DisplayName("역량 정보를 수정한다.")
@Test
void updateAbility() {
    // given
    Long abilityId = 1L;
    Ability ability = Ability.parent(abilityId, "역량", "너잘의 3인칭 역량", "파란색", member);
    Ability updateTarget = new Ability(abilityId, "새로운 역량", "그것은 피카를 사랑하는 힘", "핑크색");
    // when
    ability.update(updateTarget);
    // then
    assertThat(ability).usingRecursiveComparison().ignoringFields("parent", "children", "member").isEqualTo(updateTarget);
}
Also used : Ability(wooteco.prolog.ability.domain.Ability) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Ability (wooteco.prolog.ability.domain.Ability)21 DefaultAbility (wooteco.prolog.ability.domain.DefaultAbility)14 DisplayName (org.junit.jupiter.api.DisplayName)11 Test (org.junit.jupiter.api.Test)11 Member (wooteco.prolog.member.domain.Member)7 IntegrationTest (wooteco.support.utils.IntegrationTest)6 Transactional (org.springframework.transaction.annotation.Transactional)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 HierarchyAbilityResponse (wooteco.prolog.ability.application.dto.HierarchyAbilityResponse)4 AbilityResponse (wooteco.prolog.ability.application.dto.AbilityResponse)2 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Disabled (org.junit.jupiter.api.Disabled)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