Skip to content

Commit

Permalink
Merge pull request #15 from khu-bigdata-project-team-5/feat/1
Browse files Browse the repository at this point in the history
Feat/1: Lecture API ๊ตฌํ˜„(#1)
  • Loading branch information
yxhwxn authored Jun 10, 2024
2 parents 4939977 + b05a893 commit 19f2341
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 85 deletions.
43 changes: 29 additions & 14 deletions src/main/java/khu/bigdata/infou/business/LectureConverter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package khu.bigdata.infou.business;

import khu.bigdata.infou.domain.LectureTag;
import khu.bigdata.infou.domain.LectureDetail;
import khu.bigdata.infou.domain.LectureUdemy;
import khu.bigdata.infou.web.dto.LectureResponseDTO;

Expand All @@ -12,19 +12,15 @@ public class LectureConverter {

public static LectureResponseDTO.CategoryRecommendLectureInfo toCategoryRecommendLectureInfo(LectureUdemy lectureUdemy) {

LectureTag lectureTag = lectureUdemy.getLectureTag();

return LectureResponseDTO.CategoryRecommendLectureInfo.builder()
.lectureId(lectureUdemy.getLectureId())
.title(lectureUdemy.getTitle())
.price(lectureUdemy.getPrice())
.avgRating(lectureUdemy.getAvgRating())
.thumbnail(lectureUdemy.getThumbnail())
.topword1(lectureTag.getTopword1())
.topword2(lectureTag.getTopword2())
.topword3(lectureTag.getTopword3())
.topword4(lectureTag.getTopword4())
.topword5(lectureTag.getTopword5())
.instructorName(lectureUdemy.getInstructorName())
.topword1(lectureUdemy.getTopic())
.topword2(lectureUdemy.getSubcategory())
.build();
}

Expand All @@ -40,19 +36,16 @@ public static LectureResponseDTO.CategoryRecommendLectureDto toCategoryRecommend

// ํ‚ค์›Œ๋“œ๋ณ„ ์ถ”์ฒœ ๊ฐ•์ขŒ ์กฐํšŒ
public static LectureResponseDTO.KeywordRecommendLectureInfo toKeywordRecommendLectureInfo(LectureUdemy lectureUdemy) {
LectureTag lectureTag = lectureUdemy.getLectureTag();

return LectureResponseDTO.KeywordRecommendLectureInfo.builder()
.lectureId(lectureUdemy.getLectureId())
.title(lectureUdemy.getTitle())
.price(lectureUdemy.getPrice())
.avgRating(lectureUdemy.getAvgRating())
.thumbnail(lectureUdemy.getThumbnail())
.topword1(lectureTag.getTopword1())
.topword2(lectureTag.getTopword2())
.topword3(lectureTag.getTopword3())
.topword4(lectureTag.getTopword4())
.topword5(lectureTag.getTopword5())
.instructorName(lectureUdemy.getInstructorName())
.topword1(lectureUdemy.getTopic())
.topword2(lectureUdemy.getSubcategory())
.build();
}

Expand All @@ -67,4 +60,26 @@ public static LectureResponseDTO.KeywordRecommendLectureDto toKeywordRecommendLe
.build();
}

// ๊ฐ•์ขŒ ์„ธ๋ถ€ ์กฐํšŒ
public static LectureResponseDTO.LectureDetailDto toLectureDetailDto(LectureUdemy lectureUdemy, LectureDetail lectureDetail) {

return LectureResponseDTO.LectureDetailDto.builder()
.lectureId(lectureUdemy.getLectureId())
.title(lectureUdemy.getTitle())
.price(lectureUdemy.getPrice())
.avgRating(lectureUdemy.getAvgRating())
.thumbnail(lectureUdemy.getThumbnail())
.instructorName(lectureUdemy.getInstructorName())
.category(lectureUdemy.getCategory())
.subcategory(lectureUdemy.getSubcategory())
.good(lectureDetail.getGood())
.bad(lectureDetail.getBad())
.teaching_quality(lectureDetail.getTeachingQuality())
.reference(lectureDetail.getReference())
.practice(lectureDetail.getPractice())
.rating(lectureDetail.getRating())
.level(lectureDetail.getLevel())
.topword(lectureUdemy.getTopic())
.build();
}
}
3 changes: 2 additions & 1 deletion src/main/java/khu/bigdata/infou/domain/LectureDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
@DynamicInsert
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED) // ์ƒ์„ฑ ๋กœ์ง ๊ทœ์ •
@Table(name = "lecture_detail")
@Table(name = "lecture_detail", indexes = {
@Index(name = "idx_lecture_id", columnList = "lectureId")})
public class LectureDetail {

@Id
Expand Down
24 changes: 6 additions & 18 deletions src/main/java/khu/bigdata/infou/domain/LectureUdemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import lombok.*;
import org.hibernate.annotations.DynamicInsert;

import java.util.Date;

@Entity
@Getter
@Builder
@DynamicInsert
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED) // ์ƒ์„ฑ ๋กœ์ง ๊ทœ์ •
@Table(name = "lecture_udemy")
@Table(name = "lecture_udemy", indexes = {
@Index(name = "idx_lecture_id", columnList = "lectureId")})
public class LectureUdemy {

@Id
Expand Down Expand Up @@ -53,13 +52,13 @@ public class LectureUdemy {
@Column(name = "content_length_min")
private float contentLengthMin;

@Column(name = "category", length = 255)
@Column(name = "category")
private String category;

@Column(name = "subcategory", length = 50)
@Column(name = "subcategory")
private String subcategory;

@Column(name = "topic", length = 50)
@Column(name = "topic")
private String topic;

@Column(name = "language", length = 20)
Expand All @@ -68,23 +67,12 @@ public class LectureUdemy {
@Column(name = "course_url", columnDefinition = "TEXT")
private String courseUrl;

@Column(name = "instructor_name", length = 50)
@Column(name = "instructor_name")
private String instructorName;

@Column(name = "instructor_url", columnDefinition = "TEXT")
private String instructorUrl;

@Column(name = "thumbnail", columnDefinition = "TEXT")
private String thumbnail;

@Column(name = "published_time")
@Temporal(TemporalType.DATE)
private Date publishedTime;

@Column(name = "last_update_date")
@Temporal(TemporalType.DATE)
private Date lastUpdateDate;

@ManyToOne(fetch = FetchType.LAZY)
private PlatformStudentLecture platformStudentLecture;

Expand Down
33 changes: 22 additions & 11 deletions src/main/java/khu/bigdata/infou/implement/LectureService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package khu.bigdata.infou.implement;

import khu.bigdata.infou.business.LectureConverter;
import khu.bigdata.infou.domain.LectureDetail;
import khu.bigdata.infou.domain.LectureUdemy;
import khu.bigdata.infou.repository.LectureDetailRepository;
import khu.bigdata.infou.repository.LectureInflearnRepository;
import khu.bigdata.infou.repository.LectureUdemyRepository;
import khu.bigdata.infou.web.dto.LectureResponseDTO;
Expand All @@ -20,9 +22,10 @@ public class LectureService {

private final LectureInflearnRepository lectureInflearnRepository;
private final LectureUdemyRepository lectureUdemyRepository;
private final LectureDetailRepository lectureDetailRepository;


// ๋ฉ”์ธํŽ˜์ด์ง€ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์ถ”์ฒœ ๊ฐ•์ขŒ ์กฐํšŒ
// ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์ถ”์ฒœ ๊ฐ•์ขŒ ์กฐํšŒ
public LectureResponseDTO.CategoryRecommendLectureDto findRecommendedLectureByCategory(String category) {

if (category == null) {
Expand All @@ -33,7 +36,7 @@ public LectureResponseDTO.CategoryRecommendLectureDto findRecommendedLectureByCa

// ์ผ๋‹จ ๊ฐ€์ ธ์˜ค๊ณ  ์ƒ์œ„ ๊ฐ’ ์ถ”์ถœ
List<LectureUdemy> sortedList = lectureUdemyList.stream()
.sorted(Comparator.comparingDouble(lecture -> lecture.getAvgRating() * lecture.getNumReviews()))
.sorted(Comparator.comparingDouble((LectureUdemy lecture) -> lecture.getAvgRating() * lecture.getNumReviews()).reversed())
.collect(Collectors.toList());

return LectureConverter.toCategoryRecommendLectureDto(sortedList);
Expand All @@ -46,20 +49,32 @@ public LectureResponseDTO.KeywordRecommendLectureDto findRecommendedLectureByKey
throw new IllegalArgumentException("Keyword must not be null or empty");
}

// ํ‚ค์›Œ๋“œ๋ฅผ ํฌํ•จํ•˜๋Š” ๊ฐ•์˜ ๋ชฉ๋ก์„ ์กฐํšŒ
List<LectureUdemy> lectureUdemyList = lectureUdemyRepository.findAllByTitleContaining(keyword);
// ํ‚ค์›Œ๋“œ๋ฅผ ํฌํ•จํ•˜๋Š” ๊ฐ•์˜ ๋ชฉ๋ก์„ ์กฐํšŒ(topic ๋ฐ์ดํ„ฐ์— ์žˆ๋Š”์ง€ ํ™•์ธ)
List<LectureUdemy> lectureUdemyList = lectureUdemyRepository.findAllByTopic(keyword);

// ์กฐํšŒ๋œ ๊ฐ•์˜ ๋ชฉ๋ก์„ AvgRating๊ณผ NumReviews์˜ ๊ฐ’์„ ๊ณฑํ•œ ๊ฐ’์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ
List<LectureUdemy> sortedList = lectureUdemyList.stream()
.sorted(Comparator.comparingDouble(lecture -> lecture.getAvgRating() * lecture.getNumReviews()))
.sorted(Comparator.comparingDouble((LectureUdemy lecture) -> lecture.getAvgRating() * lecture.getNumReviews()).reversed())
.collect(Collectors.toList());

// ์กฐํšŒ๋œ ๊ฐ•์˜ ๋ชฉ๋ก์„ DTO๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜
return LectureConverter.toKeywordRecommendLectureDto(sortedList);
}

public LectureResponseDTO.LectureDetailDto findLectureDetail() {
return null;
// ๊ฐ•์ขŒ ์„ธ๋ถ€ ์กฐํšŒ
public LectureResponseDTO.LectureDetailDto findLectureDetail(Integer lectureId) {

// lectureId๊ฐ€ null์ธ ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ
if (lectureId == null) {
throw new IllegalArgumentException("LectureId must not be null");
}

LectureUdemy lectureUdemy = lectureUdemyRepository.findByLectureId(Long.valueOf(lectureId))
.orElseThrow(() -> new IllegalArgumentException("Lecture not found"));
LectureDetail lectureDetail = lectureDetailRepository.findByLectureId(Long.valueOf(lectureId))
.orElseThrow(() -> new IllegalArgumentException("Lecture detail not found"));

return LectureConverter.toLectureDetailDto(lectureUdemy, lectureDetail);
}

public LectureResponseDTO.OtherStudentsDto findOtherStudents() {
Expand All @@ -70,8 +85,4 @@ public LectureResponseDTO.OtherLectureListDto findOtherLectureList() {
return null;
}


public LectureResponseDTO.StudentTopwordDto findStudentTopword() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package khu.bigdata.infou.repository;

import khu.bigdata.infou.domain.LectureDetail;
import khu.bigdata.infou.domain.LectureUdemy;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface LectureDetailRepository extends JpaRepository<LectureDetail, Long> {

Optional<LectureDetail> findByLectureUdemy(LectureUdemy lectureUdemy);

Optional<LectureDetail> findByLectureId(Long lectureId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

import khu.bigdata.infou.domain.LectureUdemy;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface LectureUdemyRepository extends JpaRepository<LectureUdemy, Long> {

public List<LectureUdemy> findAllBySubcategory(String subcategory);

public List<LectureUdemy> findAllByTitleContaining(String keyword);
@Query("select l from LectureUdemy l left join fetch l.lectureTag where l.subcategory = :subcategory")
List<LectureUdemy> findAllBySubcategory(String subcategory);

List<LectureUdemy> findAllByTopic(String topic);

Optional<LectureUdemy> findByLectureId(Long lectureId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package khu.bigdata.infou.repository;

import khu.bigdata.infou.domain.PlatformStudentLecture;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PlatformStudentLectureRepository extends JpaRepository<PlatformStudentLecture, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package khu.bigdata.infou.repository;

import khu.bigdata.infou.domain.PlatformStudent;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PlatformStudentRepository extends JpaRepository<PlatformStudent, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/api")
public class MainController {
public class MainServiceController {

private final LectureService lectureService;

@GetMapping("/lectures/categories")
@Operation(summary = "์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์ถ”์ฒœ ๊ฐ•์ขŒ ์กฐํšŒ API", description = "์นดํ…Œ๊ณ ๋ฆฌ: ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด, ์›น ๊ฐœ๋ฐœ, ๊ฒŒ์ž„ ๊ฐœ๋ฐœ, ๋ชจ๋ฐ”์ผ ์•ฑ ๊ฐœ๋ฐœ, ๋ฐ์ดํ„ฐ ์‚ฌ์ด์–ธ์Šค, ์ธ๊ณต์ง€๋Šฅ")
@Operation(summary = "์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์ถ”์ฒœ ๊ฐ•์ขŒ ์กฐํšŒ API", description = "์นดํ…Œ๊ณ ๋ฆฌ: Programming Language, Web Development, Game Development, Mobile Development, Data Science")
public ResponseEntity<LectureResponseDTO.CategoryRecommendLectureDto> getRecommendedLectureByCategory(
@RequestParam(name = "category") String category
) {
Expand All @@ -26,7 +26,7 @@ public ResponseEntity<LectureResponseDTO.CategoryRecommendLectureDto> getRecomme


@GetMapping("/curriculum/recommendation")
@Operation(summary = "์„ ํƒ๋œ ํ‚ค์›Œ๋“œ๋ณ„ ์ถ”์ฒœ ๊ฐ•์ขŒ ์กฐํšŒ API", description = "์œ ์ €๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›์€ ํ‚ค์›Œ๋“œ 4๊ฐœ๋ฅผ ์ž…๋ ฅ๋ฐ›์Šต๋‹ˆ๋‹ค.")
@Operation(summary = "์„ ํƒ๋œ ํ‚ค์›Œ๋“œ๋ณ„ ์ถ”์ฒœ ๊ฐ•์ขŒ ์กฐํšŒ API", description = "์œ ์ €๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›์€ ํ‚ค์›Œ๋“œ์™€ ์ผ์น˜ํ•˜๋Š” ๊ฐ•์ขŒ๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
public ResponseEntity<LectureResponseDTO.KeywordRecommendLectureDto> getRecommendedLectureByKeyword(
@RequestParam(name = "keyword") String keyword
) {
Expand All @@ -39,9 +39,12 @@ public ResponseEntity<LectureResponseDTO.KeywordRecommendLectureDto> getRecommen
public ResponseEntity<LectureResponseDTO.LectureDetailDto> getLectureDetail(
@PathVariable(name = "lectureId") Integer lectureId
) {
return ResponseEntity.ok(lectureService.findLectureDetail());
return ResponseEntity.ok(lectureService.findLectureDetail(lectureId));
}

/**
* TODO
*/
@GetMapping("/others")
@Operation(summary = "๋‹ค๋ฅธ ์ˆ˜๊ฐ•์ƒ๋“ค์˜ ์ปค๋ฆฌํ˜๋Ÿผ ์ „์ฒด ์กฐํšŒ API")
public ResponseEntity<LectureResponseDTO.OtherStudentsDto> getOtherStudents() {
Expand All @@ -55,12 +58,4 @@ public ResponseEntity<LectureResponseDTO.OtherLectureListDto> getOtherLectureLis
) {
return ResponseEntity.ok(lectureService.findOtherLectureList());
}

@GetMapping("/others/{userId}")
@Operation(summary = "ํŠน์ • ์ˆ˜๊ฐ•์ƒ์˜ topword ์กฐํšŒ API", description = "์œ ์ €๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›์€ ํ‚ค์›Œ๋“œ 4๊ฐœ๋ฅผ ์ž…๋ ฅ๋ฐ›์Šต๋‹ˆ๋‹ค.")
public ResponseEntity<LectureResponseDTO.StudentTopwordDto> getStudentTopword(
@PathVariable(name = "userId") Integer userId
) {
return ResponseEntity.ok(lectureService.findStudentTopword());
}
}
17 changes: 0 additions & 17 deletions src/main/java/khu/bigdata/infou/web/controller/TestController.java

This file was deleted.

Loading

0 comments on commit 19f2341

Please sign in to comment.