Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feat: 전체 강의 정보 조회 구현 #26

Merged
merged 1 commit into from
Dec 2, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum SuccessStatus implements BaseCode {
// 강의 관련 응답
SUCCESS_FETCH_LECTURE(HttpStatus.OK, "LECTURE2001", "강의 정보를 성공적으로 가져왔습니다."),
SUCCESS_CREATE_LECTURE(HttpStatus.OK, "LECTURE2002", "강의 정보를 성공적으로 등록했습니다."),
SUCCESS_FETCH_LECTURES(HttpStatus.OK, "LETURE2003", "전체 강의 정보를 성공적으로 가져왔습니다."),

// 리뷰 관련 응답
SUCCESS_FETCH_REVIEW_LIST(HttpStatus.OK, "REVIEW2001", "리뷰 목록을 성공적으로 가져왔습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import miniproject.web02.web.dto.lectureDTO.LectureResponseDTO;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

public interface LectureService {
LectureResponseDTO.LectureDTO getLecture(Long lectureId);

//LectureResponseDTO createLecture(LectureRequestDTO lectureRequestDto, MultipartFile image);
//LectureResponseDTO.LectureDTO createLecture(LectureRequestDTO lectureRequestDto);
LectureResponseDTO.LectureDTO createLecture(LectureRequestDTO lectureRequestDTO, MultipartFile image);
List<LectureResponseDTO.LectureDTO> getAllLectures();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class LectureServiceImpl implements LectureService {
Expand Down Expand Up @@ -83,4 +86,25 @@ public LectureResponseDTO.LectureDTO createLecture(LectureRequestDTO lectureRequ
.imageUrl(imageUrl) // 이미지 URL 반환
.build();
}

@Override
public List<LectureResponseDTO.LectureDTO> getAllLectures() {
List<Lecture> lectures = lectureRepository.findAll(); // Fetch all lectures

return lectures.stream()
.map(lecture -> {
String imageUrl = lectureImageRepository.findFirstByLecture(lecture)
.map(LectureImage::getImageUrl)
.orElse(null);

return LectureResponseDTO.LectureDTO.builder()
.lectureId(lecture.getLectureID())
.lectureName(lecture.getName())
.platform(lecture.getPlatform().toString())
.teacher(lecture.getTeacher())
.imageUrl(imageUrl)
.build();
})
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ public class ApiController {
private final RatingCommandService ratingCommandService;
private final ReviewSearchCommandService reviewSearchCommandService;

@Operation(summary = "강의 등록 API", description = "새로운 강의 정보를 등록합니다.")
@PostMapping(value = "/lectures", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ApiResponse<LectureResponseDTO.LectureDTO> createLecture(
@RequestPart("lectureRequest") @Validated LectureRequestDTO lectureRequestDTO,
@RequestPart(value = "image", required = false) MultipartFile image) {

// 강의 생성
LectureResponseDTO.LectureDTO createdLecture = lectureService.createLecture(lectureRequestDTO, image);
return ApiResponse.of(SuccessStatus.SUCCESS_CREATE_LECTURE, createdLecture);
}

@Operation(summary = "총 별점 & 별점 개수 조회 API", description = "해당하는 강의의 총 별점 & 점수 대 별 별점 개수를 조회하는 API")
@GetMapping("/rating_info/{lectureId}")
Expand All @@ -70,7 +60,7 @@ public ApiResponse<totalRatingResponseDTO.getRatingInfoDTO> RatingInfo (@PathVar
return ApiResponse.onSuccess(TotalRatingConverter.toTotalRatigDTO(lecture,ratingCounts,lectureReviewRatingList));
}

@Operation(summary = "강의 정보 조회 API", description = "강의 상세 페이지의 강의 정보 조회")
@Operation(summary = "특정 강의 정보 조회 API", description = "강의 상세 페이지의 강의 정보 조회")
@GetMapping("/lecture_info/{lectureId}")
public ApiResponse<LectureResponseDTO.LectureDTO> getLectureInfo (@PathVariable(name = "lectureId") Long lectureId){
LectureResponseDTO.LectureDTO lectureDTO = lectureService.getLecture(lectureId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package miniproject.web02.web.controller;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import miniproject.web02.apiPayLoad.ApiResponse;
import miniproject.web02.apiPayLoad.code.status.SuccessStatus;
import miniproject.web02.repository.LectureRepository;
import miniproject.web02.service.lectureSerivce.LectureService;
import miniproject.web02.web.dto.lectureDTO.LectureRequestDTO;
import miniproject.web02.web.dto.lectureDTO.LectureResponseDTO;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Validated
@RequestMapping("/api")
public class LectureController {
private final LectureRepository lectureRepository;
private final LectureService lectureService;

@Operation(summary = "강의 등록 API", description = "새로운 강의 정보를 등록합니다.")
@PostMapping(value = "/lectures", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ApiResponse<LectureResponseDTO.LectureDTO> createLecture(
@RequestPart("lectureRequest") @Validated LectureRequestDTO lectureRequestDTO,
@RequestPart(value = "image", required = false) MultipartFile image) {

// 강의 생성
LectureResponseDTO.LectureDTO createdLecture = lectureService.createLecture(lectureRequestDTO, image);
return ApiResponse.of(SuccessStatus.SUCCESS_CREATE_LECTURE, createdLecture);
}

@Operation(summary = "전체 강의 조회 API", description = "전체 강의 정보 조회")
@GetMapping("/lectures")
public ApiResponse<List<LectureResponseDTO.LectureDTO>> getLectureInfo() {
List<LectureResponseDTO.LectureDTO> lectures = lectureService.getAllLectures();
return ApiResponse.of(SuccessStatus.SUCCESS_FETCH_LECTURES, lectures);
}
}
Loading