Skip to content

Commit a5920c3

Browse files
authored
Merge pull request #18 from CodIN-INU/develop
refactor: Lecture 내부 Syllabus 컬럼 OneToOne으로 테이블 분리 및 사전수강과목 StringListConverter 추가
2 parents ed79ba1 + 089b519 commit a5920c3

File tree

10 files changed

+305
-54
lines changed

10 files changed

+305
-54
lines changed

src/main/java/inu/codin/codin/domain/elasticsearch/convertor/LectureDocumentConverter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
public class LectureDocumentConverter {
1818

1919
public LectureDocument convertToDocument(Lecture lecture) {
20-
2120
return LectureDocument.builder()
2221
.id(lecture.getId())
2322
.lectureNm(lecture.getLectureNm())
@@ -28,15 +27,15 @@ public LectureDocument convertToDocument(Lecture lecture) {
2827
.type(lecture.getType() != null ? lecture.getType().name() : null)
2928
.lectureType(lecture.getLectureType())
3029
.evaluation(lecture.getEvaluation() != null ? lecture.getEvaluation().name() : null)
31-
.preCourses(toPreCourses(lecture.getPreCourse()))
30+
.preCourses(lecture.getPreCourse())
3231
.starRating(lecture.getStarRating())
3332
.likes(lecture.getLikes())
3433
.hits(lecture.getHits())
3534
.semesters(toSemesterInfos(lecture.getSemester()))
3635
.tags(toTagNames(lecture.getTags()))
3736
.schedule(toScheduleInfos(lecture.getSchedule()))
3837
.emotion(EmotionInfo.from(lecture.getEmotion()))
39-
.syllabus(lecture.getSyllabus())
38+
.syllabus(lecture.getSyllabus().getFullText())
4039
.aiSummary(lecture.getAiSummary())
4140
.build();
4241
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package inu.codin.codin.domain.lecture.converter;
2+
3+
import inu.codin.codin.domain.lecture.exception.LectureErrorCode;
4+
import inu.codin.codin.domain.lecture.exception.LectureException;
5+
import jakarta.persistence.AttributeConverter;
6+
import jakarta.persistence.Converter;
7+
import lombok.extern.slf4j.Slf4j;
8+
9+
import java.util.Arrays;
10+
import java.util.List;
11+
12+
@Slf4j
13+
@Converter(autoApply = true)
14+
public class StringListConverter implements AttributeConverter<List<String>, String> {
15+
16+
@Override
17+
public String convertToDatabaseColumn(List<String> dataList) {
18+
try {
19+
return String.join(",", dataList);
20+
} catch (Exception e) {
21+
log.error(e.getMessage(), e);
22+
throw new LectureException(LectureErrorCode.CONVERT_ERROR);
23+
}
24+
}
25+
26+
@Override
27+
public List<String> convertToEntityAttribute(String data) {
28+
try {
29+
return data != null ? Arrays.stream(data.split(",")).toList() : null;
30+
} catch (Exception e) {
31+
log.error(e.getMessage(), e);
32+
throw new LectureException(LectureErrorCode.CONVERT_ERROR);
33+
}
34+
}
35+
}

src/main/java/inu/codin/codin/domain/lecture/dto/LectureDetailResponseDto.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
@Getter
1515
public class LectureDetailResponseDto extends LecturePreviewResponseDto {
1616

17-
// todo: 강의 계획서, AI 요약본 반환 데이터 추가
18-
1917
@Schema(description = "단과대", example = "정보기술대학")
2018
private String college;
2119

@@ -29,14 +27,16 @@ public class LectureDetailResponseDto extends LecturePreviewResponseDto {
2927
private List<Schedule> schedule;
3028

3129
@Schema(description = "선수과목")
32-
private String preCourse;
30+
private List<String> preCourse;
3331

3432
@Schema(description = "후기 평점들의 범위마다 100분율 계산", example = "hard : 30, ok : 20, best : 50")
3533
private EmotionResponseDto emotion;
3634

3735
private boolean openKeyword;
3836

39-
public LectureDetailResponseDto(Long id, String title, String professor, Type type, int grade, int credit, List<String> tags, Department department, Department college, String evaluation, String lectureType, List<Schedule> schedule, String preCourse, EmotionResponseDto emotion, boolean openKeyword, int likes, double starRating) {
37+
private String aiSummary;
38+
39+
public LectureDetailResponseDto(Long id, String title, String professor, Type type, int grade, int credit, List<String> tags, Department department, Department college, String evaluation, String lectureType, List<Schedule> schedule, List<String> preCourse, EmotionResponseDto emotion, boolean openKeyword, int likes, double starRating, String aiSummary) {
4040
super(id, title, professor, type, grade, credit, tags, null, department.getDescription(), likes, starRating);
4141
this.college = college.getDescription();
4242
this.evaluation = evaluation;
@@ -45,6 +45,7 @@ public LectureDetailResponseDto(Long id, String title, String professor, Type ty
4545
this.preCourse = preCourse;
4646
this.emotion = emotion;
4747
this.openKeyword = openKeyword;
48+
this.aiSummary = aiSummary;
4849
}
4950

5051
public static LectureDetailResponseDto of(Lecture lecture, Emotion emotion, boolean openKeyword){
@@ -67,7 +68,8 @@ public static LectureDetailResponseDto of(Lecture lecture, Emotion emotion, bool
6768
emotion.changeToPercentage(),
6869
openKeyword,
6970
lecture.getLikes(),
70-
lecture.getStarRating()
71+
lecture.getStarRating(),
72+
lecture.getAiSummary()
7173
);
7274
}
7375

src/main/java/inu/codin/codin/domain/lecture/entity/Lecture.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package inu.codin.codin.domain.lecture.entity;
22

33
import inu.codin.codin.domain.lecture.converter.EvaluationConverter;
4+
import inu.codin.codin.domain.lecture.converter.StringListConverter;
45
import inu.codin.codin.domain.lecture.converter.TypeConverter;
56
import inu.codin.codin.domain.review.entity.Review;
67
import inu.codin.codin.global.common.entity.Department;
@@ -19,8 +20,6 @@
1920
@DynamicUpdate
2021
public class Lecture {
2122

22-
// todo: 강의계획서 내용, 강의 계획서 AI 요약 컬럼 추가
23-
2423
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
2524
private Long id;
2625
private String lectureNm; //교과목명
@@ -37,14 +36,18 @@ public class Lecture {
3736

3837
@Convert(converter = EvaluationConverter.class)
3938
private Evaluation evaluation; //평가 방식(상대평가, 절대평가, 이수)
40-
private String preCourse; //사전 과목 //todo List로 관리 피룡
39+
40+
// Json 형태로 저장
41+
@Convert(converter = StringListConverter.class)
42+
private List<String> preCourse; //사전 과목 //todo List로 관리 피룡
4143
private double starRating; //과목 평점
4244
private int likes; //좋아요 수
4345
private int hits; //조회 수
4446

4547
/** 강의 계획서 */
46-
@Column(columnDefinition = "TEXT")
47-
private String syllabus;
48+
@OneToOne(fetch = FetchType.EAGER)
49+
@JoinColumn(name = "syllabus_id")
50+
private Syllabus syllabus;
4851

4952
/** 교과목 정보 + 강의 계획서 + 리뷰 -> AI 요약 */
5053
@Column(columnDefinition = "TEXT")
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
package inu.codin.codin.domain.lecture.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.AccessLevel;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
8+
@Entity
9+
@Getter
10+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
11+
public class Syllabus {
12+
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.IDENTITY)
15+
private Long id;
16+
17+
/** 전체 텍스트 캐시 */
18+
@Transient
19+
private String fullText;
20+
21+
// 기본 메타/분류 정보
22+
23+
/** 개설 대학/대학원명 (원문 보존) */
24+
@Column(name = "college")
25+
private String college;
26+
27+
/** 개설 주체 학과(부) (원문 보존) */
28+
@Column(name = "department_name")
29+
private String departmentName;
30+
31+
/** 이수구분(전필/전선/교양 등 원문 보존) */
32+
@Column(name = "completion_category")
33+
private String completionCategory;
34+
35+
/** 이수영역 */
36+
@Column(name = "completion_area")
37+
private String completionArea;
38+
39+
/** 학수번호 */
40+
@Column(name = "course_code")
41+
private String courseCode;
42+
43+
/** 시간표(교시) – 예: 월3,수4 같은 원문 문자열 */
44+
@Column(name = "timetable_text")
45+
private String timetableText;
46+
47+
/** 수업구분(일반과목/졸업과제 등) */
48+
@Column(name = "class_division")
49+
private String classDivision;
50+
51+
/** 수업유형(RISE/e-Learning 등) */
52+
@Column(name = "class_type_text")
53+
private String classTypeText;
54+
55+
/** 성적평가(원문 보존: 절대/상대/이수인정 등) */
56+
@Column(name = "grading_text")
57+
private String gradingText;
58+
59+
/** 원어강의 여부 */
60+
@Column(name = "is_foreign_language")
61+
private Boolean foreignLanguage;
62+
63+
// 시수 정보
64+
65+
/** 총 시수 */
66+
@Column(name = "total_hours")
67+
private Integer totalHours;
68+
69+
/** 이론 시수 */
70+
@Column(name = "theory_hours")
71+
private Integer theoryHours;
72+
73+
/** 실습 시수 */
74+
@Column(name = "practice_hours")
75+
private Integer practiceHours;
76+
77+
/** 실험 시수 */
78+
@Column(name = "experiment_hours")
79+
private Integer experimentHours;
80+
81+
// 강의 개요/목표/평가
82+
83+
/** 강의 개요 */
84+
@Lob @Column(name = "overview", columnDefinition = "TEXT")
85+
private String overview;
86+
87+
/** 강의 목표 */
88+
@Lob @Column(name = "objective", columnDefinition = "TEXT")
89+
private String objective;
90+
91+
/** 평가 방법(비율·기준 설명 등) */
92+
@Lob @Column(name = "assessment_method", columnDefinition = "TEXT")
93+
private String assessmentMethod;
94+
95+
// 주차별(1~16주) 수업 계획
96+
@Lob @Column(name = "week01", columnDefinition = "TEXT")
97+
private String week01;
98+
@Lob @Column(name = "week02", columnDefinition = "TEXT")
99+
private String week02;
100+
@Lob @Column(name = "week03", columnDefinition = "TEXT")
101+
private String week03;
102+
@Lob @Column(name = "week04", columnDefinition = "TEXT")
103+
private String week04;
104+
@Lob @Column(name = "week05", columnDefinition = "TEXT")
105+
private String week05;
106+
@Lob @Column(name = "week06", columnDefinition = "TEXT")
107+
private String week06;
108+
@Lob @Column(name = "week07", columnDefinition = "TEXT")
109+
private String week07;
110+
@Lob @Column(name = "week08", columnDefinition = "TEXT")
111+
private String week08;
112+
@Lob @Column(name = "week09", columnDefinition = "TEXT")
113+
private String week09;
114+
@Lob @Column(name = "week10", columnDefinition = "TEXT")
115+
private String week10;
116+
@Lob @Column(name = "week11", columnDefinition = "TEXT")
117+
private String week11;
118+
@Lob @Column(name = "week12", columnDefinition = "TEXT")
119+
private String week12;
120+
@Lob @Column(name = "week13", columnDefinition = "TEXT")
121+
private String week13;
122+
@Lob @Column(name = "week14", columnDefinition = "TEXT")
123+
private String week14;
124+
@Lob @Column(name = "week15", columnDefinition = "TEXT")
125+
private String week15;
126+
@Lob @Column(name = "week16", columnDefinition = "TEXT")
127+
private String week16;
128+
129+
// 주교재 1
130+
@Column(name = "main_textbook1_title")
131+
private String mainTextbook1Title;
132+
@Column(name = "main_textbook1_author")
133+
private String mainTextbook1Author;
134+
@Column(name = "main_textbook1_publisher")
135+
private String mainTextbook1Publisher;
136+
@Column(name = "main_textbook1_year")
137+
private String mainTextbook1Year;
138+
139+
// 참고서적 1
140+
@Column(name = "ref_book1_title")
141+
private String refBook1Title;
142+
@Column(name = "ref_book1_author")
143+
private String refBook1Author;
144+
@Column(name = "ref_book1_publisher")
145+
private String refBook1Publisher;
146+
@Column(name = "ref_book1_year")
147+
private String refBook1Year;
148+
149+
// 주교재 2
150+
@Column(name = "main_textbook2_title")
151+
private String mainTextbook2Title;
152+
@Column(name = "main_textbook2_author")
153+
private String mainTextbook2Author;
154+
@Column(name = "main_textbook2_publisher")
155+
private String mainTextbook2Publisher;
156+
@Column(name = "main_textbook2_year")
157+
private String mainTextbook2Year;
158+
159+
// 참고서적 2
160+
@Column(name = "ref_book2_title")
161+
private String refBook2Title;
162+
@Column(name = "ref_book2_author")
163+
private String refBook2Author;
164+
@Column(name = "ref_book2_publisher")
165+
private String refBook2Publisher;
166+
@Column(name = "ref_book2_year")
167+
private String refBook2Year;
168+
169+
/**
170+
* 강의계획서 전체 내용을 하나의 문자열로 합쳐 반환.
171+
* null 값은 무시하고 공백으로 구분합니다.
172+
*/
173+
public String getFullText() {
174+
if (fullText == null) {
175+
StringBuilder sb = new StringBuilder();
176+
177+
appendIfNotNull(sb, college);
178+
appendIfNotNull(sb, departmentName);
179+
appendIfNotNull(sb, completionCategory);
180+
appendIfNotNull(sb, completionArea);
181+
appendIfNotNull(sb, courseCode);
182+
appendIfNotNull(sb, timetableText);
183+
appendIfNotNull(sb, classDivision);
184+
appendIfNotNull(sb, classTypeText);
185+
appendIfNotNull(sb, gradingText);
186+
appendIfNotNull(sb, foreignLanguage != null && foreignLanguage ? "원어강의" : null);
187+
188+
appendIfNotNull(sb, totalHours);
189+
appendIfNotNull(sb, theoryHours);
190+
appendIfNotNull(sb, practiceHours);
191+
appendIfNotNull(sb, experimentHours);
192+
193+
appendIfNotNull(sb, overview);
194+
appendIfNotNull(sb, objective);
195+
appendIfNotNull(sb, assessmentMethod);
196+
197+
appendIfNotNull(sb, week01);
198+
appendIfNotNull(sb, week02);
199+
appendIfNotNull(sb, week03);
200+
appendIfNotNull(sb, week04);
201+
appendIfNotNull(sb, week05);
202+
appendIfNotNull(sb, week06);
203+
appendIfNotNull(sb, week07);
204+
appendIfNotNull(sb, week08);
205+
appendIfNotNull(sb, week09);
206+
appendIfNotNull(sb, week10);
207+
appendIfNotNull(sb, week11);
208+
appendIfNotNull(sb, week12);
209+
appendIfNotNull(sb, week13);
210+
appendIfNotNull(sb, week14);
211+
appendIfNotNull(sb, week15);
212+
appendIfNotNull(sb, week16);
213+
214+
appendIfNotNull(sb, mainTextbook1Title);
215+
appendIfNotNull(sb, mainTextbook1Author);
216+
appendIfNotNull(sb, mainTextbook1Publisher);
217+
appendIfNotNull(sb, mainTextbook1Year);
218+
219+
appendIfNotNull(sb, refBook1Title);
220+
appendIfNotNull(sb, refBook1Author);
221+
appendIfNotNull(sb, refBook1Publisher);
222+
appendIfNotNull(sb, refBook1Year);
223+
224+
appendIfNotNull(sb, mainTextbook2Title);
225+
appendIfNotNull(sb, mainTextbook2Author);
226+
appendIfNotNull(sb, mainTextbook2Publisher);
227+
appendIfNotNull(sb, mainTextbook2Year);
228+
229+
appendIfNotNull(sb, refBook2Title);
230+
appendIfNotNull(sb, refBook2Author);
231+
appendIfNotNull(sb, refBook2Publisher);
232+
appendIfNotNull(sb, refBook2Year);
233+
234+
fullText = sb.toString().trim();
235+
}
236+
return fullText;
237+
}
238+
239+
private void appendIfNotNull(StringBuilder sb, Object value) {
240+
if (value != null) {
241+
sb.append(value).append(" ");
242+
}
243+
}
244+
}

src/main/java/inu/codin/codin/domain/lecture/event/LectureSummarizationEvent.java

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

0 commit comments

Comments
 (0)