Skip to content

Commit

Permalink
refactor: OrderFilter#defaultValue를 추가하여 명시적으로 기본 값을 설정해주었습니다
Browse files Browse the repository at this point in the history
<description>
인자가 잘못 들어오는 경우(IllegalArgumentException)이 발생하는 경우에도 기본 값을 반환할 수 있도록 수정하였습니다.
  • Loading branch information
belljun3395 committed May 8, 2024
1 parent dd1fe99 commit e1962f1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions api/src/main/java/com/walking/api/web/dto/request/OrderFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
@Getter
public enum OrderFilter {
NAME("name"),
CREATEDAT("createdAt");
CREATEDAT("createdAt"),
;

private String field;

OrderFilter(String field) {
this.field = field;
}

private static OrderFilter defaultValue() {
return CREATEDAT;
}

/**
* 요청에 따라 정렬할 필드를 반환합니다.
*
Expand All @@ -22,8 +27,13 @@ public enum OrderFilter {
*/
public static OrderFilter ofRequest(String source) {
if (Objects.isNull(source) || source.isEmpty()) {
return CREATEDAT;
return defaultValue();
}

try {
return OrderFilter.valueOf(source.toUpperCase());
} catch (IllegalArgumentException e) {
return defaultValue();
}
return OrderFilter.valueOf(source.toUpperCase());
}
}

0 comments on commit e1962f1

Please sign in to comment.