Search in sources :

Example 1 with DefaultAbility

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

the class AbilityService method createDefaultAbility.

@Transactional
public Long createDefaultAbility(DefaultAbilityCreateRequest request) {
    if (request.hasParent()) {
        DefaultAbility parentDefaultAbility = findDefaultAbilityById(request.getParentId());
        DefaultAbility childDefaultAbility = createChildDefaultAbility(request, parentDefaultAbility);
        return childDefaultAbility.getId();
    }
    DefaultAbility defaultAbility = createParentDefaultAbility(request);
    return defaultAbility.getId();
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DefaultAbility

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

the class AbilityServiceTest method createTemplateAbilities.

@DisplayName("멤버ID와 과정 선택을 통해 기본 역량을 등록한다.")
@Test
void createTemplateAbilities() {
    // given
    defaultAbilityRepository.save(new DefaultAbility("프로그래밍", "프로그래밍 입니다.", "#111111", "be"));
    assertThat(abilityService.findAbilitiesByMemberId(member.getId())).isEmpty();
    // when
    abilityService.applyDefaultAbilities(member.getId(), "be");
    // then
    assertThat(abilityService.findAbilitiesByMemberId(member.getId())).isNotEmpty();
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with DefaultAbility

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

the class DefaultAbilityRepositoryTest method findByTemplateOrTemplate.

@DisplayName("Template 타입이 common 또는 be인 역량 목록을 조회한다.")
@Test
void findByTemplateOrTemplate() {
    // given
    DefaultAbility defaultAbility = defaultAbilityRepository.save(new DefaultAbility("프로그래밍", "프로그래밍 역량", "#111111", "be", null));
    // when
    List<DefaultAbility> defaultAbilities = defaultAbilityRepository.findByTemplateOrTemplate("common", "be");
    // then
    assertThat(defaultAbilities).containsExactly(defaultAbility);
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Test(org.junit.jupiter.api.Test) RepositoryTest(wooteco.support.utils.RepositoryTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with DefaultAbility

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

the class AbilityService method applyDefaultAbilities.

@Transactional
public void applyDefaultAbilities(Long memberId, String template) {
    Member member = memberService.findById(memberId);
    List<DefaultAbility> defaultAbilities = findDefaultAbilitiesByTemplate(template);
    Map<DefaultAbility, Ability> parentAbilities = new HashMap<>();
    for (DefaultAbility defaultAbility : defaultAbilities) {
        if (defaultAbility.isParent()) {
            Ability parentAbility = mapToParentAbility(member, defaultAbility);
            parentAbilities.put(defaultAbility, parentAbility);
        } else {
            Ability parentAbility = parentAbilities.get(defaultAbility.getParent());
            mapToChildAbility(member, defaultAbility, parentAbility);
        }
    }
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability) DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) HashMap(java.util.HashMap) Member(wooteco.prolog.member.domain.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DefaultAbility (wooteco.prolog.ability.domain.DefaultAbility)4 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashMap (java.util.HashMap)1 Ability (wooteco.prolog.ability.domain.Ability)1 Member (wooteco.prolog.member.domain.Member)1 IntegrationTest (wooteco.support.utils.IntegrationTest)1 RepositoryTest (wooteco.support.utils.RepositoryTest)1