Skip to content

Commit

Permalink
Merge pull request TeamMajorLink#47 from chaerinryu/feat#30
Browse files Browse the repository at this point in the history
✨ [FEAT] 클래스 목록 조회 및 검색 기능
  • Loading branch information
chaerinryu authored Aug 18, 2024
2 parents 6157342 + 8c9f7a5 commit f650b88
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,17 @@ public void deleteLecture(@PathVariable(name = "lectureId") Long lectureId,
@GetMapping("/list")
@ResponseBody
// 스웨거 세팅 후 파라미터 등 설명 추가
public LectureResponseDTO.LecturePreViewList getLectures(@RequestParam(name = "page") Integer page){
public LectureResponseDTO.LecturePreViewList getLectures(@RequestParam(name = "page", defaultValue = "1") Integer page){
Page<Lecture> lectureList = lectureService.getLectureList(page-1);

return LectureResponseDTO.LecturePreViewList.builder()
.lectureList(lectureList.stream()
.map(lecture -> LectureResponseDTO.LecturePreView.builder()
.name(lecture.getName())
.cNum(lecture.getCNum())
.pNum(lecture.getPNum())
.mainCategory(lecture.getCategory().getMainCategory())
.subCategory(lecture.getCategory().getSubCategory())
.build())
.collect(Collectors.toList()))
.listSize(lectureList.getNumberOfElements())
Expand All @@ -85,6 +89,31 @@ public LectureResponseDTO.LecturePreViewList getLectures(@RequestParam(name = "p
.build();
}

// 강의 상세페이지
@GetMapping("/{lectureId}/details")
@ResponseBody
public LectureResponseDTO.LectureDetails getLecture(@PathVariable(name = "lectureId") Long lectureId){
Lecture lecture = lectureService.getLecture(lectureId);

return LectureResponseDTO.LectureDetails.builder()
.name(lecture.getName())
.body(lecture.getBody())
.curri(lecture.getCurri())
.info(lecture.getInfo())
.level(lecture.getLevel().name())
.cNum(lecture.getCNum())
.pNum(lecture.getPNum())
.time(lecture.getTime().toString())
.day(lecture.getDay().name())
.startDate(lecture.getStartDate())
.exam(lecture.getExam().name())
.tag(lecture.getTag())
.tutor(lecture.getTutor())
.mainCategory(lecture.getCategory().getMainCategory())
.subCategory(lecture.getCategory().getSubCategory())
.build();
}

// 강의 수강 신청 api
@PostMapping("/{lectureId}/register")
@ResponseBody
Expand All @@ -100,16 +129,6 @@ public LectureResponseDTO.CreateTuteeLecture createTuteeLecture(@PathVariable(na
.build();
}

// 강의 취소 api
@DeleteMapping("/{lectureId}/cancel")
@ResponseBody
public void cancelLecture(@PathVariable(name = "lectureId") Long lectureId,
@AuthenticationPrincipal AuthUser authUser){
User user = authUser.getUser();

lectureService.cancelLecture(user.getId(), lectureId);
}

// 강의 좋아요 토글 api
@PostMapping("/{lectureId}/like")
@ResponseBody
Expand All @@ -123,13 +142,17 @@ public Boolean toggleLike(@PathVariable(name = "lectureId") Long lectureId,
// 좋아요 많은 강의 조회 api
@GetMapping("/mostLiked")
@ResponseBody
public LectureResponseDTO.LecturePreViewList getMostLikedLectures(@RequestParam(name = "page") Integer page){
public LectureResponseDTO.LecturePreViewList getMostLikedLectures(@RequestParam(name = "page", defaultValue = "1") Integer page){
Page<Lecture> lectureList = lectureService.getMostLikedLecture(page-1);

return LectureResponseDTO.LecturePreViewList.builder()
.lectureList(lectureList.stream()
.map(lecture -> LectureResponseDTO.LecturePreView.builder()
.name(lecture.getName())
.mainCategory(lecture.getCategory().getMainCategory())
.subCategory(lecture.getCategory().getSubCategory())
.cNum(lecture.getCNum())
.pNum(lecture.getPNum())
.build())
.collect(Collectors.toList()))
.listSize(lectureList.getNumberOfElements())
Expand All @@ -143,13 +166,17 @@ public LectureResponseDTO.LecturePreViewList getMostLikedLectures(@RequestParam(
// 최신 강의 조회 api
@GetMapping("/new")
@ResponseBody
public LectureResponseDTO.LecturePreViewList getNewLectures(@RequestParam(name = "page") Integer page){
public LectureResponseDTO.LecturePreViewList getNewLectures(@RequestParam(name = "page", defaultValue = "1") Integer page){
Page<Lecture> lectureList = lectureService.getNewLecture(page-1);

return LectureResponseDTO.LecturePreViewList.builder()
.lectureList(lectureList.stream()
.map(lecture -> LectureResponseDTO.LecturePreView.builder()
.name(lecture.getName())
.mainCategory(lecture.getCategory().getMainCategory())
.subCategory(lecture.getCategory().getSubCategory())
.cNum(lecture.getCNum())
.pNum(lecture.getPNum())
.build())
.collect(Collectors.toList()))
.listSize(lectureList.getNumberOfElements())
Expand All @@ -163,13 +190,17 @@ public LectureResponseDTO.LecturePreViewList getNewLectures(@RequestParam(name =
// 가장 많이 모집된 강의 조회 api
@GetMapping("/mostRecruited")
@ResponseBody
public LectureResponseDTO.LecturePreViewList getMostRecruitedLectures(@RequestParam(name = "page") Integer page){
public LectureResponseDTO.LecturePreViewList getMostRecruitedLectures(@RequestParam(name = "page", defaultValue = "1") Integer page){
Page<Lecture> lectureList = lectureService.getMostRecruitedLecture(page-1);

return LectureResponseDTO.LecturePreViewList.builder()
.lectureList(lectureList.stream()
.map(lecture -> LectureResponseDTO.LecturePreView.builder()
.name(lecture.getName())
.mainCategory(lecture.getCategory().getMainCategory())
.subCategory(lecture.getCategory().getSubCategory())
.cNum(lecture.getCNum())
.pNum(lecture.getPNum())
.build())
.collect(Collectors.toList()))
.listSize(lectureList.getNumberOfElements())
Expand All @@ -183,14 +214,18 @@ public LectureResponseDTO.LecturePreViewList getMostRecruitedLectures(@RequestPa
// 카테고리별 강의 조회 api
@GetMapping("/{categoryId}")
@ResponseBody
public LectureResponseDTO.LecturePreViewList getLecturesByCategory(@RequestParam(name = "page") Integer page,
public LectureResponseDTO.LecturePreViewList getLecturesByCategory(@RequestParam(name = "page", defaultValue = "1") Integer page,
@PathVariable(name = "categoryId") Long categoryId){
Page<Lecture> lectureList = lectureService.getLectureByCategory(page-1, categoryId);

return LectureResponseDTO.LecturePreViewList.builder()
.lectureList(lectureList.stream()
.map(lecture -> LectureResponseDTO.LecturePreView.builder()
.name(lecture.getName())
.mainCategory(lecture.getCategory().getMainCategory())
.subCategory(lecture.getCategory().getSubCategory())
.cNum(lecture.getCNum())
.pNum(lecture.getPNum())
.build())
.collect(Collectors.toList()))
.listSize(lectureList.getNumberOfElements())
Expand All @@ -200,4 +235,30 @@ public LectureResponseDTO.LecturePreViewList getLecturesByCategory(@RequestParam
.isLast(lectureList.isLast())
.build();
}

// 메인 카테고리 조회 api
@GetMapping("/categories/main")
@ResponseBody
public LectureResponseDTO.MainCategory getMainCategory() {
return LectureResponseDTO.MainCategory.builder()
.mainCategoryList(lectureService.getMainCategory())
.build();
}

// 서브 카테고리 조회 api
@GetMapping("/categories/sub")
@ResponseBody
public LectureResponseDTO.SubCategory getSubCategory(@RequestParam(name = "mainCategory") String mainCategory) {
return LectureResponseDTO.SubCategory.builder()
.subCategoryList(lectureService.getSubCategory(mainCategory))
.build();
}

// 카테고리 id 조회 api
@GetMapping("/categories/id")
@ResponseBody
public Long getCategoryId(@RequestParam(name = "mainCategory") String mainCategory,
@RequestParam(name = "subCategory") String subCategory) {
return lectureService.getCategoryId(mainCategory, subCategory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public ReviewResponseDTO.ReviewPreViewList getReviews(@PathVariable(name = "lect
.reviewList(reviewList.stream()
.map(review -> ReviewResponseDTO.ReviewPreView.builder()
.ownerNickname(review.getUser().getUsername())
.createdAt(review.getCreatedAt())
.title(review.getTitle())
.rate(review.getRate())
.build())
.collect(Collectors.toList()))
Expand All @@ -86,11 +88,12 @@ public ReviewResponseDTO.ReviewPreViewList getReviews(@PathVariable(name = "lect
// 리뷰 내용 조회 api
@GetMapping("/{reviewId}/details")
@ResponseBody
public ReviewResponseDTO.ReviewPreView getReview(@PathVariable(name = "reviewId") Long reviewId){
public ReviewResponseDTO.ReviewDetails getReview(@PathVariable(name = "reviewId") Long reviewId){
Review review = reviewService.getReview(reviewId);

return ReviewResponseDTO.ReviewPreView.builder()
return ReviewResponseDTO.ReviewDetails.builder()
.ownerNickname(review.getUser().getUsername())
.title(review.getTitle())
.rate(review.getRate())
.content(review.getContent())
.createdAt(review.getCreatedAt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Lecture extends BaseEntity{
private String body;

@Column(nullable = false)
private int curri;
private Integer curri;

@Column(nullable = false, length = 1000)
private String info;
Expand All @@ -38,11 +38,11 @@ public class Lecture extends BaseEntity{

// 총 인원
@Column(nullable = false)
private int pNum;
private Integer pNum;

// 현재 신청 인원
@Column(nullable = false)
private int curPNum;
private Integer cNum;

private LocalTime time;

Expand All @@ -57,7 +57,7 @@ public class Lecture extends BaseEntity{
@Column(nullable = false, columnDefinition = "VARCHAR(10)")
private Exam exam;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id")
private Category category;

Expand All @@ -83,10 +83,10 @@ public void updateLecture(String name, String body, int curri, String info, Leve
}

public void addCurPNum(){
this.curPNum++;
this.cNum++;
}

public void subCurPNum(){
this.curPNum--;
this.cNum--;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@
import com.example.majorLink.domain.enums.Day;
import com.example.majorLink.domain.enums.Exam;
import com.example.majorLink.domain.enums.Level;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalTime;
import java.util.Date;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class LectureRequestDTO {
// 새로운 강의 등록할때 필요한 정보들 작성
String name;
String body; // 강의 개요
int curri; // 강의 횟수
Integer curri; // 강의 횟수
String info; // 강의 정보
Level level;
int pNum;
LocalTime time;
Day day; // 요일
Date startDate;
Exam exam; // 시험 유무
Long categoryId;
String tag;
Integer num; // 정원
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

public class LectureResponseDTO {
Expand All @@ -24,6 +25,32 @@ public static class CreateLecture {
@NoArgsConstructor
public static class LecturePreView {
String name;
Integer cNum;
Integer pNum;
String mainCategory;
String subCategory;
}

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class LectureDetails {
String name;
String body;
Integer curri;
String info;
String level;
Integer cNum;
Integer pNum;
String time;
String day;
Date startDate;
String exam;
String tag;
String tutor;
String mainCategory;
String subCategory;
}

@Builder
Expand Down Expand Up @@ -56,4 +83,20 @@ public static class CreateTuteeLecture {
Long tuteeLectureId;
LocalDateTime createdAt;
}

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class MainCategory {
List<String> mainCategoryList;
}

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class SubCategory {
List<String> subCategoryList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ public static class CreateReview {
public static class ReviewPreView {
String ownerNickname;
int rate;
String title;
LocalDateTime createdAt;
}

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class ReviewDetails {
String ownerNickname;
int rate;
String title;
String content;
LocalDateTime createdAt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

import com.example.majorLink.domain.Category;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

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

@Repository
public interface CategoryRepository extends JpaRepository<Category, Long> {
// 필요한 추가 쿼리 메소드가 있다면 여기에 정의
@Query("SELECT DISTINCT c.mainCategory FROM Category c")
List<String> findMainCategory();

@Query("SELECT c.subCategory FROM Category c WHERE c.mainCategory = :mainCategory")
List<String> findSubCategory(String mainCategory);

Optional<Category> findByMainCategoryAndSubCategory(String mainCategory, String subCategory);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.majorLink.repository;

import com.example.majorLink.domain.Lecture;
import com.example.majorLink.domain.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -11,7 +10,7 @@ public interface LectureRepository extends JpaRepository<Lecture, Long> {
@Query("SELECT l FROM Lecture l ORDER BY (SELECT COUNT(lk) FROM Liked lk WHERE lk.lecture.id = l.id) DESC")
Page<Lecture> orderByLikedCount(Pageable pageable);

@Query("SELECT l FROM Lecture l ORDER BY l.curPNum DESC")
@Query("SELECT l FROM Lecture l ORDER BY l.cNum DESC")
Page<Lecture> orderByCurPNum(Pageable pageable);

@Query("SELECT l FROM Lecture l WHERE l.category.id = :categoryId")
Expand Down
Loading

0 comments on commit f650b88

Please sign in to comment.