Skip to content

Commit

Permalink
[feat] #58 add promise participant list sorting (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaewonni authored Jul 15, 2024
1 parent 6ba0be4 commit e43d8b4
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -97,11 +98,12 @@ public PreparationStatusDto getPreparation(
@Transactional(readOnly = true)
public ParticipantsDto getParticipants(final Long promiseId) {
List<ParticipantStatusUserInfoDto> participants = participantRetriever.findAllByPromiseIdWithUserInfo(promiseId);
return ParticipantsDto.from(
participants.stream()
.map(this::createParticipantDto)
.collect(Collectors.toList())
);
List<ParticipantDto> sortedParticipants = participants.stream()
.map(this::createParticipantDto)
.sorted(Comparator.comparing(ParticipantDto::state, Comparator.comparingInt(this::stateOrder)))
.collect(Collectors.toList());

return ParticipantsDto.from(sortedParticipants);
}

@Transactional
Expand Down Expand Up @@ -186,4 +188,14 @@ private String determineState(
}
return "꾸물중";
}

private int stateOrder(String state) {
switch(state) {
case "도착": return 1;
case "이동중": return 2;
case "준비중": return 3;
case "꾸물중": return 4;
default: return 5;
}
}
}

0 comments on commit e43d8b4

Please sign in to comment.