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