Search in sources :

Example 16 with Ability

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

the class AbilityService method deleteAbility.

@Transactional
public void deleteAbility(Long memberId, Long abilityId) {
    Ability ability = findAbilityByIdAndMemberId(abilityId, memberId);
    if (ability.isParent() && !ability.getChildren().isEmpty()) {
        throw new AbilityHasChildrenException();
    }
    abilityRepository.delete(ability);
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability) AbilityHasChildrenException(wooteco.prolog.report.exception.AbilityHasChildrenException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with Ability

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

the class AbilityService method findParentAbilitiesByUsername.

public List<HierarchyAbilityResponse> findParentAbilitiesByUsername(String username) {
    Member member = memberService.findByUsername(username);
    List<Ability> parentAbilities = abilityRepository.findByMemberIdAndParentIsNull(member.getId());
    return HierarchyAbilityResponse.listOf(parentAbilities);
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability) Member(wooteco.prolog.member.domain.Member)

Example 18 with Ability

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

Example 19 with Ability

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

the class AbilityService method findFlatAbilitiesByMember.

public List<AbilityResponse> findFlatAbilitiesByMember(String username) {
    Member member = memberService.findByUsername(username);
    List<Ability> abilities = abilityRepository.findByMemberId(member.getId());
    return AbilityResponse.listOf(abilities);
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability) Member(wooteco.prolog.member.domain.Member)

Example 20 with Ability

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

the class AbilityService method extractParentAbility.

private Ability extractParentAbility(Member member, List<Ability> abilities, String name, String description, String color) {
    Ability parentAbility = Ability.parent(name, description, color, member);
    parentAbility.validateDuplicateName(abilities);
    parentAbility.validateDuplicateColor(abilities);
    return parentAbility;
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability)

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