From a3df2f502dc4321f84c5097df1aa64c685aa30d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A3=BC=EC=98=81?= <77871898+kjy-asl@users.noreply.github.com> Date: Sat, 8 Jun 2024 14:28:05 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=B0=9C=EA=B2=AC-=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?return=20=EA=B0=92=20=EB=A1=A4=EB=B0=B1=20(#184)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/UserServiceImpl.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java index b0bcd46e..e4735114 100644 --- a/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java @@ -252,7 +252,7 @@ public List getPopularDesigners(Long userId) { //TODO - 쿼리 return UserResponseDTO.of(user, userScrap.isStatus()); } return UserResponseDTO.of(user, false); - }).collect(Collectors.toList()); + }).collect(Collectors.toList()); } @Override @@ -284,27 +284,38 @@ public WorkPortfolioGetResponseDTO getPortfolio(Long requestUserId, Long userId) public List getDiscoveryUsers(Long userId, int[] tags){ List users; - if (tags.length == 0) { // user 정보 조회 태그가 걸린 경우와 아닌 경우 + if (tags.length == 0) { users = userRepository.findAllDiscoveryUser(userId); //TODO - user 관련 쿼리 잡기 , 동적 쿼리 필요,, } else { users = userRepository.findAllDiscoveryUserWithTag(userId, tags); } - Map scrapMap = users.stream() - .collect(Collectors.toMap(UserScrapUserQueryDto::user, UserScrapUserQueryDto::scrapStatus)); - // 모든 work를 가져와 최근 수정된 날짜 기준으로 정리 - List workAll = users.stream() - .flatMap(dto -> dto.user().getWorks().stream()) - .sorted(Comparator.comparing(Work::getModifiedAt).reversed()) - .toList(); - return workAll.stream().map((work) -> { - val userScrap = scrapMap.get(work.getUser().getId()); + return users.stream().map((dto) -> { + val firstWorkId = dto.user().getFirstWorkId(); + Work firstWork; + + if (firstWorkId == null && !dto.user().getActiveWorks().isEmpty()) { // User 권한 에러 + firstWork = workRepository.findFirstByUserIdAndIsActiveOrderByCreatedAtDesc(dto.user().getId(), true) + .orElse(Work.builder() + .user(dto.user()) + .photoUrl("해당하는 작업물을 찾을 수 없습니다.") + .detail("해당하는 작업물을 찾을 수 없습니다.") + .title("해당하는 작업물을 찾을 수 없습니다.") + .build()); + dto.user().setUserStatus(UserStatus.NOT_PERMITTED); + } + else { + firstWork = dto.user().getActiveWorks().stream() + .filter(work -> dto.user().getFirstWorkId().equals(work.getId())) + .findFirst().get(); + } + val userScrap = dto.scrapStatus(); if (Objects.isNull(userScrap)) { - return UserDiscoveryResponseDTO.of(work.getUser(), false, work); + return UserDiscoveryResponseDTO.of(dto.user(), false, firstWork); } - return UserDiscoveryResponseDTO.of(work.getUser(), userScrap, work); + return UserDiscoveryResponseDTO.of(dto.user(), userScrap, firstWork); }).collect(Collectors.toList()); } @@ -328,7 +339,7 @@ public void deleteUserAccount(Long userId, UserDeleteAccountRequestDTO userDelet public UserStatusResponseDTO getUserStatus(Long userId) { val user = findUser(userId); return UserStatusResponseDTO.of(user); - } + } @Transactional @Override