From 674ff15d8ed3f6f3986f106743cc6c348317e5c1 Mon Sep 17 00:00:00 2001 From: 5win <94297900+5win@users.noreply.github.com> Date: Wed, 30 Oct 2024 20:09:59 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EB=B0=98=ED=99=98=20API=20(#49)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 카테고리 목록 반환 API 생성 - 클라이언트와 주고받는 카테고리명 한글로 수정 --- .../com/gamsa/activity/constant/Category.java | 26 +++++++++++++++++++ .../controller/ActivityController.java | 4 +-- .../controller/CategoryController.java | 17 ++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/gamsa/activity/controller/CategoryController.java 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()); + } +}