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: goal category 조회 api #90

Merged
merged 2 commits into from
Nov 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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, "필수 요청 파라미터가 누락되었습니다."),
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/groom/orbit/goal/app/GoalQueryService.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.groom.orbit.goal.app.dto;

import java.util.List;

public record GetGoalCategoryResponseDto(List<String> categories) {}
10 changes: 10 additions & 0 deletions src/main/java/com/groom/orbit/goal/app/util/GoalConst.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.groom.orbit.goal.app.util;

import java.util.List;

public class GoalConst {

private GoalConst() {}

public static final List<String> GOAL_CATEGORY = List.of("자격·어학·수상", "경험·활동·교육", "경력", "기타");
}
Original file line number Diff line number Diff line change
@@ -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<GetGoalCategoryResponseDto> getCategories() {
return ResponseDto.ok(goalQueryService.getGoalCategory());
}
}
7 changes: 5 additions & 2 deletions src/main/java/com/groom/orbit/goal/dao/entity/Goal.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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;
}
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/groom/orbit/goal/dao/entity/GoalCategory.java
Original file line number Diff line number Diff line change
@@ -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<String> getAll() {
return Arrays.stream(GoalCategory.values()).map(GoalCategory::getCategory).toList();
}
}
Loading