Skip to content

Commit

Permalink
Merge pull request #30 from TEAM-Workit/feat/hyeonji/#29
Browse files Browse the repository at this point in the history
chore: 역량의 count가 0이어도 태그 개수만큼 responseBody를 보내도록 수정
  • Loading branch information
hyeon-z authored Mar 15, 2023
2 parents cfd5da3 + 022953a commit 1222f58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 0 additions & 2 deletions workit/src/main/java/workit/controller/AbilityController.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public ResponseMessage getAbilityCollection(HttpServletRequest request) {

Long userId = Long.valueOf(request.getUserPrincipal().getName());


abilityService.getAbilityCollection(userId);
return ResponseMessage.toResponseEntity(
ResponseCode.GET_ABILITY_COLLECTION,
abilityService.getAbilityCollection(userId)
Expand Down
16 changes: 8 additions & 8 deletions workit/src/main/java/workit/service/AbilityService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,29 @@ public List<AbilityCollectionResponseDto> getAbilityCollection(Long userId) {
() -> new CustomException(ResponseCode.USER_NOT_FOUND)
);

List<Ability> allAbilities = abilityRepository.findAll();

List<Project> projects = projectRepository.findByUser(user);
Map<Long, Integer> abilityCount = new HashMap<>();

for (Ability ability : allAbilities) {
abilityCount.put(ability.getId(), 0);
}

projects.forEach(project -> {
List<Work> works = workRepository.findByProject(project);
works.forEach(work -> {
List<WorkAbility> workAbilities = workAbilityRepository.findByWork(work);
workAbilities.forEach((workAbility -> {
Ability ability = workAbility.getAbility();
Long abilityId = ability.getId();

if (!abilityCount.containsKey(abilityId)) {
abilityCount.put(abilityId, 0);
}
Long abilityId = workAbility.getAbility().getId();
abilityCount.put(abilityId, abilityCount.get(abilityId) + 1);
}));
});
});

List<AbilityCollectionResponseDto> responseDtos = new ArrayList<>();
List<Ability> abilities = abilityRepository.findAllById(abilityCount.keySet());
abilities.stream()

allAbilities.stream()
.sorted(Comparator.comparing(Ability::getName))
.forEach(ability -> {
AbilityCollectionResponseDto responseDto =
Expand Down

0 comments on commit 1222f58

Please sign in to comment.