Skip to content

Commit 2ecd5a0

Browse files
authored
[T3-106] 감정구슬 테이블 구축, API 개발 (#24)
* feat: 감정구슬 테이블 구축, API 개발 * chore: 감정구슬 case 매 * remove: 불필요한 주석 제거 * remove: caseName 필드 삭제
1 parent 61aa1c4 commit 2ecd5a0

14 files changed

Lines changed: 392 additions & 24 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.controller;
2+
3+
import bitnagil.bitnagil_backend.emotionMarble.controller.spec.EmotionMarbleSpec;
4+
import bitnagil.bitnagil_backend.emotionMarble.domain.EmotionMarble;
5+
import bitnagil.bitnagil_backend.emotionMarble.domain.enums.EmotionMarbleType;
6+
import bitnagil.bitnagil_backend.emotionMarble.request.RegisterEmotionMarbleRequest;
7+
import bitnagil.bitnagil_backend.emotionMarble.response.EmotionMarbleTypeResponse;
8+
import bitnagil.bitnagil_backend.emotionMarble.response.RegisterEmotionMarbleResponse;
9+
import bitnagil.bitnagil_backend.emotionMarble.service.EmotionMarbleService;
10+
import bitnagil.bitnagil_backend.global.annotation.CurrentUser;
11+
import bitnagil.bitnagil_backend.global.response.CustomResponseDto;
12+
import bitnagil.bitnagil_backend.user.domain.User;
13+
import lombok.RequiredArgsConstructor;
14+
import org.springframework.web.bind.annotation.*;
15+
16+
@RestController
17+
@RequiredArgsConstructor
18+
@RequestMapping(value = "/api/v1/emotion-marbles")
19+
public class EmotionMarbleController implements EmotionMarbleSpec {
20+
private final EmotionMarbleService emotionMarbleService;
21+
22+
// 감정구슬 조회 API
23+
@GetMapping("")
24+
public CustomResponseDto<EmotionMarbleTypeResponse> getEmotionMarbles() {
25+
return CustomResponseDto.from(emotionMarbleService.getEmotionMarbles());
26+
}
27+
28+
// 감정구슬 등록 API
29+
@PostMapping("")
30+
public CustomResponseDto<RegisterEmotionMarbleResponse> registryEmotionMarble(@CurrentUser User user, @RequestBody RegisterEmotionMarbleRequest request) {
31+
return CustomResponseDto.from(emotionMarbleService.registryEmotionMarble(user, request));
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.controller.spec;
2+
3+
import bitnagil.bitnagil_backend.emotionMarble.request.RegisterEmotionMarbleRequest;
4+
import bitnagil.bitnagil_backend.emotionMarble.response.EmotionMarbleTypeResponse;
5+
import bitnagil.bitnagil_backend.emotionMarble.response.RegisterEmotionMarbleResponse;
6+
import bitnagil.bitnagil_backend.global.errorcode.ErrorCode;
7+
import bitnagil.bitnagil_backend.global.response.CustomResponseDto;
8+
import bitnagil.bitnagil_backend.global.swagger.ApiErrorCodeExamples;
9+
import bitnagil.bitnagil_backend.global.swagger.ApiTags;
10+
import bitnagil.bitnagil_backend.user.domain.User;
11+
import io.swagger.v3.oas.annotations.Operation;
12+
import io.swagger.v3.oas.annotations.tags.Tag;
13+
14+
@Tag(name = ApiTags.EMOTION_MARBLE)
15+
public interface EmotionMarbleSpec {
16+
17+
@Operation(summary = "감정 구슬을 조회합니다")
18+
public CustomResponseDto<EmotionMarbleTypeResponse> getEmotionMarbles();
19+
20+
@Operation(summary = "감정 구슬을 등록합니다. 감정 구슬에 따른 추천 루틴을 응답합니다.")
21+
@ApiErrorCodeExamples({ErrorCode.NOT_FOUND_RECOMMENDED_ROUTINE})
22+
public CustomResponseDto<RegisterEmotionMarbleResponse> registryEmotionMarble(User user, RegisterEmotionMarbleRequest request);
23+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.domain;
2+
3+
import bitnagil.bitnagil_backend.emotionMarble.domain.enums.EmotionMarbleType;
4+
import bitnagil.bitnagil_backend.global.entity.BaseTimeEntity;
5+
import bitnagil.bitnagil_backend.global.entity.HistoryPk;
6+
import bitnagil.bitnagil_backend.onboarding.domain.Case;
7+
import jakarta.persistence.*;
8+
import jakarta.validation.constraints.NotNull;
9+
import lombok.AccessLevel;
10+
import lombok.Builder;
11+
import lombok.Getter;
12+
import lombok.NoArgsConstructor;
13+
14+
import java.time.LocalDate;
15+
import java.time.LocalDateTime;
16+
import java.util.UUID;
17+
18+
@Getter
19+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
20+
@Entity
21+
public class EmotionMarble extends BaseTimeEntity {
22+
23+
@EmbeddedId
24+
@AttributeOverrides({
25+
@AttributeOverride(name = "id", column = @Column(name = "emotion_marble_id")),
26+
@AttributeOverride(name = "historySeq", column = @Column(name = "history_seq"))
27+
})
28+
private HistoryPk emotionMarblePk;
29+
30+
@NotNull
31+
@Enumerated(EnumType.STRING)
32+
@Column(columnDefinition = "varchar(40)")
33+
private EmotionMarbleType emotionMarbleType;
34+
35+
@NotNull
36+
private LocalDate date;
37+
38+
@NotNull
39+
private UUID userId;
40+
41+
@NotNull
42+
private LocalDateTime historyStartDateTime;
43+
44+
@NotNull
45+
private LocalDateTime historyEndDateTime;
46+
47+
@ManyToOne(fetch = FetchType.LAZY)
48+
@JoinColumn(name = "case_id", nullable = false)
49+
private Case resultCase;
50+
51+
@Builder
52+
public EmotionMarble(HistoryPk emotionMarblePk, EmotionMarbleType emotionMarbleType, LocalDate date, UUID userId,
53+
LocalDateTime historyStartDateTime, LocalDateTime historyEndDateTime, Case resultCase) {
54+
this.emotionMarblePk = emotionMarblePk;
55+
this.emotionMarbleType = emotionMarbleType;
56+
this.date = date;
57+
this.userId = userId;
58+
this.historyStartDateTime = historyStartDateTime;
59+
this.historyEndDateTime = historyEndDateTime;
60+
this.resultCase = resultCase;
61+
}
62+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.domain.enums;
2+
3+
import bitnagil.bitnagil_backend.enums.EnumType;
4+
import lombok.Getter;
5+
import lombok.RequiredArgsConstructor;
6+
7+
@RequiredArgsConstructor
8+
@Getter
9+
public enum EmotionMarbleType implements EnumType {
10+
CALM("평온함", 5L),
11+
VITALITY("활기참", 6L),
12+
LETHARGY("무기력함", 7L),
13+
ANXIETY("불안함", 8L),
14+
SATISFACTION("만족함", 9L),
15+
FATIGUE("피로함", 10L)
16+
;
17+
18+
private final String description;
19+
private final Long caseId;
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.repository;
2+
3+
import bitnagil.bitnagil_backend.emotionMarble.domain.EmotionMarble;
4+
import bitnagil.bitnagil_backend.global.entity.HistoryPk;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
7+
public interface EmotionMarbleRepository extends JpaRepository<EmotionMarble, HistoryPk> {
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.request;
2+
3+
import bitnagil.bitnagil_backend.emotionMarble.domain.enums.EmotionMarbleType;
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
import jakarta.validation.constraints.NotNull;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* 감정구슬의 종류를 조회하는 dto 입니다.
11+
*/
12+
@Getter
13+
@NoArgsConstructor
14+
@Schema(description = "감정구슬 등록 요청 DTO")
15+
public class RegisterEmotionMarbleRequest {
16+
17+
@Schema(description = "감정구술 enum 값",
18+
example = "CALM", required = true)
19+
@NotNull
20+
private EmotionMarbleType emotionMarbleType;
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.response;
2+
3+
import bitnagil.bitnagil_backend.emotionMarble.domain.enums.EmotionMarbleType;
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
7+
import lombok.Getter;
8+
9+
@Getter
10+
@AllArgsConstructor
11+
@Builder
12+
@Schema(description = "감정 구슬 조회 DTO")
13+
public class EmotionMarbleTypeResponse {
14+
@Schema(
15+
description = "감정 구슬 enum 배열",
16+
type = "array",
17+
example = "[\"CALM\", \"VITALITY\", \"LETHARGY\", \"ANXIETY\", \"SATISFACTION\", \"FATIGUE\"]"
18+
)
19+
private EmotionMarbleType[] emotionMarbleTypes;
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.response;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
7+
import java.util.List;
8+
9+
/**
10+
* 추천 루틴에 대한 DTO 클래스
11+
*/
12+
@Getter
13+
@AllArgsConstructor
14+
@Builder
15+
public class RecommendedRoutineDto {
16+
17+
// 추천 루틴 ID
18+
private Long recommendedRoutineId;
19+
// 추천 루틴 이름
20+
private String recommendedRoutineName;
21+
// 추천 루틴 설명
22+
private String routineDescription;
23+
24+
// 추천 루틴 상세 정보
25+
List<RecommendedSubRoutineDto> recommendedSubRoutines;
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.response;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
7+
/**
8+
* 추천 루틴 상세에 대한 DTO 클래스
9+
*/
10+
@Getter
11+
@AllArgsConstructor
12+
@Builder
13+
public class RecommendedSubRoutineDto {
14+
// 추천 루틴 상세 ID
15+
private Long recommendedSubRoutineId;
16+
// 추천 루틴 상세 이름
17+
private String recommendedSubRoutineName;
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package bitnagil.bitnagil_backend.emotionMarble.response;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
8+
import java.util.List;
9+
10+
/**
11+
* 구슬 선택에 대한 추천 루틴 응답 DTO 클래스
12+
*/
13+
@Getter
14+
@AllArgsConstructor
15+
@Builder
16+
@Schema(description = "감정 구슬 등록 응답 DTO")
17+
public class RegisterEmotionMarbleResponse {
18+
19+
private List<RecommendedRoutineDto> recommendedRoutines;
20+
21+
}

0 commit comments

Comments
 (0)