Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 발견-유저 return 값 롤백 #184

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading