diff --git a/src/main/java/com/fairy_pitt/recordary/endpoint/group/GroupApplyController.java b/src/main/java/com/fairy_pitt/recordary/endpoint/group/GroupApplyController.java index a7718b7..a74632c 100644 --- a/src/main/java/com/fairy_pitt/recordary/endpoint/group/GroupApplyController.java +++ b/src/main/java/com/fairy_pitt/recordary/endpoint/group/GroupApplyController.java @@ -43,13 +43,13 @@ public Boolean applyDelete(@RequestBody GroupMemberRequestDto id){ } @GetMapping("findGroupApply/{userCd}") - public List findGroupAppliesToUser(@PathVariable Long userCd){ + public List findGroupAppliesToUser(@PathVariable Long userCd){ return groupApplyService.findGroupAppliesToUser(userCd); } @GetMapping("findUserApply/{groupCd}") - public List findUserAppliesToGroup(@PathVariable Long groupCd) + public List findUserAppliesToGroup(@PathVariable Long groupCd) { return groupApplyService.findUserAppliesToGroup(groupCd); } diff --git a/src/main/java/com/fairy_pitt/recordary/endpoint/group/service/GroupApplyService.java b/src/main/java/com/fairy_pitt/recordary/endpoint/group/service/GroupApplyService.java index dc41c40..591213f 100644 --- a/src/main/java/com/fairy_pitt/recordary/endpoint/group/service/GroupApplyService.java +++ b/src/main/java/com/fairy_pitt/recordary/endpoint/group/service/GroupApplyService.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -49,29 +50,20 @@ public void delete (GroupMemberRequestDto requestDto) { } @Transactional(readOnly = true) - public List findGroupAppliesToUser(Long userId){ + public List findGroupAppliesToUser(Long userId){ UserEntity user = userService.findEntity(userId); - List groupApplyEntities = groupApplyRepository.findAllByUserFKAndAndApplyState(user,1); - List groupResponseDto = new ArrayList<>(); + return groupApplyRepository.findAllByUserFKAndAndApplyState(user,1).stream() + .map(GroupApplyResponseDto :: new) + .collect(Collectors.toList()); - for (GroupApplyEntity groupApplyEntity : groupApplyEntities){ - GroupResponseDto responseDto = new GroupResponseDto(groupApplyEntity.getGroupFK()); - groupResponseDto.add(responseDto); - } - return groupResponseDto; } @Transactional(readOnly = true) - public List findUserAppliesToGroup(Long groupCd){ + public List findUserAppliesToGroup(Long groupCd){ GroupEntity group = groupRepository.findByGroupCd(groupCd); - List groupApplyEntities = groupApplyRepository.findAllByGroupFKAndApplyState(group,2); - List userResponseDto = new ArrayList<>(); - - for (GroupApplyEntity groupApplyEntity : groupApplyEntities){ - UserResponseDto responseDto = new UserResponseDto(groupApplyEntity.getUserFK()); - userResponseDto.add(responseDto); - } - return userResponseDto; + return groupApplyRepository.findAllByGroupFKAndApplyState(group,2).stream() + .map(GroupApplyResponseDto :: new) + .collect(Collectors.toList()); } private Boolean checkApply(Long groupCd, Long userCd)