Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
56 changes: 41 additions & 15 deletions src/main/java/com/example/Devkor_project/dto/CommentDto.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.example.Devkor_project.dto;

import com.example.Devkor_project.entity.Comment;
import com.example.Devkor_project.entity.CommentRating;
import com.example.Devkor_project.entity.Course;
import com.example.Devkor_project.entity.CourseRating;
import com.example.Devkor_project.entity.*;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.*;

import java.time.LocalDate;
import java.util.List;

public class CommentDto
{
Expand Down Expand Up @@ -268,7 +266,7 @@ public static class StartUpdate
@Schema(description = "학점")
private String credit;
@Schema(description = "시간, 장소")
private String time_location;
private List<CourseDto.TimeLocation> time_locations;
@NotNull(message = "COUNT_comments는 null일 수 없습니다.")
@Schema(description = "강의평 개수")
private int COUNT_comments;
Expand Down Expand Up @@ -566,7 +564,7 @@ public static class MyPage
@Schema(description = "학점")
private String credit;
@Schema(description = "시간, 장소")
private String time_location;
private List<CourseDto.TimeLocation> time_locations;

@NotBlank(message = "[review] cannot be blank.")
@Schema(description = "강의평 내용")
Expand Down Expand Up @@ -629,10 +627,13 @@ public static class MyPage
private boolean learn_t4_industry;
}

public static CommentDto.StartUpdate entityToStartUpdate(Course course,
CourseRating courseRating,
com.example.Devkor_project.entity.Comment comment,
CommentRating commentRating)
public static CommentDto.StartUpdate entityToStartUpdate(
Course course,
CourseRating courseRating,
com.example.Devkor_project.entity.Comment comment,
CommentRating commentRating,
List<TimeLocation> timeLocations
)
{
return StartUpdate.builder()
.course_id(course.getCourse_id())
Expand All @@ -645,7 +646,18 @@ public static CommentDto.StartUpdate entityToStartUpdate(Course course,
.name(course.getName())
.professor(course.getProfessor())
.credit(course.getCredit())
.time_location(course.getTime_location())
.time_locations(
timeLocations.stream().map(
timeLocation -> {
return CourseDto.TimeLocation.builder()
.day(timeLocation.getDay())
.startPeriod(timeLocation.getStartPeriod())
.endPeriod(timeLocation.getEndPeriod())
.location(timeLocation.getLocation())
.build();
})
.toList()
)
.COUNT_comments(course.getCOUNT_comments())
.AVG_rating(courseRating.getAVG_rating())
.AVG_r1_amount_of_studying(courseRating.getAVG_r1_amount_of_studying())
Expand Down Expand Up @@ -680,9 +692,12 @@ public static CommentDto.StartUpdate entityToStartUpdate(Course course,
.build();
}

public static CommentDto.MyPage entityToMyPage(com.example.Devkor_project.entity.Comment comment,
Course course,
CommentRating commentRating)
public static CommentDto.MyPage entityToMyPage(
com.example.Devkor_project.entity.Comment comment,
Course course,
CommentRating commentRating,
List<TimeLocation> timeLocations
)
{
return MyPage.builder()
.comment_id(comment.getComment_id())
Expand All @@ -696,7 +711,18 @@ public static CommentDto.MyPage entityToMyPage(com.example.Devkor_project.entity
.name(course.getName())
.professor(course.getProfessor())
.credit(course.getCredit())
.time_location(course.getTime_location())
.time_locations(
timeLocations.stream().map(
timeLocation -> {
return CourseDto.TimeLocation.builder()
.day(timeLocation.getDay())
.startPeriod(timeLocation.getStartPeriod())
.endPeriod(timeLocation.getEndPeriod())
.location(timeLocation.getLocation())
.build();
})
.toList()
)
.review(comment.getReview())
.likes(comment.getLikes())
.created_at(comment.getCreated_at())
Expand Down
94 changes: 78 additions & 16 deletions src/main/java/com/example/Devkor_project/dto/CourseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.Devkor_project.entity.Course;
import com.example.Devkor_project.entity.CourseRating;
import com.example.Devkor_project.entity.TimeLocation;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static class Basic
@Schema(description = "학점")
private String credit;
@Schema(description = "시간, 장소")
private String time_location;
private List<CourseDto.TimeLocation> time_locations;
@NotNull(message = "COUNT_comments는 null일 수 없습니다.")
@Schema(description = "강의평 개수")
private int COUNT_comments;
Expand Down Expand Up @@ -138,7 +139,7 @@ public static class ExpiredBasic
@Schema(description = "학점")
private String credit;
@Schema(description = "시간, 장소")
private String time_location;
private List<CourseDto.TimeLocation> time_locations;
@NotNull(message = "COUNT_comments는 null일 수 없습니다.")
@Schema(description = "강의평 개수")
private int COUNT_comments;
Expand Down Expand Up @@ -183,7 +184,7 @@ public static class Detail
@Schema(description = "학점")
private String credit;
@Schema(description = "시간, 장소")
private String time_location;
private List<CourseDto.TimeLocation> time_locations;
@NotNull(message = "COUNT_comments는 null일 수 없습니다.")
@Schema(description = "강의평 개수")
private int COUNT_comments;
Expand Down Expand Up @@ -275,7 +276,7 @@ public static class ExpiredDetail
@Schema(description = "학점")
private String credit;
@Schema(description = "시간, 장소")
private String time_location;
private List<CourseDto.TimeLocation> time_locations;
@NotNull(message = "COUNT_comments는 null일 수 없습니다.")
@Schema(description = "강의평 개수")
private int COUNT_comments;
Expand Down Expand Up @@ -324,7 +325,13 @@ public static class TimeLocation
private String location;
}

public static CourseDto.Basic entityToBasic(Course course, CourseRating courseRating, Boolean isBookmark) {
public static CourseDto.Basic entityToBasic(
Course course,
CourseRating courseRating,
List<com.example.Devkor_project.entity.TimeLocation> timeLocations,
Boolean isBookmark
)
{
return Basic.builder()
.course_id(course.getCourse_id())
.course_code(course.getCourse_code())
Expand All @@ -336,7 +343,18 @@ public static CourseDto.Basic entityToBasic(Course course, CourseRating courseRa
.name(course.getName())
.professor(course.getProfessor())
.credit(course.getCredit())
.time_location(course.getTime_location())
.time_locations(
timeLocations.stream().map(
timeLocation -> {
return CourseDto.TimeLocation.builder()
.day(timeLocation.getDay())
.startPeriod(timeLocation.getStartPeriod())
.endPeriod(timeLocation.getEndPeriod())
.location(timeLocation.getLocation())
.build();
})
.toList()
)
.COUNT_comments(course.getCOUNT_comments())
.isBookmark(isBookmark)
.AVG_rating(courseRating.getAVG_rating())
Expand All @@ -356,7 +374,12 @@ public static CourseDto.Basic entityToBasic(Course course, CourseRating courseRa
.build();
}

public static CourseDto.ExpiredBasic entityToExpiredBasic(Course course, Boolean isBookmark) {
public static CourseDto.ExpiredBasic entityToExpiredBasic(
Course course,
List<com.example.Devkor_project.entity.TimeLocation> timeLocations,
Boolean isBookmark
)
{
return ExpiredBasic.builder()
.course_id(course.getCourse_id())
.course_code(course.getCourse_code())
Expand All @@ -368,16 +391,30 @@ public static CourseDto.ExpiredBasic entityToExpiredBasic(Course course, Boolean
.name(course.getName())
.professor(course.getProfessor())
.credit(course.getCredit())
.time_location(course.getTime_location())
.time_locations(
timeLocations.stream().map(
timeLocation -> {
return CourseDto.TimeLocation.builder()
.day(timeLocation.getDay())
.startPeriod(timeLocation.getStartPeriod())
.endPeriod(timeLocation.getEndPeriod())
.location(timeLocation.getLocation())
.build();
})
.toList()
)
.COUNT_comments(course.getCOUNT_comments())
.isBookmark(isBookmark)
.build();
}

public static CourseDto.Detail entityToDetail(Course course,
CourseRating courseRating,
List<CommentDto.Detail> commentDtos,
Boolean isBookmark)
public static CourseDto.Detail entityToDetail(
Course course,
CourseRating courseRating,
List<CommentDto.Detail> commentDtos,
List<com.example.Devkor_project.entity.TimeLocation> timeLocations,
Boolean isBookmark
)
{
return Detail.builder()
.course_id(course.getCourse_id())
Expand All @@ -390,7 +427,18 @@ public static CourseDto.Detail entityToDetail(Course course,
.name(course.getName())
.professor(course.getProfessor())
.credit(course.getCredit())
.time_location(course.getTime_location())
.time_locations(
timeLocations.stream().map(
timeLocation -> {
return CourseDto.TimeLocation.builder()
.day(timeLocation.getDay())
.startPeriod(timeLocation.getStartPeriod())
.endPeriod(timeLocation.getEndPeriod())
.location(timeLocation.getLocation())
.build();
})
.toList()
)
.COUNT_comments(course.getCOUNT_comments())
.isBookmark(isBookmark)
.AVG_rating(courseRating.getAVG_rating())
Expand All @@ -411,8 +459,11 @@ public static CourseDto.Detail entityToDetail(Course course,
.build();
}

public static CourseDto.ExpiredDetail entityToExpiredDetail(Course course,
Boolean isBookmark)
public static CourseDto.ExpiredDetail entityToExpiredDetail(
Course course,
List<com.example.Devkor_project.entity.TimeLocation> timeLocations,
Boolean isBookmark
)
{
return ExpiredDetail.builder()
.course_id(course.getCourse_id())
Expand All @@ -425,7 +476,18 @@ public static CourseDto.ExpiredDetail entityToExpiredDetail(Course course,
.name(course.getName())
.professor(course.getProfessor())
.credit(course.getCredit())
.time_location(course.getTime_location())
.time_locations(
timeLocations.stream().map(
timeLocation -> {
return CourseDto.TimeLocation.builder()
.day(timeLocation.getDay())
.startPeriod(timeLocation.getStartPeriod())
.endPeriod(timeLocation.getEndPeriod())
.location(timeLocation.getLocation())
.build();
})
.toList()
)
.COUNT_comments(course.getCOUNT_comments())
.isBookmark(isBookmark)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ public class Course
@Column(nullable = false) private String year;
@Column(nullable = false) private String semester;
@Column private String credit;
@Column private String time_location;
@Column(nullable = false) private int COUNT_comments;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package com.example.Devkor_project.repository;

import com.example.Devkor_project.entity.Course;
import com.example.Devkor_project.entity.TimeLocation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface TimeLocationRepository extends JpaRepository<TimeLocation, Long> {
import java.util.List;

public interface TimeLocationRepository extends JpaRepository<TimeLocation, Long>
{
@Query(value = "SELECT * FROM time_location WHERE course_id = :course_id", nativeQuery = true)
List<TimeLocation> findByCourseId(Long course_id);
}
Loading
Loading