Skip to content

Commit

Permalink
feat: 카테고리 목록 반환 API (#49)
Browse files Browse the repository at this point in the history
- 카테고리 목록 반환 API 생성
- 클라이언트와 주고받는 카테고리명 한글로 수정
  • Loading branch information
5win authored Oct 30, 2024
1 parent f0045bf commit 674ff15
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/main/java/com/gamsa/activity/constant/Category.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class ActivityController {

@GetMapping
public Slice<ActivityFindSliceResponse> 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,
@RequestParam(defaultValue = "false") boolean beforeDeadlineOnly,
Pageable pageable) {

ActivityFilterRequest request = ActivityFilterRequest.builder()
.category(category)
.category(Category.fromValuesForSlice(category))
.sidoGunguCode(sidoGunguCode)
.sidoCode(sidoCode)
.teenPossibleOnly(teenPossibleOnly)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Category> findAllCategories() {
return List.of(Category.values());
}
}

0 comments on commit 674ff15

Please sign in to comment.