Skip to content

Commit

Permalink
[#16] fix : mapping 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
sangminee committed May 18, 2023
1 parent 79ca638 commit 07fde5d
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 11 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ dependencies {
// validation
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.5.6'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '2.6.3'

// 다중 파일 처리
implementation 'commons-io:commons-io:2.6'
}

dependencyManagement {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
package com.mju.course.application.lecture;

import com.mju.course.domain.model.other.Result.CommonResult;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

public interface LectureService {
CommonResult readLecture(Long lecture_index, String tab);

CommonResult createQuestion(Long lecture_index, List<MultipartFile> images, String question, Long userId);
CommonResult readQuestion(Long question_index);
CommonResult readQuestions(String lecture_index);
CommonResult updateQuestion(Long question_index);
CommonResult deleteQuestion(Long question_index);


}
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
package com.mju.course.application.lecture;

import com.mju.course.application.S3UploaderService;
import com.mju.course.domain.model.User;
import com.mju.course.domain.model.course.Course;
import com.mju.course.domain.model.course.Curriculum;
import com.mju.course.domain.model.lecture.Lecture;
import com.mju.course.domain.model.lecture.LectureQuestion;
import com.mju.course.domain.model.lecture.LectureQuestionPhoto;
import com.mju.course.domain.model.other.Exception.CourseException;
import com.mju.course.domain.model.other.Result.CommonResult;
import com.mju.course.domain.repository.UserRepository;
import com.mju.course.domain.repository.course.CourseRepository;
import com.mju.course.domain.repository.course.CurriculumRepository;
import com.mju.course.domain.repository.lecture.LectureRepository;
import com.mju.course.domain.repository.lecture.*;
import com.mju.course.domain.service.ResponseService;
import com.mju.course.presentation.dto.response.CurriculumReadDto;
import com.mju.course.presentation.dto.response.LectureCurriculumReadDto;
import com.mju.course.presentation.dto.response.LectureReadDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import static com.mju.course.domain.model.other.Exception.ExceptionList.NOT_EXISTENT_COURSE;
import static com.mju.course.domain.model.other.Exception.ExceptionList.NOT_EXISTENT_LECTURE;
Expand All @@ -31,7 +41,16 @@ public class LectureServiceImpl implements LectureService{
private final CurriculumRepository curriculumRepository;
private final LectureRepository lectureRepository;

private final UserRepository userRepository;

private final LectureQuestionRepository lectureQuestionRepository;
private final LectureQuestionPhotoRepository lectureQuestionPhotoRepository;

private final LectureAnswerRepository lectureAnswerRepository;
private final LectureAnswerPhotoRepository lectureAnswerPhotoRepository;

private final ResponseService responseService;
private final S3UploaderService s3UploaderService;

@Override
public CommonResult readLecture(Long lecture_index, String tab){
Expand Down Expand Up @@ -74,4 +93,57 @@ public LectureCurriculumReadDto readCurriculumLecture(Long lecture_index) {
.build();
}

/** 강의 질문 작성하기
* @param lecture_index
* @param images
* @param question
* @param userId
*/
@Override
@Transactional
public CommonResult createQuestion(Long lecture_index, List<MultipartFile> images, String question, Long userId) {
Lecture lecture = lectureRepository.findById(lecture_index)
.orElseThrow(() -> new CourseException(NOT_EXISTENT_LECTURE));
User user = userRepository.findById(userId).get();

LectureQuestion lectureQuestion = LectureQuestion.of(lecture, user, question);
LectureQuestion saveQuestion = lectureQuestionRepository.save(lectureQuestion);

// 사진 등록
if(images.size() !=0){
images.forEach(s->{
try {
String basicFileName = UUID.randomUUID().toString();
String dirName = "question/" + String.valueOf(lecture.getId()) +"/"+String.valueOf(saveQuestion.getId());
String questionPhotoKey = s3UploaderService.upload(s, dirName, basicFileName);

LectureQuestionPhoto lectureQuestionPhoto = LectureQuestionPhoto.of(saveQuestion, questionPhotoKey);
lectureQuestionPhotoRepository.save(lectureQuestionPhoto);
} catch (IOException e) {
e.printStackTrace();
}
});
}
return responseService.getSuccessfulResult();
}

@Override
public CommonResult readQuestion(Long question_index) {
return null;
}

@Override
public CommonResult readQuestions(String lecture_index) {
return null;
}

@Override
public CommonResult updateQuestion(Long question_index) {
return null;
}

@Override
public CommonResult deleteQuestion(Long question_index) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.mju.course.domain.model.BaseTimeEntity;
import com.mju.course.domain.model.User;
import com.mju.course.domain.model.course.Course;
import com.mju.course.domain.model.course.Skill;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -39,4 +38,19 @@ public class LectureQuestion extends BaseTimeEntity {
@OneToMany(mappedBy = "lectureQuestion")
private List<LectureQuestionPhoto> lectureQuestionPhotoList = new ArrayList<>();

}
@Builder
public LectureQuestion(Lecture lecture, User user, String lectureQuestion) {
this.lecture = lecture;
this.user = user;
this.lectureQuestion = lectureQuestion;
}

public static LectureQuestion of(Lecture lecture, User user, String question){
return LectureQuestion.builder()
.lecture(lecture)
.user(user)
.lectureQuestion(question)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mju.course.domain.model.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -21,5 +22,17 @@ public class LectureQuestionPhoto extends BaseTimeEntity {

@Column(name = "lecture_question_photo_key")
private String lectureQuestionPhotoKey;


@Builder
public LectureQuestionPhoto(LectureQuestion lectureQuestion, String lectureQuestionPhotoKey) {
this.lectureQuestion = lectureQuestion;
this.lectureQuestionPhotoKey = lectureQuestionPhotoKey;
}

public static LectureQuestionPhoto of(LectureQuestion lectureQuestion, String lectureQuestionPhotoKey) {
return LectureQuestionPhoto.builder()
.lectureQuestion(lectureQuestion)
.lectureQuestionPhotoKey(lectureQuestionPhotoKey)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/admin")
@RequestMapping("/admin-service/admin")
@Tag(name = "Admin Controller", description = "운영자 용 코스, 강의 관리 api ")
public class AdminController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/course")
@RequestMapping("/course-service/course")
@Tag(name = "Course controller", description = "코스 관련 api")
public class CourseController {

private final CourseService courseService;
private final UserServiceImpl userService;

// 추후 개발 - 다른 MSA 와의 통신 : 평점 높은 순, 리뷰 많은 순
@Operation(summary = "목록 보기", description = " order : 최신순 (createdAt), 난이도 순 (difficulty), 조회 수 높은 순 (hits)")
// 유저 정보가 존재한다면 - 검색어 저장
@Operation(summary = "목록 보기", description = " order : 최신순 (createdAt), 난이도 순 (difficulty), 조회 수 높은 순 (hits), 좋아요 수(likeSum)")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "성공하였습니다.", content = @Content(schema = @Schema(implementation = CoursesReadDto.class))),
@ApiResponse(responseCode = "-9999", description = "알 수 없는 오류가 발생하였습니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/course/manage")
@RequestMapping("/course-service/course/manage")
@Tag(name = "Course Manage controller", description = "강사진 용 코스 관련 api")
public class CourseManageController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
import com.mju.course.application.UserServiceImpl;
import com.mju.course.domain.model.enums.UserType;
import com.mju.course.domain.model.other.Result.CommonResult;
import com.mju.course.presentation.dto.response.CoursesReadDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/lecture")
@RequestMapping("/lecture-service/lecture")
@Tag(name = "Lecture Controller", description = "강의 관련 api ")
public class LectureController {

Expand All @@ -23,13 +32,46 @@ private void checkUser(){

// 강의 보기
// (공통) 강의 조회 - tab : 기본(basic), 목차 (curriculum)
@Operation(summary = "(공통) 강의 조회", description = "tab : 기본(basic), 목차 (curriculum)")
@GetMapping("/{lecture_index}")
public CommonResult readBasicLecture(@PathVariable Long lecture_index,
@RequestParam("tab") String tab){
return lectureService.readLecture(lecture_index, tab);
}

// 강의 질문 CRUD
@Operation(summary = "강의 질문 작성하기", description = "강의 질문 작성하기 API 입니다. ")
@PostMapping("/{lecture_index}/question")
public CommonResult createQuestion(@PathVariable Long lecture_index,
@RequestParam(value="image", required=false) List<MultipartFile> images,
@RequestParam(value="question") String question,
@RequestParam Long userId){
return lectureService.createQuestion(lecture_index, images, question, userId);
}

@Operation(summary = "강의 질문 하나 보기", description = "강의 질문 하나 보기 API 입니다. ")
@GetMapping("/question/{question_index}")
public CommonResult readQuestion(@PathVariable Long question_index){
return lectureService.readQuestion(question_index);
}

@Operation(summary = "강의 질문 전체 보기", description = "강의 질문 전체 보기 API 입니다. ")
@GetMapping("/{lecture_index}/question")
public CommonResult readQuestions(@PathVariable String lecture_index){
return lectureService.readQuestions(lecture_index);
}

@Operation(summary = "강의 질문 수정하기", description = "강의 질문 수정하기 API 입니다. ")
@PutMapping("/question/{question_index}")
public CommonResult updateQuestion(@PathVariable Long question_index){
return lectureService.updateQuestion(question_index);
}

@Operation(summary = "강의 질문 삭제하기", description = "강의 질문 삭제하기 API 입니다. ")
@DeleteMapping("/question/{question_index}")
public CommonResult deleteQuestion(@PathVariable Long question_index){
return lectureService.deleteQuestion(question_index);
}

// 강의 답변 CRUD

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/lecture/manage")
@RequestMapping("/lecture-service/lecture/manage")
@Tag(name = "Lecture Manage Controller", description = "강사진 용 강의 관리 관련 api")
public class LectureManageController {

Expand Down

0 comments on commit 07fde5d

Please sign in to comment.