Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 카테고리 목록 반환 API #49

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}