Skip to content

Commit ff544ad

Browse files
committed
Merge remote-tracking branch 'origin/dev' into feat/42
2 parents cf8b8b2 + 0b2b38e commit ff544ad

File tree

19 files changed

+399
-81
lines changed

19 files changed

+399
-81
lines changed

src/main/java/com/back/domain/study/entity/RepeatRule.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/main/java/com/back/domain/study/entity/StudyPlan.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/com/back/domain/study/entity/StudyStatus.java

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.back.domain.study.plan.controller;
2+
3+
import com.back.domain.study.plan.dto.StudyPlanCreateRequest;
4+
import com.back.domain.study.plan.dto.StudyPlanResponse;
5+
import com.back.domain.study.plan.service.StudyPlanService;
6+
import com.back.global.common.dto.RsData;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
10+
import org.springframework.web.bind.annotation.*;
11+
12+
@RestController
13+
@RequiredArgsConstructor
14+
@RequestMapping("/api/plans")
15+
public class StudyPlanController {
16+
private final StudyPlanService studyPlanService;
17+
18+
@PostMapping
19+
public ResponseEntity<RsData<StudyPlanResponse>> createStudyPlan(
20+
// 로그인 유저 정보 받기 @AuthenticationPrincipal CustomUserDetails user,
21+
@RequestBody StudyPlanCreateRequest request) {
22+
//커스텀 디테일 구현 시 사용 int userId = user.getId();
23+
Long userId = 1L; // 임시로 userId를 1로 설정
24+
StudyPlanResponse response = studyPlanService.createStudyPlan(userId, request);
25+
return ResponseEntity.ok(RsData.success("학습 계획이 성공적으로 생성되었습니다.", response));
26+
}
27+
28+
@DeleteMapping("/{planId}")
29+
public ResponseEntity<RsData<Void>> deleteStudyPlan(@PathVariable Long planId) {
30+
//studyPlanService.deleteStudyPlan(planId);
31+
return ResponseEntity.ok(RsData.success("학습 계획이 성공적으로 삭제되었습니다.", null));
32+
}
33+
34+
35+
36+
37+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.back.domain.study.plan.dto;
2+
3+
import com.back.domain.study.plan.entity.Color;
4+
import com.back.domain.study.plan.entity.Frequency;
5+
import com.fasterxml.jackson.annotation.JsonFormat;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Getter;
8+
import lombok.NoArgsConstructor;
9+
import lombok.Setter;
10+
11+
import java.time.LocalDateTime;
12+
13+
@Getter
14+
@Setter
15+
@NoArgsConstructor
16+
@AllArgsConstructor
17+
public class StudyPlanCreateRequest {
18+
private String subject;
19+
20+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
21+
private LocalDateTime startDate;
22+
23+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
24+
private LocalDateTime endDate;
25+
26+
private Color color;
27+
28+
// RepeatRule 중첩 객체
29+
private RepeatRuleRequest repeatRule;
30+
31+
@Getter
32+
@Setter
33+
@NoArgsConstructor
34+
@AllArgsConstructor
35+
public static class RepeatRuleRequest {
36+
private Frequency frequency;
37+
private Integer intervalValue;
38+
private String byDay; // "MON" 형태의 문자열
39+
40+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
41+
private String untilDate; // "2025-12-31" 형태
42+
}
43+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.back.domain.study.plan.dto;
2+
3+
import com.back.domain.study.plan.entity.Color;
4+
import com.back.domain.study.plan.entity.DayOfWeek;
5+
import com.back.domain.study.plan.entity.Frequency;
6+
import com.back.domain.study.plan.entity.StudyPlan;
7+
import com.fasterxml.jackson.annotation.JsonFormat;
8+
import lombok.AllArgsConstructor;
9+
import lombok.Getter;
10+
import lombok.NoArgsConstructor;
11+
import lombok.Setter;
12+
13+
import java.time.LocalDateTime;
14+
import java.util.Arrays;
15+
import java.util.List;
16+
import java.util.stream.Collectors;
17+
18+
@Getter
19+
@Setter
20+
@NoArgsConstructor
21+
@AllArgsConstructor
22+
public class StudyPlanResponse {
23+
private Long id;
24+
private String subject;
25+
26+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
27+
private LocalDateTime startDate;
28+
29+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
30+
private LocalDateTime endDate;
31+
32+
private Color color;
33+
34+
private Long parentPlanId;
35+
private List<StudyPlanResponse> childPlans;
36+
37+
// RepeatRule 정보
38+
private RepeatRuleResponse repeatRule;
39+
40+
@Getter
41+
@Setter
42+
@NoArgsConstructor
43+
@AllArgsConstructor
44+
public static class RepeatRuleResponse {
45+
private Frequency frequency;
46+
private Integer repeatInterval;
47+
private String byDay; // "MON" 형태의 문자열
48+
49+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
50+
private LocalDateTime until;
51+
52+
public RepeatRuleResponse(com.back.domain.study.plan.entity.RepeatRule repeatRule) {
53+
if (repeatRule != null) {
54+
this.frequency = repeatRule.getFrequency();
55+
this.repeatInterval = repeatRule.getRepeatInterval();
56+
this.byDay = repeatRule.getByDay();
57+
this.until = repeatRule.getUntilDate();
58+
}
59+
}
60+
61+
// 요일을 리스트로 접근 ("MON,TUE" -> [MON, TUE])
62+
public List<DayOfWeek> getByDaysList() {
63+
if (byDay == null || byDay.isEmpty()) {
64+
return List.of();
65+
}
66+
return Arrays.stream(byDay.split(","))
67+
.map(String::trim)
68+
.map(com.back.domain.study.plan.entity.DayOfWeek::valueOf)
69+
.collect(Collectors.toList());
70+
}
71+
}
72+
//엔티티를 DTO로 변환하는 생성자
73+
public StudyPlanResponse(StudyPlan studyPlan) {
74+
if (studyPlan != null) {
75+
this.id = studyPlan.getId();
76+
this.subject = studyPlan.getSubject();
77+
this.startDate = studyPlan.getStartDate();
78+
this.endDate = studyPlan.getEndDate();
79+
this.color = studyPlan.getColor();
80+
81+
82+
// RepeatRule 변환
83+
if (studyPlan.getRepeatRule() != null) {
84+
this.repeatRule = new RepeatRuleResponse(studyPlan.getRepeatRule());
85+
}
86+
}
87+
}
88+
}

src/main/java/com/back/domain/study/entity/Color.java renamed to src/main/java/com/back/domain/study/plan/entity/Color.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.back.domain.study.entity;
1+
package com.back.domain.study.plan.entity;
22

33
public enum Color {
44
RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, PINK

src/main/java/com/back/domain/study/entity/DayOfWeek.java renamed to src/main/java/com/back/domain/study/plan/entity/DayOfWeek.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.back.domain.study.entity;
1+
package com.back.domain.study.plan.entity;
22

33
public enum DayOfWeek {
44
MON, TUE, WED, THU, FRI, SAT, SUN

src/main/java/com/back/domain/study/entity/Frequency.java renamed to src/main/java/com/back/domain/study/plan/entity/Frequency.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.back.domain.study.entity;
1+
package com.back.domain.study.plan.entity;
22

33
public enum Frequency {
44
DAILY, WEEKLY, MONTHLY
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.back.domain.study.plan.entity;
2+
3+
import com.back.global.entity.BaseEntity;
4+
import jakarta.persistence.*;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
import lombok.Setter;
9+
10+
import java.time.LocalDateTime;
11+
12+
@Entity
13+
@Getter
14+
@Setter
15+
@NoArgsConstructor
16+
@AllArgsConstructor
17+
public class RepeatRule extends BaseEntity {
18+
@OneToOne
19+
@JoinColumn(name = "plan_id", nullable = false)
20+
private StudyPlan studyPlan;
21+
22+
@Enumerated(EnumType.STRING)
23+
private Frequency frequency;
24+
25+
@Column(name = "interval_value", nullable = false)
26+
private int RepeatInterval;
27+
28+
//필요 시 요일 지정. 여러 요일 지정 시 ,로 구분
29+
//현재는 요일 하나만 지정하는 형태로 구현
30+
@Column(name = "by_day")
31+
private String byDay;
32+
33+
private LocalDateTime untilDate;
34+
}

0 commit comments

Comments
 (0)