Skip to content

Commit

Permalink
Merge pull request TeamMajorLink#41 from chaerinryu/feat#30
Browse files Browse the repository at this point in the history
✨ [FEAT] 강의 기능 구현
  • Loading branch information
chaerinryu authored Aug 17, 2024
2 parents e5bc39b + 57e4deb commit 8dc7c8b
Show file tree
Hide file tree
Showing 19 changed files with 443 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.majorLink.domain.Lecture;
import com.example.majorLink.domain.User;
import com.example.majorLink.domain.mapping.TuteeLecture;
import com.example.majorLink.dto.request.LectureRequestDTO;
import com.example.majorLink.dto.response.LectureResponseDTO;
import com.example.majorLink.global.auth.AuthUser;
Expand All @@ -28,7 +29,7 @@ public LectureResponseDTO.CreateLecture createReview(@RequestBody LectureRequest

User user = authUser.getUser();

Lecture lecture = lectureService.createLecture(user, request);
Lecture lecture = lectureService.createLecture(user.getId(), request);

return LectureResponseDTO.CreateLecture.builder()
.lectureId(lecture.getId())
Expand All @@ -41,10 +42,10 @@ public LectureResponseDTO.CreateLecture createReview(@RequestBody LectureRequest
@ResponseBody
public LectureResponseDTO.UpdateLecture updateLecture(@RequestBody LectureRequestDTO request,
@AuthenticationPrincipal AuthUser authUser,
@PathVariable(name = "lectureId") Long lectureId){
@PathVariable(name = "lectureId") Long lectureId){
User user = authUser.getUser();

Lecture lecture = lectureService.updateLecture(user, lectureId, request);
Lecture lecture = lectureService.updateLecture(user.getId(), request, lectureId);

return LectureResponseDTO.UpdateLecture.builder()
.lectureId(lecture.getId())
Expand All @@ -60,7 +61,7 @@ public void deleteLecture(@PathVariable(name = "lectureId") Long lectureId,

User user = authUser.getUser();

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

// 강의 list 조회 api
Expand All @@ -84,4 +85,119 @@ public LectureResponseDTO.LecturePreViewList getLectures(@RequestParam(name = "p
.build();
}

// 강의 수강 신청 api
@PostMapping("/{lectureId}/register")
@ResponseBody
public LectureResponseDTO.CreateTuteeLecture createTuteeLecture(@PathVariable(name = "lectureId") Long lectureId,
@AuthenticationPrincipal AuthUser authUser){
User user = authUser.getUser();

TuteeLecture tuteeLecture = lectureService.addLecture(user.getId(), lectureId);

return LectureResponseDTO.CreateTuteeLecture.builder()
.tuteeLectureId(tuteeLecture.getId())
.createdAt(user.getCreatedAt())
.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
public Boolean toggleLike(@PathVariable(name = "lectureId") Long lectureId,
@AuthenticationPrincipal AuthUser authUser){
User user = authUser.getUser();

return lectureService.toggleLike(user.getId(), lectureId);
}

// 좋아요 많은 강의 조회 api
@GetMapping("/mostLiked")
@ResponseBody
public LectureResponseDTO.LecturePreViewList getMostLikedLectures(@RequestParam(name = "page") Integer page){
Page<Lecture> lectureList = lectureService.getMostLikedLecture(page-1);

return LectureResponseDTO.LecturePreViewList.builder()
.lectureList(lectureList.stream()
.map(lecture -> LectureResponseDTO.LecturePreView.builder()
.name(lecture.getName())
.build())
.collect(Collectors.toList()))
.listSize(lectureList.getNumberOfElements())
.totalPage(lectureList.getTotalPages())
.totalElements(lectureList.getTotalElements())
.isFirst(lectureList.isFirst())
.isLast(lectureList.isLast())
.build();
}

// 최신 강의 조회 api
@GetMapping("/new")
@ResponseBody
public LectureResponseDTO.LecturePreViewList getNewLectures(@RequestParam(name = "page") Integer page){
Page<Lecture> lectureList = lectureService.getNewLecture(page-1);

return LectureResponseDTO.LecturePreViewList.builder()
.lectureList(lectureList.stream()
.map(lecture -> LectureResponseDTO.LecturePreView.builder()
.name(lecture.getName())
.build())
.collect(Collectors.toList()))
.listSize(lectureList.getNumberOfElements())
.totalPage(lectureList.getTotalPages())
.totalElements(lectureList.getTotalElements())
.isFirst(lectureList.isFirst())
.isLast(lectureList.isLast())
.build();
}

// 가장 많이 모집된 강의 조회 api
@GetMapping("/mostRecruited")
@ResponseBody
public LectureResponseDTO.LecturePreViewList getMostRecruitedLectures(@RequestParam(name = "page") Integer page){
Page<Lecture> lectureList = lectureService.getMostRecruitedLecture(page-1);

return LectureResponseDTO.LecturePreViewList.builder()
.lectureList(lectureList.stream()
.map(lecture -> LectureResponseDTO.LecturePreView.builder()
.name(lecture.getName())
.build())
.collect(Collectors.toList()))
.listSize(lectureList.getNumberOfElements())
.totalPage(lectureList.getTotalPages())
.totalElements(lectureList.getTotalElements())
.isFirst(lectureList.isFirst())
.isLast(lectureList.isLast())
.build();
}

// 카테고리별 강의 조회 api
@GetMapping("/{categoryId}")
@ResponseBody
public LectureResponseDTO.LecturePreViewList getLecturesByCategory(@RequestParam(name = "page") 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())
.build())
.collect(Collectors.toList()))
.listSize(lectureList.getNumberOfElements())
.totalPage(lectureList.getTotalPages())
.totalElements(lectureList.getTotalElements())
.isFirst(lectureList.isFirst())
.isLast(lectureList.isLast())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ReviewController {
private final ReviewService reviewService;

// 리뷰 추가하는 api
@PostMapping("/{lectureId}/reviews")
@PostMapping("/{lectureId}")
@ResponseBody
public ReviewResponseDTO.CreateReview createReview(@RequestBody ReviewRequestDTO request,
@PathVariable(name = "lectureId") Long lectureId,
Expand All @@ -40,8 +40,10 @@ public ReviewResponseDTO.CreateReview createReview(@RequestBody ReviewRequestDTO
@PutMapping("/{reviewId}")
@ResponseBody
public ReviewResponseDTO.UpdateReview updateReview(@RequestBody ReviewRequestDTO request,
@PathVariable(name = "reviewId") Long reviewId){
Review review = reviewService.updateReview(reviewId, request);
@PathVariable(name = "reviewId") Long reviewId,
@AuthenticationPrincipal AuthUser authUser){
User user = authUser.getUser();
Review review = reviewService.updateReview(user.getId(), reviewId, request);

return ReviewResponseDTO.UpdateReview.builder()
.reviewId(review.getId())
Expand All @@ -52,25 +54,25 @@ public ReviewResponseDTO.UpdateReview updateReview(@RequestBody ReviewRequestDTO
// 리뷰 삭제하는 api
@DeleteMapping("/{reviewId}")
@ResponseBody
public void deleteReview(@PathVariable(name = "reviewId") Long reviewId){
reviewService.deleteReview(reviewId);
public void deleteReview(@PathVariable(name = "reviewId") Long reviewId,
@AuthenticationPrincipal AuthUser authUser){
User user = authUser.getUser();

reviewService.deleteReview(user.getId(), reviewId);
}

// 리뷰 조회하는 api
@GetMapping("/{lectureId}/reviews")
@GetMapping("/{lectureId}")
@ResponseBody
// 스웨거 세팅 후 파라미터 등 설명 추가
public ReviewResponseDTO.ReviewPreViewList getReviews(@PathVariable(name = "lectureId") Long lectureId,
@RequestParam(name = "page") Integer page){
@RequestParam(name = "page", defaultValue = "1") Integer page){
Page<Review> reviewList = reviewService.getReviewList(lectureId, page-1);

return ReviewResponseDTO.ReviewPreViewList.builder()
.reviewList(reviewList.stream()
.map(review -> ReviewResponseDTO.ReviewPreView.builder()
.ownerNickname(review.getUser().getUsername())
.rate(review.getRate())
.content(review.getContent())
.createdAt(review.getCreatedAt())
.build())
.collect(Collectors.toList()))
.listSize(reviewList.getNumberOfElements())
Expand All @@ -80,4 +82,18 @@ public ReviewResponseDTO.ReviewPreViewList getReviews(@PathVariable(name = "lect
.isLast(reviewList.isLast())
.build();
}

// 리뷰 내용 조회 api
@GetMapping("/{reviewId}/details")
@ResponseBody
public ReviewResponseDTO.ReviewPreView getReview(@PathVariable(name = "reviewId") Long reviewId){
Review review = reviewService.getReview(reviewId);

return ReviewResponseDTO.ReviewPreView.builder()
.ownerNickname(review.getUser().getUsername())
.rate(review.getRate())
.content(review.getContent())
.createdAt(review.getCreatedAt())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import jakarta.persistence.*;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@Builder
Expand All @@ -17,12 +14,10 @@ public class Category extends BaseEntity{
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, length = 40)
private String name;
@Column(nullable = false, length = 20)
private String mainCategory;

/*@OneToMany(mappedBy = "category", cascade = CascadeType.ALL)
private List<Tag> tagList = new ArrayList<>();
@Column(nullable = false, length = 20)
private String subCategory;

@OneToMany(mappedBy = "category", cascade = CascadeType.ALL)
private List<Lecture> lectureList = new ArrayList<>();*/
}
41 changes: 19 additions & 22 deletions majorLink/src/main/java/com/example/majorLink/domain/Lecture.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
import com.example.majorLink.domain.enums.Day;
import com.example.majorLink.domain.enums.Exam;
import com.example.majorLink.domain.enums.Level;
import com.example.majorLink.domain.mapping.Bookmark;
import com.example.majorLink.domain.mapping.Liked;
import com.example.majorLink.domain.mapping.UserLecture;
import jakarta.persistence.*;
import lombok.*;

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

@Entity
@Getter
Expand All @@ -38,12 +33,17 @@ public class Lecture extends BaseEntity{
private String info;

@Enumerated(EnumType.STRING)
@Column(nullable = false, columnDefinition = "VARCHAR(10)")
@Column(nullable = false, columnDefinition = "VARCHAR(20)")
private Level level;

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

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

private LocalTime time;

@Enumerated(EnumType.STRING)
Expand All @@ -61,24 +61,13 @@ public class Lecture extends BaseEntity{
@JoinColumn(name = "category_id")
private Category category;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "tag_id")
private Tag tag;

/*@OneToMany(mappedBy = "lecture", cascade = CascadeType.ALL)
private List<UserLecture> userLectureList = new ArrayList<>();
@OneToMany(mappedBy = "lecture", cascade = CascadeType.ALL)
private List<Liked> likedList = new ArrayList<>();
@Column(nullable = false, length = 20)
private String tag;

@OneToMany(mappedBy = "lecture", cascade = CascadeType.ALL)
private List<Bookmark> bookmarkList = new ArrayList<>();*/

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
@Column(nullable = false, length = 100)
private String tutor;

public void updateLecture(String name, String body, int curri, String info, Level level, int pNum, LocalTime time, Day day, Date startDate, Exam exam, Category category, Tag tag ){
public void updateLecture(String name, String body, int curri, String info, Level level, int pNum, LocalTime time, Day day, Date startDate, Exam exam, Category category, String tag ){
this.name = name;
this.body = body;
this.curri = curri;
Expand All @@ -92,4 +81,12 @@ public void updateLecture(String name, String body, int curri, String info, Leve
this.category = category;
this.tag = tag;
}

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

public void subCurPNum(){
this.curPNum--;
}
}
29 changes: 0 additions & 29 deletions majorLink/src/main/java/com/example/majorLink/domain/Tag.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.example.majorLink.domain.enums;

public enum LectureStatus {
INPROGRESS, FINISHED
INPROGRESS, FINISHED, CANCELLED
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class UserLecture extends BaseEntity {
public class TuteeLecture extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Loading

0 comments on commit 8dc7c8b

Please sign in to comment.