diff --git a/src/main/java/com/gamsa/activity/constant/Category.java b/src/main/java/com/gamsa/activity/constant/Category.java index 561983f..848c0cf 100644 --- a/src/main/java/com/gamsa/activity/constant/Category.java +++ b/src/main/java/com/gamsa/activity/constant/Category.java @@ -1,5 +1,7 @@ package com.gamsa.activity.constant; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -15,4 +17,28 @@ public enum Category { OTHER_ACTIVITIES("기타 활동"); private final String name; + + @JsonCreator + public static Category fromValues(String value) { + for (Category category : Category.values()) { + if (category.getName().equals(value)) { + return category; + } + } + throw new IllegalArgumentException("Unknown value: " + value); + } + + public static Category fromValuesForSlice(String value) { + for (Category category : Category.values()) { + if (category.getName().equals(value)) { + return category; + } + } + return null; // QueryDSL 에서는 null일 경우 필터링에서 제외하므로 null 반환 허용 + } + + @JsonValue + public String toValue() { + return this.name; + } } diff --git a/src/main/java/com/gamsa/activity/controller/ActivityController.java b/src/main/java/com/gamsa/activity/controller/ActivityController.java index 6da07fc..13e3fa5 100644 --- a/src/main/java/com/gamsa/activity/controller/ActivityController.java +++ b/src/main/java/com/gamsa/activity/controller/ActivityController.java @@ -28,7 +28,7 @@ public class ActivityController { @GetMapping public Slice findSlice( - @RequestParam(required = false) Category category, + @RequestParam(required = false) String category, @RequestParam(required = false) Integer sidoGunguCode, @RequestParam(required = false) Integer sidoCode, @RequestParam(defaultValue = "false") boolean teenPossibleOnly, @@ -36,7 +36,7 @@ public Slice findSlice( Pageable pageable) { ActivityFilterRequest request = ActivityFilterRequest.builder() - .category(category) + .category(Category.fromValuesForSlice(category)) .sidoGunguCode(sidoGunguCode) .sidoCode(sidoCode) .teenPossibleOnly(teenPossibleOnly) diff --git a/src/main/java/com/gamsa/activity/controller/CategoryController.java b/src/main/java/com/gamsa/activity/controller/CategoryController.java new file mode 100644 index 0000000..0a36aa5 --- /dev/null +++ b/src/main/java/com/gamsa/activity/controller/CategoryController.java @@ -0,0 +1,17 @@ +package com.gamsa.activity.controller; + +import com.gamsa.activity.constant.Category; +import java.util.List; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1/activities/categories") +public class CategoryController { + + @GetMapping + public List findAllCategories() { + return List.of(Category.values()); + } +}