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;
}
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());
}
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);
}
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);
}
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);
}
Aggregations