Skip to content

Commit

Permalink
Merge pull request #13 from depth-rolling-paper/develop
Browse files Browse the repository at this point in the history
feat: 3차 QA 수정사항 반영
  • Loading branch information
phonil authored Dec 23, 2023
2 parents aa4126a + 0968c62 commit 8586a1b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -185,22 +186,31 @@ public ResponseEntity<?> findUsersExclusionMe(Long userId, String roomUrl) {

User user = userById.get();

List<User> users = userRepository.findAllByRoom(room);
List<User> allUsersInRoom = userRepository.findAllByRoom(room);
List<UserRes> exclusiveMe = new ArrayList<>();

for (User userInRoom : users) {
for (User userInRoom : allUsersInRoom) {
if (userInRoom.getId() == userId)
continue;

// userId를 기준으로 뒤쪽으로 회전시키기 위한 offset 계산
int offset = (int) (userInRoom.getId() - userId);

// 겹치지 않게 sequence를 조합
int newSequence = (offset > 0) ? offset : allUsersInRoom.size() + offset;

UserRes userRes = UserRes.builder()
.id(userInRoom.getId())
.userName(userInRoom.getUserName())
.userType(userInRoom.getUserType())
.sequence(newSequence)
.build();

exclusiveMe.add(userRes);
}

exclusiveMe.sort(Comparator.comparing(UserRes::getSequence));

ExclusionMeRes exclusionMeRes = ExclusionMeRes.builder()
.users(exclusiveMe)
.message("본인 제외 현재 방 내 유저 목록")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ public class UserRes {

private UserType userType;

private Integer sequence;

@Builder
public UserRes(Long id, String userName, UserType userType) {
public UserRes(Long id, String userName, UserType userType, Integer sequence) {
this.id = id;
this.userName = userName;
this.userType = userType;
this.sequence = sequence;
}
}

0 comments on commit 8586a1b

Please sign in to comment.