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 21 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 @@ -121,7 +121,11 @@ ResponseEntity<Void> deleteAllTimetablesFrame(
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true)))
}
)
@Operation(summary = "시간표에 강의 정보 추가")
@Operation(summary = "시간표에 강의 정보 추가",
description = """
lecture_id가 있는 경우 class_title, class_time, professor은 null, grades는 '0'으로 입력해야합니다.\n
lecture_id가 없는 경우 class_title, class_time, professor, grades을 선택적으로 입력합니다.
""")
@SecurityRequirement(name = "Jwt Authentication")
@PostMapping("/v2/timetables/lecture")
ResponseEntity<TimetableLectureResponse> createTimetableLecture(
Expand Down
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 @@ -15,6 +15,7 @@
import in.koreatech.koin.domain.timetableV2.model.TimetableFrame;
import in.koreatech.koin.domain.timetableV2.model.TimetableLecture;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Size;

@JsonNaming(value = SnakeCaseStrategy.class)
public record TimetableLectureResponse(
Expand Down Expand Up @@ -47,11 +48,8 @@ public record InnerTimetableLectureResponse(
@Schema(description = "설계 학점", example = "0", requiredMode = NOT_REQUIRED)
String designScore,

@Schema(description = "강의(커스텀) 시간", example = "[204, 205, 206, 207, 302, 303]", requiredMode = REQUIRED)
List<Integer> classTime,

@Schema(description = "강의 장소", example = "2공학관", requiredMode = NOT_REQUIRED)
String classPlace,
@Schema(description = "강의 정보", requiredMode = NOT_REQUIRED)
List<ClassInfo> classInfos,

@Schema(description = "메모", example = "null", requiredMode = NOT_REQUIRED)
String memo,
Expand All @@ -74,6 +72,58 @@ public record InnerTimetableLectureResponse(
@Schema(description = "학부", example = "디자인ㆍ건축공학부", requiredMode = NOT_REQUIRED)
String department
) {
@JsonNaming(value = SnakeCaseStrategy.class)
public record ClassInfo(
@Schema(description = "강의 시간", example = "null", requiredMode = NOT_REQUIRED)
List<Integer> classTime,

@Schema(description = "강의 장소", example = "도서관", requiredMode = NOT_REQUIRED)
String classPlace
) {
public static List<ClassInfo> of(String classTime, String classPlace) {
// 정규 강의인 경우 강의 장소가 없기 때문에 바로 반환
if (classPlace == null) {
return List.of(new ClassInfo(parseClassTimes(classTime), null));
}

// 구분자를 바탕으로 강의 시간과 강의 장소 분리
String[] classPlaceSegment = classPlace.split(",\\s*");
String[] classTimeSegment = classTime.substring(1, classTime.length() - 1).trim().split(",\\s*");

List<ClassInfo> classInfos = new ArrayList<>();
List<Integer> tempClassTimes = new ArrayList<>();
int index = 0;

for (String segment : classTimeSegment) {
int parseInt = Integer.parseInt(segment);
if (parseInt == -1) {
if (!tempClassTimes.isEmpty()) {
classInfos.add(new ClassInfo(new ArrayList<>(tempClassTimes), classPlaceSegment[index++]));
tempClassTimes.clear();
}
}
else {
tempClassTimes.add(parseInt);
}
}

if (!tempClassTimes.isEmpty()) {
classInfos.add(new ClassInfo(new ArrayList<>(tempClassTimes), classPlaceSegment[index]));
}

return classInfos;
}

private static List<Integer> parseClassTimes(String classTime) {
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)
.toList();
}
}

public static List<InnerTimetableLectureResponse> from(List<TimetableLecture> timetableLectures) {
List<InnerTimetableLectureResponse> timetableLectureList = new ArrayList<>();
Expand All @@ -89,8 +139,7 @@ public static List<InnerTimetableLectureResponse> from(List<TimetableLecture> ti
null,
null,
null,
parseClassTimes(timetableLecture.getClassTime()),
timetableLecture.getClassPlace(),
ClassInfo.of(timetableLecture.getClassTime(), timetableLecture.getClassPlace()),
timetableLecture.getMemo(),
timetableLecture.getGrades(),
timetableLecture.getClassTitle(),
Expand All @@ -106,8 +155,7 @@ public static List<InnerTimetableLectureResponse> from(List<TimetableLecture> ti
lecture.getRegularNumber(),
lecture.getCode(),
lecture.getDesignScore(),
getClassTime(timetableLecture, lecture),
timetableLecture.getClassPlace(),
ClassInfo.of(getClassTime(timetableLecture, lecture), timetableLecture.getClassPlace()),
timetableLecture.getMemo(),
getGrades(timetableLecture, lecture),
getClassTitle(timetableLecture, lecture),
Expand Down Expand Up @@ -143,11 +191,11 @@ private static String getGrades(TimetableLecture timetableLecture, Lecture lectu
return timetableLecture.getGrades();
}

private static List<Integer> getClassTime(TimetableLecture timetableLecture, Lecture lecture) {
private static String getClassTime(TimetableLecture timetableLecture, Lecture lecture) {
if (timetableLecture.getClassTime() == null) {
return parseClassTimes(lecture.getClassTime());
return lecture.getClassTime();
}
return parseClassTimes(timetableLecture.getClassTime());
return timetableLecture.getClassTime();
}
}

Expand All @@ -163,13 +211,4 @@ public static TimetableLectureResponse of(TimetableFrame timetableFrame, Integer
totalGrades
);
}

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

return Arrays.stream(classTimeWithoutBrackets.split(SEPARATOR))
.map(String::strip)
.map(Integer::parseInt)
.toList();
}
}
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;
Loading
Loading