Skip to content

Commit

Permalink
Merge pull request #79 from uswLectureEvaluation/hotfix/lecture_schedule
Browse files Browse the repository at this point in the history
hotfix: 시간표상 강의 조회 오류 해결 및 강의 테이블 구조 변경
  • Loading branch information
wonslee authored Feb 8, 2024
2 parents 35c9686 + c7b3cf7 commit 4b46553
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import usw.suwiki.domain.lecture.domain.Lecture;
import usw.suwiki.domain.lecture.domain.LectureSchedule;
import usw.suwiki.global.util.apiresponse.ResponseFieldManipulationUtils;

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class LectureWithScheduleResponse {
public class LectureWithScheduleResponse { // TODO refactor V2: lecture_id, schedule_id 분리
private long id;
private String name;
private String type;
Expand All @@ -25,16 +25,16 @@ public class LectureWithScheduleResponse {
private final List<OriginalLectureCellResponse> originalCellList = new ArrayList<>();

public static LectureWithScheduleResponse of(
Lecture lecture
LectureSchedule lectureSchedule
) {
final String professorName = ResponseFieldManipulationUtils.resolveLiteralNull(lecture.getProfessor());
final String professorName = ResponseFieldManipulationUtils.resolveLiteralNull(lectureSchedule.getLecture().getProfessor());
return LectureWithScheduleResponse.builder()
.id(lecture.getId())
.name(lecture.getName())
.id(lectureSchedule.getId())
.name(lectureSchedule.getLecture().getName())
.professorName(professorName)
.type(lecture.getType())
.major(lecture.getMajorType())
.grade(lecture.getLectureDetail().getGrade())
.type(lectureSchedule.getLecture().getType())
.major(lectureSchedule.getLecture().getMajorType())
.grade(lectureSchedule.getLecture().getLectureDetail().getGrade())
.build();
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/usw/suwiki/domain/lecture/domain/Lecture.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class Lecture extends BaseTimeEntity {

private int postsCount = 0;

@OneToMany(mappedBy = "lecture", cascade = CascadeType.ALL, orphanRemoval = true)
private List<LectureSchedule> scheduleList = new ArrayList<>();

@OneToMany(mappedBy = "lecture", cascade = CascadeType.ALL, orphanRemoval = true)
private List<EvaluatePost> evaluatePostList = new ArrayList<>();
Expand Down Expand Up @@ -83,6 +85,13 @@ public void removeEvaluatePost(EvaluatePost evaluatePost) {
this.evaluatePostList.remove(evaluatePost);
}

public void addSchedule(LectureSchedule lectureSchedule) {
this.scheduleList.add(lectureSchedule);
}

public void removeSchedule(LectureSchedule lectureSchedule) {
this.scheduleList.remove(lectureSchedule);
}
/**
* 비즈니스 메서드
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
@Embeddable
@NoArgsConstructor
public class LectureDetail { // TODO refactor: placeSchedule, grade, point 은 Lecture로 이동. 혹은 전체 이동.
@Column(name = "place_schedule")
private String placeSchedule;

@Column(name = "lecture_code")
private String code;
Expand All @@ -32,9 +30,8 @@ public class LectureDetail { // TODO refactor: placeSchedule, grade, point 은 L
private String evaluateType;

@Builder
public LectureDetail(String placeSchedule, String code, double point, String capprType, String diclNo,
public LectureDetail(String code, double point, String capprType, String diclNo,
int grade, String evaluateType) {
this.placeSchedule = placeSchedule;
this.code = code;
this.point = point;
this.capprType = capprType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package usw.suwiki.domain.lecture.domain;

import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class LectureSchedule {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "place_schedule", nullable = false)
private String placeSchedule;

@ManyToOne(fetch = FetchType.LAZY)
private Lecture lecture;

@Builder
public LectureSchedule(String placeSchedule, Lecture lecture) {
this.placeSchedule = placeSchedule;
associateLecture(lecture);
}

//-------------------------------------------------------------------------
// 연관관계 메서드
//-------------------------------------------------------------------------
private void associateLecture(Lecture lecture) {
if (Objects.nonNull(this.lecture)) {
this.lecture.removeSchedule(this);
}
this.lecture = lecture;
lecture.addSchedule(this);
}

//-------------------------------------------------------------------------
// 비즈니스 메서드
//-------------------------------------------------------------------------


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
import org.springframework.data.domain.Slice;
import usw.suwiki.domain.lecture.controller.dto.LectureFindOption;
import usw.suwiki.domain.lecture.domain.Lecture;
import usw.suwiki.domain.lecture.domain.LectureSchedule;
import usw.suwiki.domain.lecture.domain.repository.dao.LecturesAndCountDao;


public interface LectureCustomRepository {
Slice<Lecture> findCurrentSemesterLectures(
Slice<LectureSchedule> findCurrentSemesterLectureSchedules(
final Long cursorId,
final int limit,
final String keyword,
final String majorType,
final Integer grade
);

List<LectureSchedule> findAllLectureSchedulesByLectureSemesterContains(String semester);

Optional<Lecture> findByExtraUniqueKey(String lectureName, String ProfessorName, String majorType);

List<String> findAllMajorType();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package usw.suwiki.domain.lecture.domain.repository;

import static usw.suwiki.domain.lecture.domain.QLecture.lecture;
import static usw.suwiki.domain.lecture.domain.QLectureSchedule.lectureSchedule;

import com.querydsl.core.QueryResults;
import com.querydsl.core.types.OrderSpecifier;
Expand All @@ -10,7 +11,6 @@
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import java.util.Objects;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -19,6 +19,7 @@
import org.springframework.data.domain.Slice;
import usw.suwiki.domain.lecture.controller.dto.LectureFindOption;
import usw.suwiki.domain.lecture.domain.Lecture;
import usw.suwiki.domain.lecture.domain.LectureSchedule;
import usw.suwiki.domain.lecture.domain.repository.dao.LecturesAndCountDao;
import usw.suwiki.global.util.query.SlicePaginationUtils;

Expand All @@ -35,25 +36,34 @@ public class LectureCustomRepositoryImpl implements LectureCustomRepository { //
private String currentSemester; // TODO 고민: Lecture - currently_opened 혹은 last_opened_semester 컬럼 추가 -> 데이터 파싱 로직 및 WHERE절 변경해야 함.

@Override
public Slice<Lecture> findCurrentSemesterLectures(
public Slice<LectureSchedule> findCurrentSemesterLectureSchedules(
final Long cursorId,
final int limit,
final String keyword,
final String majorType,
final Integer grade
) {
JPAQuery<Lecture> query = queryFactory.selectFrom(lecture)
.where(gtCursorId(cursorId))
.where(containsLectureKeyword(keyword))
.where(eqMajorType(majorType))
.where(eqGrade(grade))
.where(lecture.semester.endsWith(currentSemester))
.orderBy(lecture.id.asc())
JPAQuery<LectureSchedule> query = queryFactory.selectFrom(lectureSchedule)
.join(lectureSchedule.lecture).fetchJoin()
.where(gtLectureScheduleCursorId(cursorId))
.where(containsLectureScheduleLectureKeyword(keyword))
.where(eqLectureScheduleLectureMajorType(majorType))
.where(eqLectureScheduleLectureGrade(grade))
.where(lectureSchedule.lecture.semester.endsWith(currentSemester))
.orderBy(lectureSchedule.id.asc())
.limit(SlicePaginationUtils.increaseSliceLimit(limit));

return SlicePaginationUtils.buildSlice(query.fetch(), limit);
}

@Override
public List<LectureSchedule> findAllLectureSchedulesByLectureSemesterContains(String semester) {
return queryFactory.selectFrom(lectureSchedule)
.join(lectureSchedule.lecture).fetchJoin()
.where(lectureSchedule.lecture.semester.contains(semester))
.fetch();
}


@Override
public Optional<Lecture> findByExtraUniqueKey(String lectureName, String professorName, String majorType) {
Expand Down Expand Up @@ -206,33 +216,33 @@ public List<String> findAllMajorType() {
.fetch();
}

private BooleanExpression gtCursorId(Long cursorId) {
private BooleanExpression gtLectureScheduleCursorId(Long cursorId) {
if (Objects.isNull(cursorId)) {
return null;
}
return lecture.id.gt(cursorId);
return lectureSchedule.id.gt(cursorId);
}

private BooleanExpression containsLectureKeyword(String keyword) {
private BooleanExpression containsLectureScheduleLectureKeyword(String keyword) {
if (Objects.isNull(keyword)) {
return null;
}
return lecture.name.contains(keyword)
.or(lecture.professor.contains(keyword));
return lectureSchedule.lecture.name.contains(keyword)
.or(lectureSchedule.lecture.professor.contains(keyword));
}

private BooleanExpression eqMajorType(String majorType) {
private BooleanExpression eqLectureScheduleLectureMajorType(String majorType) {
if (Objects.isNull(majorType)) {
return null;
}
return lecture.majorType.eq(majorType);
return lectureSchedule.lecture.majorType.eq(majorType);
}

private BooleanExpression eqGrade(Integer grade) {
private BooleanExpression eqLectureScheduleLectureGrade(Integer grade) {
if (Objects.isNull(grade)) {
return null;
}
return lecture.lectureDetail.grade.eq(grade);
return lectureSchedule.lecture.lectureDetail.grade.eq(grade);
}

private OrderSpecifier<?> getOrderSpecifier(String orderOption) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package usw.suwiki.domain.lecture.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import usw.suwiki.domain.lecture.domain.LectureSchedule;

public interface LectureScheduleRepository extends JpaRepository<LectureSchedule, Long> {
}
Loading

0 comments on commit 4b46553

Please sign in to comment.