From 022953aa73681dc428e6dc7e75f3cf8ec8681b98 Mon Sep 17 00:00:00 2001 From: dingding-21 Date: Wed, 15 Mar 2023 12:42:35 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=EC=97=AD=EB=9F=89=EC=9D=98=20count?= =?UTF-8?q?=EA=B0=80=200=EC=9D=B4=EC=96=B4=EB=8F=84=20=ED=83=9C=EA=B7=B8?= =?UTF-8?q?=20=EA=B0=9C=EC=88=98=EB=A7=8C=ED=81=BC=20responseBody=EB=A5=BC?= =?UTF-8?q?=20=EB=B3=B4=EB=82=B4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workit/controller/AbilityController.java | 2 -- .../main/java/workit/service/AbilityService.java | 16 ++++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/workit/src/main/java/workit/controller/AbilityController.java b/workit/src/main/java/workit/controller/AbilityController.java index ab622ff..5aea0bb 100644 --- a/workit/src/main/java/workit/controller/AbilityController.java +++ b/workit/src/main/java/workit/controller/AbilityController.java @@ -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) diff --git a/workit/src/main/java/workit/service/AbilityService.java b/workit/src/main/java/workit/service/AbilityService.java index 0196ae7..f66a9a4 100644 --- a/workit/src/main/java/workit/service/AbilityService.java +++ b/workit/src/main/java/workit/service/AbilityService.java @@ -41,29 +41,29 @@ public List getAbilityCollection(Long userId) { () -> new CustomException(ResponseCode.USER_NOT_FOUND) ); + List allAbilities = abilityRepository.findAll(); List projects = projectRepository.findByUser(user); Map abilityCount = new HashMap<>(); + for (Ability ability : allAbilities) { + abilityCount.put(ability.getId(), 0); + } + projects.forEach(project -> { List works = workRepository.findByProject(project); works.forEach(work -> { List 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 responseDtos = new ArrayList<>(); - List abilities = abilityRepository.findAllById(abilityCount.keySet()); - abilities.stream() + + allAbilities.stream() .sorted(Comparator.comparing(Ability::getName)) .forEach(ability -> { AbilityCollectionResponseDto responseDto =