diff --git a/src/main/java/com/groom/orbit/common/exception/ErrorCode.java b/src/main/java/com/groom/orbit/common/exception/ErrorCode.java index 74ca045..f0cabbb 100644 --- a/src/main/java/com/groom/orbit/common/exception/ErrorCode.java +++ b/src/main/java/com/groom/orbit/common/exception/ErrorCode.java @@ -22,6 +22,7 @@ public enum ErrorCode { NOT_FOUND_SCHEDULE(40405, HttpStatus.NOT_FOUND, "해당 일정이 존재하지 않습니다."), NOT_FOUND_S3(40406, HttpStatus.NOT_FOUND, "해당 파일을 찾을 수 없습니다."), NOT_FOUND_QUEST(40407, HttpStatus.NOT_FOUND, "해당 퀘스트가 존재하지 않습니다."), + NOT_FOUND_GOAL_CATEGORY(40408, HttpStatus.NOT_FOUND, "해당 목표 카테고리가 존재하지 않습니다."), // Invalid Argument Error MISSING_REQUEST_PARAMETER(40000, HttpStatus.BAD_REQUEST, "필수 요청 파라미터가 누락되었습니다."), diff --git a/src/main/java/com/groom/orbit/goal/app/GoalQueryService.java b/src/main/java/com/groom/orbit/goal/app/GoalQueryService.java new file mode 100644 index 0000000..e30fda3 --- /dev/null +++ b/src/main/java/com/groom/orbit/goal/app/GoalQueryService.java @@ -0,0 +1,19 @@ +package com.groom.orbit.goal.app; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.groom.orbit.goal.app.dto.GetGoalCategoryResponseDto; +import com.groom.orbit.goal.dao.entity.GoalCategory; + +import lombok.RequiredArgsConstructor; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class GoalQueryService { + + public GetGoalCategoryResponseDto getGoalCategory() { + return new GetGoalCategoryResponseDto(GoalCategory.getAll()); + } +} diff --git a/src/main/java/com/groom/orbit/goal/app/dto/GetGoalCategoryResponseDto.java b/src/main/java/com/groom/orbit/goal/app/dto/GetGoalCategoryResponseDto.java new file mode 100644 index 0000000..a164874 --- /dev/null +++ b/src/main/java/com/groom/orbit/goal/app/dto/GetGoalCategoryResponseDto.java @@ -0,0 +1,5 @@ +package com.groom.orbit.goal.app.dto; + +import java.util.List; + +public record GetGoalCategoryResponseDto(List categories) {} diff --git a/src/main/java/com/groom/orbit/goal/app/util/GoalConst.java b/src/main/java/com/groom/orbit/goal/app/util/GoalConst.java new file mode 100644 index 0000000..d6939d7 --- /dev/null +++ b/src/main/java/com/groom/orbit/goal/app/util/GoalConst.java @@ -0,0 +1,10 @@ +package com.groom.orbit.goal.app.util; + +import java.util.List; + +public class GoalConst { + + private GoalConst() {} + + public static final List GOAL_CATEGORY = List.of("자격·어학·수상", "경험·활동·교육", "경력", "기타"); +} diff --git a/src/main/java/com/groom/orbit/goal/controller/GoalQueryController.java b/src/main/java/com/groom/orbit/goal/controller/GoalQueryController.java new file mode 100644 index 0000000..9fa91be --- /dev/null +++ b/src/main/java/com/groom/orbit/goal/controller/GoalQueryController.java @@ -0,0 +1,24 @@ +package com.groom.orbit.goal.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.groom.orbit.common.dto.ResponseDto; +import com.groom.orbit.goal.app.GoalQueryService; +import com.groom.orbit.goal.app.dto.GetGoalCategoryResponseDto; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/goal") +public class GoalQueryController { + + private final GoalQueryService goalQueryService; + + @GetMapping("/categories") + public ResponseDto getCategories() { + return ResponseDto.ok(goalQueryService.getGoalCategory()); + } +} diff --git a/src/main/java/com/groom/orbit/goal/dao/entity/Goal.java b/src/main/java/com/groom/orbit/goal/dao/entity/Goal.java index c65e367..497f772 100644 --- a/src/main/java/com/groom/orbit/goal/dao/entity/Goal.java +++ b/src/main/java/com/groom/orbit/goal/dao/entity/Goal.java @@ -2,6 +2,8 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -25,7 +27,8 @@ public class Goal { private String title; @Column(nullable = false, length = 10) - private String category; + @Enumerated(EnumType.STRING) + private GoalCategory category; @ColumnDefault("0") @Column(nullable = false) @@ -34,7 +37,7 @@ public class Goal { public static Goal create(String title, String category) { Goal goal = new Goal(); goal.title = title; - goal.category = category; + goal.category = GoalCategory.from(category); return goal; } diff --git a/src/main/java/com/groom/orbit/goal/dao/entity/GoalCategory.java b/src/main/java/com/groom/orbit/goal/dao/entity/GoalCategory.java new file mode 100644 index 0000000..ab68714 --- /dev/null +++ b/src/main/java/com/groom/orbit/goal/dao/entity/GoalCategory.java @@ -0,0 +1,35 @@ +package com.groom.orbit.goal.dao.entity; + +import java.util.Arrays; +import java.util.List; + +import com.groom.orbit.common.exception.CommonException; +import com.groom.orbit.common.exception.ErrorCode; + +public enum GoalCategory { + CERTIFICATION("자격·어학·수상"), + EXPERIENCE("경험·활동·교육"), + CAREER("경력"), + ETC("기타"); + + private String category; + + GoalCategory(String category) { + this.category = category; + } + + public String getCategory() { + return category; + } + + public static GoalCategory from(String category) { + return Arrays.stream(GoalCategory.values()) + .filter(goalCategory -> goalCategory.getCategory().equals(category)) + .findFirst() + .orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_GOAL_CATEGORY)); + } + + public static List getAll() { + return Arrays.stream(GoalCategory.values()).map(GoalCategory::getCategory).toList(); + } +}