Skip to content

Commit

Permalink
fix: 발견-유저 return 값 롤백 (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjy-asl authored Jun 8, 2024
1 parent 2c7b044 commit a3df2f5
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/main/java/com/gam/api/domain/user/service/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public List<UserResponseDTO> getPopularDesigners(Long userId) { //TODO - 쿼리
return UserResponseDTO.of(user, userScrap.isStatus());
}
return UserResponseDTO.of(user, false);
}).collect(Collectors.toList());
}).collect(Collectors.toList());
}

@Override
Expand Down Expand Up @@ -284,27 +284,38 @@ public WorkPortfolioGetResponseDTO getPortfolio(Long requestUserId, Long userId)
public List<UserDiscoveryResponseDTO> getDiscoveryUsers(Long userId, int[] tags){
List<UserScrapUserQueryDto> users;

if (tags.length == 0) { // user 정보 조회 태그가 걸린 경우와 아닌 경우
if (tags.length == 0) {
users = userRepository.findAllDiscoveryUser(userId); //TODO - user 관련 쿼리 잡기 , 동적 쿼리 필요,,
}
else {
users = userRepository.findAllDiscoveryUserWithTag(userId, tags);
}

Map<User, Boolean> scrapMap = users.stream()
.collect(Collectors.toMap(UserScrapUserQueryDto::user, UserScrapUserQueryDto::scrapStatus));
// 모든 work를 가져와 최근 수정된 날짜 기준으로 정리
List<Work> 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());
}

Expand All @@ -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
Expand Down

0 comments on commit a3df2f5

Please sign in to comment.