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

fix: timetableLecture 클래스 필드 수정 #1070

Merged
merged 22 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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 @@ -3,7 +3,9 @@
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
Expand Down Expand Up @@ -32,12 +34,9 @@ public record InnerTimeTableLectureRequest(
@Size(max = 100, message = "강의 이름의 최대 글자는 100글자입니다.")
String classTitle,

@Schema(description = "강의 시간", example = "null", requiredMode = NOT_REQUIRED)
List<Integer> classTime,

@Schema(description = "강의 장소", example = "도서관", requiredMode = NOT_REQUIRED)
@Size(max = 30, message = "강의 장소의 최대 글자는 30글자입니다.")
String classPlace,
@Valid
@Schema(description = "강의 정보", requiredMode = NOT_REQUIRED)
List<ClassInfo> classInfos,

@Schema(description = "교수명", example = "null", requiredMode = NOT_REQUIRED)
@Size(max = 30, message = "교수 명의 최대 글자는 30글자입니다.")
Expand All @@ -54,6 +53,18 @@ public record InnerTimeTableLectureRequest(
@Schema(description = "강의 고유 번호", example = "14", requiredMode = NOT_REQUIRED)
Integer lectureId
) {
@JsonNaming(value = SnakeCaseStrategy.class)
public record ClassInfo(
@Schema(description = "강의 시간", example = "null", requiredMode = NOT_REQUIRED)
List<Integer> classTime,

@Schema(description = "강의 장소", example = "도서관", requiredMode = NOT_REQUIRED)
@Size(max = 30, message = "강의 장소의 최대 글자는 30글자입니다.")
String classPlace
) {

}

public InnerTimeTableLectureRequest {
if (grades == null) {
grades = "0";
Expand All @@ -64,7 +75,7 @@ public TimetableLecture toTimetableLecture(TimetableFrame timetableFrame) {
return new TimetableLecture(
classTitle,
getClassTimeToString(),
classPlace,
getClassPlaceToString(),
professor,
grades,
memo,
Expand All @@ -78,7 +89,7 @@ public TimetableLecture toTimetableLecture(TimetableFrame timetableFrame, Lectur
return new TimetableLecture(
classTitle,
getClassTimeToString(),
classPlace,
getClassPlaceToString(),
professor,
grades,
memo,
Expand All @@ -89,8 +100,22 @@ public TimetableLecture toTimetableLecture(TimetableFrame timetableFrame, Lectur
}

private String getClassTimeToString() {
if (classTime != null) {
return classTime.toString();
if (classInfos != null) {
List<Integer> classTimes = new ArrayList<>();
for (int i = 0; i < classInfos.size(); i++) {
if (i > 0) classTimes.add(-1);
classTimes.addAll(classInfos.get(i).classTime);
}
return classTimes.toString();
}
return null;
}

private String getClassPlaceToString() {
if (classInfos != null) {
return classInfos.stream()
.map(c -> c.classPlace)
.collect(Collectors.joining(", "));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ public record InnerTimetableLectureRequest(
@Size(max = 100, message = "강의 이름의 최대 글자는 100글자입니다.")
String classTitle,

@Schema(description = "강의 시간", example = "[210, 211]", requiredMode = NOT_REQUIRED)
@Size(max = 100, message = "강의 시간의 최대 글자는 100글자입니다.")
List<Integer> classTime,

@Schema(description = "강의 장소", example = "null", requiredMode = NOT_REQUIRED)
@Size(max = 30, message = "강의 장소의 최대 글자는 30글자입니다.")
String classPlace,
@Valid
@Schema(description = "강의 정보", requiredMode = NOT_REQUIRED)
List<ClassInfo> classInfos,

@Schema(description = "강의 교수", example = "이돈우", requiredMode = NOT_REQUIRED)
@Size(max = 30, message = "교수 명의 최대 글자는 30글자입니다.")
Expand All @@ -56,6 +52,16 @@ public record InnerTimetableLectureRequest(
@Size(max = 200, message = "메모는 200자 이하로 입력해주세요.")
String memo
) {
@JsonNaming(value = SnakeCaseStrategy.class)
public record ClassInfo(
@Schema(description = "강의 시간", example = "null", requiredMode = NOT_REQUIRED)
List<Integer> classTime,

@Schema(description = "강의 장소", example = "도서관", requiredMode = NOT_REQUIRED)
@Size(max = 30, message = "강의 장소의 최대 글자는 30글자입니다.")
String classPlace
) {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ public static TimetableLectureResponse of(TimetableFrame timetableFrame, Integer
}

private static List<Integer> parseClassTimes(String classTime) {
String classTimeWithoutBrackets = classTime.substring(INITIAL_BRACE_INDEX, classTime.length() - 1);
if (classTime == null) return null;

String classTimeWithoutBrackets = classTime.substring(INITIAL_BRACE_INDEX, classTime.length() - 1);
return Arrays.stream(classTimeWithoutBrackets.split(SEPARATOR))
.map(String::strip)
.map(Integer::parseInt)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package in.koreatech.koin.domain.timetableV2.factory;

import static in.koreatech.koin.domain.timetableV2.dto.request.TimetableLectureUpdateRequest.InnerTimetableLectureRequest;
import static in.koreatech.koin.domain.timetableV2.dto.request.TimetableLectureUpdateRequest.InnerTimetableLectureRequest.ClassInfo;
import static java.util.stream.Stream.concat;
import static java.util.stream.Stream.of;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Component;

Expand All @@ -20,12 +27,33 @@ public void updateTimetablesLectures(TimetableLectureUpdateRequest request) {
TimetableLecture timetableLecture = timetableLectureRepositoryV2.getById(timetableRequest.id());
timetableLecture.update(
timetableRequest.classTitle(),
timetableRequest.classTime().toString(),
timetableRequest.classPlace(),
getClassTimeToString(timetableRequest.classInfos()),
getClassPlaceToString(timetableRequest.classInfos()),
timetableRequest.professor(),
timetableRequest.grades(),
timetableRequest.memo()
);
}
}

private String getClassTimeToString(List<ClassInfo> classInfos) {
if (classInfos != null) {
List<Integer> classTimes = new ArrayList<>();
for (int i = 0; i < classInfos.size(); i++) {
if (i > 0) classTimes.add(-1);
classTimes.addAll(classInfos.get(i).classTime());
}
return classTimes.toString();
}
return null;
}

private String getClassPlaceToString(List<ClassInfo> classInfos) {
if (classInfos != null) {
return classInfos.stream()
.map(ClassInfo::classPlace)
.collect(Collectors.joining(", "));
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class TimetableLecture extends BaseEntity {
@Column(name = "class_time", columnDefinition = "TEXT")
private String classTime;

@Size(max = 30)
@Column(name = "class_place", length = 30)
@Lob
@Column(name = "class_place", columnDefinition = "TEXT")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

굿 이거 안 하면 애가 아파해요

private String classPlace;

@Size(max = 30)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE timetable_lecture
MODIFY COLUMN class_place TEXT;
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,24 @@ void setup() {
"timetable_lecture": [
{
"class_title": "커스텀생성1",
"class_time" : [200, 201],
"class_place" : "한기대",
"class_infos": [
{
"class_time" : [200, 201],
"class_place" : "한기대"
}
],
"professor" : "서정빈",
"grades": "2",
"memo" : "메모"
},
{
"class_title": "커스텀생성2",
"class_time" : [202, 203],
"class_place" : "참빛관 편의점",
"class_infos": [
{
"class_time" : [202, 203],
"class_place" : "참빛관 편의점"
}
],
"professor" : "감사 서정빈",
"grades": "1",
"memo" : "메모"
Expand Down Expand Up @@ -144,17 +152,25 @@ void setup() {
{
"id": 1,
"class_title": "커스텀바꿔요1",
"class_time" : [200, 201],
"class_place" : "한기대",
"class_infos": [
{
"class_time" : [200, 201],
"class_place" : "한기대"
}
],
"professor" : "서정빈",
"grades" : "0",
"memo" : "메모한당 히히"
},
{
"id": 2,
"class_title": "커스텀바꿔요2",
"class_time" : [202, 203],
"class_place" : "참빛관 편의점",
"class_infos": [
{
"class_time" : [202, 203],
"class_place" : "참빛관 편의점"
}
],
"professor" : "알바 서정빈",
"grades" : "0",
"memo" : "메모한당 히히"
Expand Down
Loading