Skip to content

Commit 61aa1c4

Browse files
authored
[T3-98] 루틴 조회 API 수정 (#23)
* feat: 변경 구분코드 추가 * feat: 루틴 조회 API * feat: 수정여부 컬럼 추가 * chore: 1차 배포 최종 init sql * fix: ddl 변경에 따른 수 * fix: ddl 변경에 따른 수정 * fix: 온보딩 API 수 * fix: 루틴 조회 쿼리파라미터로 수정 * fix: 홈 루틴 조회 API 수정
1 parent c9002d8 commit 61aa1c4

26 files changed

Lines changed: 1491 additions & 615 deletions

src/main/java/bitnagil/bitnagil_backend/changedRoutine/domain/ChangedRoutine.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package bitnagil.bitnagil_backend.changedRoutine.domain;
22

3+
import bitnagil.bitnagil_backend.changedRoutine.domain.enums.ChangedDivCode;
34
import bitnagil.bitnagil_backend.global.entity.BaseTimeEntity;
45
import bitnagil.bitnagil_backend.global.entity.HistoryPk;
5-
import bitnagil.bitnagil_backend.routine.domain.Routine;
6-
import bitnagil.bitnagil_backend.user.domain.User;
76
import jakarta.persistence.*;
87
import jakarta.validation.constraints.NotNull;
98
import lombok.AccessLevel;
@@ -14,6 +13,7 @@
1413
import java.time.LocalDate;
1514
import java.time.LocalDateTime;
1615
import java.time.LocalTime;
16+
import java.util.UUID;
1717

1818
/**
1919
* 규칙적인 류틴에 대해 일시적인 변경이 발생한 루틴에 대해 관리하는 엔티티입니다.
@@ -49,33 +49,29 @@ public class ChangedRoutine extends BaseTimeEntity {
4949
@NotNull
5050
private LocalDateTime historyEndDateTime; // 이력 종료일시
5151

52-
@ManyToOne(fetch = FetchType.LAZY)
53-
@JoinColumns({
54-
@JoinColumn(name = "user_id", referencedColumnName = "user_id"),
55-
@JoinColumn(name = "user_history_seq", referencedColumnName = "history_seq")
56-
})
52+
@Enumerated(EnumType.STRING)
53+
@Column(columnDefinition = "varchar(40)")
54+
private ChangedDivCode changedDivCode; // 변경 구분 코드 (시간 변경, 내일 미루기, 오늘만 루틴 삭제 등)
55+
5756
@NotNull
58-
private User user;
57+
private UUID userId;
5958

60-
@ManyToOne(fetch = FetchType.LAZY)
61-
@JoinColumns({
62-
@JoinColumn(name = "routine_id", referencedColumnName = "routine_id"),
63-
@JoinColumn(name = "routine_history_seq", referencedColumnName = "history_seq")
64-
})
65-
private Routine routine; // 원본 루틴
59+
private UUID routineId;
6660

6761
@Builder
6862
public ChangedRoutine(HistoryPk changedRoutinePk, String changedRoutineName, LocalTime changedExecutionTime,
6963
LocalDate originalRoutineDate, LocalDate changedRoutineDate, LocalDateTime historyStartDateTime,
70-
LocalDateTime historyEndDateTime, User user, Routine routine) {
64+
LocalDateTime historyEndDateTime, UUID userId, UUID routineId, ChangedDivCode changedDivCode) {
7165
this.changedRoutinePk = changedRoutinePk;
7266
this.changedRoutineName = changedRoutineName;
7367
this.changedExecutionTime = changedExecutionTime;
7468
this.originalRoutineDate = originalRoutineDate;
7569
this.changedRoutineDate = changedRoutineDate;
7670
this.historyStartDateTime = historyStartDateTime;
7771
this.historyEndDateTime = historyEndDateTime;
78-
this.user = user;
79-
this.routine = routine;
72+
this.changedDivCode = changedDivCode;
73+
this.userId = userId;
74+
this.routineId = routineId;
8075
}
76+
8177
}

src/main/java/bitnagil/bitnagil_backend/changedRoutine/domain/ChangedSubRoutine.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import lombok.NoArgsConstructor;
1111

1212
import java.time.LocalDateTime;
13+
import java.util.UUID;
1314

1415
@Getter
1516
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@@ -32,13 +33,22 @@ public class ChangedSubRoutine extends BaseTimeEntity {
3233
@NotNull
3334
private LocalDateTime historyEndDateTime;
3435

36+
@NotNull
37+
private UUID changedRoutineId; // 변경된 루틴 ID
38+
39+
@NotNull
40+
private Integer sortOrder; // 변경서브루틴의 순서를 나타내는 필드
41+
3542

3643
@Builder
3744
public ChangedSubRoutine(HistoryPk changedSubRoutinePk, String changedSubRoutineName,
38-
LocalDateTime historyStartDateTime, LocalDateTime historyEndDateTime) {
45+
LocalDateTime historyStartDateTime, LocalDateTime historyEndDateTime, UUID changedRoutineId,
46+
Integer sortOrder) {
3947
this.changedSubRoutinePk = changedSubRoutinePk;
4048
this.changedSubRoutineName = changedSubRoutineName;
4149
this.historyStartDateTime = historyStartDateTime;
4250
this.historyEndDateTime = historyEndDateTime;
51+
this.changedRoutineId = changedRoutineId;
52+
this.sortOrder = sortOrder;
4353
}
4454
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package bitnagil.bitnagil_backend.changedRoutine.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 ChangedDivCode implements EnumType {
10+
TODAY_CHANGE("당일 변경(ex: 루틴명, 세부루틴명, 실행시간 등)"),
11+
DELAY("미루기"),
12+
TODAY_DELETE("오늘만 루틴 삭제"),
13+
ONBOARDING("온보딩 루틴")
14+
;
15+
16+
private final String description;
17+
}

src/main/java/bitnagil/bitnagil_backend/changedRoutine/repository/ChangedRoutineRepository.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,22 @@
55

66
import org.springframework.data.jpa.repository.JpaRepository;
77

8+
import java.time.LocalDate;
9+
import java.time.LocalDateTime;
10+
import java.util.List;
11+
import java.util.UUID;
12+
813
public interface ChangedRoutineRepository extends JpaRepository<ChangedRoutine, HistoryPk> {
14+
15+
/**
16+
* 현재 시점을 기준으로 유저의 살아있는 변경루틴 이력을 조회
17+
* historyStartDateTime < systime <= historyEndDateTime
18+
*/
19+
List<ChangedRoutine> findByUserIdAndHistoryStartDateTimeBeforeAndHistoryEndDateTimeGreaterThanEqualAndChangedRoutineDateBetween(
20+
UUID userId,
21+
LocalDateTime now1,
22+
LocalDateTime now2,
23+
LocalDate startDate,
24+
LocalDate endDate
25+
);
926
}

src/main/java/bitnagil/bitnagil_backend/changedRoutine/repository/ChangedSubRoutineRepository.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,19 @@
55

66
import org.springframework.data.jpa.repository.JpaRepository;
77

8+
import java.time.LocalDateTime;
9+
import java.util.List;
10+
import java.util.UUID;
11+
812
public interface ChangedSubRoutineRepository extends JpaRepository<ChangedSubRoutine, HistoryPk> {
13+
14+
/**
15+
* 현재 시점을 기준으로 살아있는 변경 서브루틴 이력을 조회
16+
* historyStartDateTime < systime <= historyEndDateTime
17+
*/
18+
List<ChangedSubRoutine> findByChangedRoutineIdAndHistoryStartDateTimeBeforeAndHistoryEndDateTimeGreaterThanEqual(
19+
UUID changedRoutineId,
20+
LocalDateTime now1,
21+
LocalDateTime now2
22+
);
923
}

src/main/java/bitnagil/bitnagil_backend/global/exception/CustomException.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
import bitnagil.bitnagil_backend.global.errorcode.ErrorCode;
44
import lombok.Getter;
5-
import lombok.RequiredArgsConstructor;
65

76
/**
87
* 커스텀 에외 클래스. 해당 클래스로 예외를 던져서 예외처리를 한다.
98
*/
109
@Getter
11-
@RequiredArgsConstructor
1210
public class CustomException extends RuntimeException {
1311

1412
private final ErrorCode errorCode;
1513

14+
public CustomException(ErrorCode errorCode) {
15+
super(errorCode.getMessage()); // ← 메시지 설정
16+
this.errorCode = errorCode;
17+
}
18+
19+
public ErrorCode getErrorCode() {
20+
return errorCode;
21+
}
1622
}

src/main/java/bitnagil/bitnagil_backend/onboarding/domain/Onboarding.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import lombok.Getter;
99
import lombok.NoArgsConstructor;
1010

11+
import java.time.LocalTime;
12+
1113
@Getter
1214
@NoArgsConstructor(access = AccessLevel.PROTECTED)
1315
@Entity
@@ -17,10 +19,10 @@ public class Onboarding extends BaseTimeEntity {
1719
@GeneratedValue(strategy = GenerationType.IDENTITY)
1820
private Long onboardingId;
1921

20-
@Enumerated(EnumType.STRING)
21-
@Column(columnDefinition = "varchar(40)") // mysql의 enum 타입을 사용하지 않도록 설정
22+
// @Enumerated(EnumType.STRING)
23+
// @Column(columnDefinition = "varchar(40)") // mysql의 enum 타입을 사용하지 않도록 설정
2224
@NotNull
23-
private TimeSlot timeSlot;
25+
private LocalTime timeSlot;
2426

2527
@Enumerated(EnumType.STRING)
2628
@Column(columnDefinition = "varchar(40)")

src/main/java/bitnagil/bitnagil_backend/onboarding/domain/enums/RealOutingFrequency.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
@RequiredArgsConstructor
88
@Getter
99
public enum RealOutingFrequency implements EnumType {
10-
ZERO_PER_WEEK("일주일 0회"),
11-
ONE_TO_TWO_PER_WEEK("일주일 1~2회"),
12-
THREE_TO_FOUR_PER_WEEK("일주일 3~4회"),
13-
MORE_THAN_FIVE_PER_WEEK("일주일 5회 이상"),
10+
11+
OFTEN("자주 외출해요"),
12+
SOMETIMES("가끔 나가요"),
13+
NEVER("밖에 나가지 않고 집에만 있어요"),
14+
SHORT("잠깐 외출했어요");
1415
;
1516

1617
private final String description;

src/main/java/bitnagil/bitnagil_backend/onboarding/domain/enums/TargetOutingFrequency.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
@RequiredArgsConstructor
88
@Getter
99
public enum TargetOutingFrequency implements EnumType {
10-
ONE_TO_TWO_PER_WEEK("일주일 1~2회"),
11-
THREE_TO_FOUR_PER_WEEK("일주일 3~4회"),
12-
MORE_THAN_FIVE_PER_WEEK("일주일 5회 이상"),
13-
UNKNOWN("아직 잘 모르겠어요"),
10+
11+
ONE_PER_WEEK("일주일 1회"),
12+
TWO_TO_THREE_PER_WEEK("일주일 2~3회"),
13+
MORE_THAN_FOUR_PER_WEEK("일주일 4회 이상"),
14+
UNKNOW("아직 잘 모르겠어요"),
1415
;
1516

1617
private final String description;

src/main/java/bitnagil/bitnagil_backend/onboarding/repository/OnboardingRepository.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import bitnagil.bitnagil_backend.onboarding.domain.enums.EmotionType;
55
import bitnagil.bitnagil_backend.onboarding.domain.enums.RealOutingFrequency;
66
import bitnagil.bitnagil_backend.onboarding.domain.enums.TargetOutingFrequency;
7-
import bitnagil.bitnagil_backend.onboarding.domain.enums.TimeSlot;
87
import org.springframework.data.jpa.repository.JpaRepository;
98
import org.springframework.stereotype.Repository;
109

10+
import java.time.LocalTime;
11+
1112
@Repository
1213
public interface OnboardingRepository extends JpaRepository<Onboarding, Long> {
1314
Onboarding findByTimeSlotAndEmotionTypeAndRealOutingFrequencyAndTargetOutingFrequency(
14-
TimeSlot timeSlot,
15+
LocalTime timeSlot,
1516
EmotionType emotionType,
1617
RealOutingFrequency realOutingFrequency,
1718
TargetOutingFrequency targetOutingFrequency

0 commit comments

Comments
 (0)