Skip to content

Commit

Permalink
refactor(ExecutiveRetrievalService): 정렬 우선순위 관리를 enum에서 하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
SongJaeHoonn committed Jan 1, 2025
1 parent 649310b commit 6def65f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -13,6 +14,7 @@
import page.clab.api.domain.memberManagement.executive.application.port.in.RetrieveExecutiveUseCase;
import page.clab.api.domain.memberManagement.executive.application.port.out.RetrieveExecutivePort;
import page.clab.api.domain.memberManagement.executive.domain.Executive;
import page.clab.api.domain.memberManagement.position.domain.PositionType;
import page.clab.api.external.memberManagement.position.application.port.ExternalRetrievePositionUseCase;

@Service
Expand All @@ -22,11 +24,6 @@ public class ExecutiveRetrievalService implements RetrieveExecutiveUseCase {
private final RetrieveExecutivePort retrieveExecutivePort;
private final ExternalRetrievePositionUseCase externalRetrievePositionUseCase;
private final ExecutiveDtoMapper mapper;
private static final Map<String, Integer> PRIORITY = Map.of(
"PRESIDENT", 1,
"VICE_PRESIDENT", 2,
"OPERATION", 3
);

@Transactional(readOnly = true)
@Override
Expand All @@ -44,11 +41,16 @@ private List<Executive> sortExecutives(List<Executive> executives, Map<String, S
return executives.stream()
.sorted(Comparator
.comparing((Executive executive) ->
PRIORITY.getOrDefault(positionMap.get(executive.getId()), Integer.MAX_VALUE))
getPriority(positionMap.get(executive.getId())))
.thenComparing(Executive::getId))
.toList();
}

private int getPriority(String positionKey) {
return Optional.ofNullable(PositionType.getPriorityByKey(positionKey))
.orElse(Integer.MAX_VALUE);
}

private Map<String, String> getPositionMap(List<Executive> executives) {
return executives.stream()
.collect(Collectors.toMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@
@AllArgsConstructor
public enum PositionType {

PRESIDENT("PRESIDENT", "회장"),
VICE_PRESIDENT("VICE_PRESIDENT", "부회장"),
OPERATION("OPERATION", "운영진"),
CORE_TEAM("CORE_TEAM", "코어팀"),
MEMBER("MEMBER", "일반회원");
PRESIDENT("PRESIDENT", "회장", 1),
VICE_PRESIDENT("VICE_PRESIDENT", "부회장", 2),
OPERATION("OPERATION", "운영진", 3),
CORE_TEAM("CORE_TEAM", "코어팀", null),
MEMBER("MEMBER", "일반회원", null);

@Enumerated(EnumType.STRING)
private final String key;
private final String description;
private final Integer priority;

public static Integer getPriorityByKey(String key) {
for (PositionType positionType : values()) {
if (positionType.getKey().equals(key)) {
return positionType.getPriority();
}
}
throw new IllegalArgumentException("Invalid PositionType key: " + key);
}
}

0 comments on commit 6def65f

Please sign in to comment.