Skip to content

Commit

Permalink
refactor: Lesson 관련 api 스웨거 명세 추가 (#86) (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
leesewon00 authored Feb 14, 2024
1 parent 0e9d59b commit eb6cf61
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
import UMC.campusNote.lesson.exception.LessonException;
import UMC.campusNote.lesson.service.LessonService;
import UMC.campusNote.user.entity.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -24,6 +30,17 @@ public class LessonController {
private final LessonService lessonService;

@GetMapping(value = "/api/v1/lessons")
@Operation(summary = "특정 학기 수업 전체 조회", description = "로그인한 회원의 특정 학기 수업을 전체 조회합니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "성공입니다."),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MEMBER4001", description = "사용자가 없습니다.",
content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "LESSON4002", description = "해당학기 수업 정보가 없습니다.",
content = @Content(schema = @Schema(implementation = ApiResponse.class)))
})
@Parameters({
@Parameter(name = "attendedSemester", description = "수강중인 학기(ex. 3-2), RequestParam")
})
public ApiResponse<List<LessonResponseDTO.FindResultDTO>> findLessons(@AuthenticationPrincipal User user,
@RequestParam(name = "attendedSemester") String attendedSemester) {
log.info("enter LessonController : [get] /api/v1/lessons?attendedSemester={}", attendedSemester);
Expand All @@ -34,6 +51,15 @@ public ApiResponse<List<LessonResponseDTO.FindResultDTO>> findLessons(@Authentic
}

@GetMapping(value = "/api/v1/lessons/{lessonId}")
@Operation(summary = "특정 수업 조회", description = "lessonId로 특정 수업 정보를 조회합니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "성공입니다."),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "LESSON4001", description = "존재하지 않는 수업.",
content = @Content(schema = @Schema(implementation = ApiResponse.class)))
})
@Parameters({
@Parameter(name = "lessonId", description = "특정 수업의 id, PathVariable")
})
public ApiResponse<LessonResponseDTO.FindResultDTO> findLessonDetails(@PathVariable(name = "lessonId") Long lessonId) {
log.info("enter LessonController : [get] /api/v1/lessons/{}", lessonId);

Expand All @@ -43,6 +69,16 @@ public ApiResponse<LessonResponseDTO.FindResultDTO> findLessonDetails(@PathVaria
}

@PostMapping(value = "/api/v1/lessons/new")
@Operation(summary = "수업 생성", description = "수업을 생성하고 로그인한 사용자 정보에 등록합니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "LESSON201", description = "수업 생성 성공."),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MEMBER4001", description = "사용자가 없습니다.",
content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "LESSON4004", description = "파라미터 바인딩 실패.",
content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "LESSON4003", description = "중복된 수업.",
content = @Content(schema = @Schema(implementation = ApiResponse.class)))
})
public ApiResponse<Long> createLesson(@AuthenticationPrincipal User user,
@Valid @RequestBody LessonRequestDTO.CreateDTO createDTO,
BindingResult bindingResult) {
Expand All @@ -57,6 +93,19 @@ public ApiResponse<Long> createLesson(@AuthenticationPrincipal User user,
}

@DeleteMapping(value = "/api/v1/lessons/{lessonId}")
@Operation(summary = "특정 수업 삭제", description = "로그인한 회원 정보에서 해당 수업을 삭제합니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "성공입니다."),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MEMBER4001", description = "사용자가 없습니다.",
content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "LESSON4001", description = "존재하지 않는 수업.",
content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USERLESSON4001", description = "존재하지 않는 유저레슨.",
content = @Content(schema = @Schema(implementation = ApiResponse.class)))
})
@Parameters({
@Parameter(name = "attendedSemester", description = "수강중인 학기(ex. 3-2), RequestParam")
})
public ApiResponse<Long> deleteUserLesson(@AuthenticationPrincipal User user,
@PathVariable(name = "lessonId") Long lessonId) {
log.info("enter LessonController : [delete] /api/v1/lessons/{}", lessonId);
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/UMC/campusNote/lesson/dto/CustomLessonRequest.java

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/UMC/campusNote/lesson/dto/LessonRequestDTO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package UMC.campusNote.lesson.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.*;

Expand All @@ -10,10 +11,12 @@ public class LessonRequestDTO {
@NoArgsConstructor
@Builder
public static class CreateDTO {
@Schema(description = "사용자의 학기", example = "3-1")
@NotNull
private String attendedSemester;
@NotNull
private String lessonName;
@Schema(description = "학교의 학기", example = "2024-1")
@NotNull
private String semester;
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void setUp() {
void getAllUserNote() {
User user = userRepository.findByClientId("test").get();
Lesson lesson = lessonRepository.findByLessonName("객체지향프로그래밍 2").get();
UserLesson findUsesrLesson = userLessonRepository.findByUserAndAndAttendedSemesterAndAndLesson(user, "2023년 2학기", lesson).get();
UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "2023년 2학기", lesson).get();
NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("2023년 2학기", "노트제목");
NoteResponseDTO.NoteCreateDTO noteCreateDTO = noteService.createUserNote(user, findUsesrLesson.getId(), request);
// when
Expand All @@ -90,7 +90,7 @@ void getAllUserNote() {
void getAllUserNotes() {
User user = userRepository.findByClientId("test").get();
Lesson lesson = lessonRepository.findByLessonName("객체지향프로그래밍 2").get();
UserLesson findUsesrLesson = userLessonRepository.findByUserAndAndAttendedSemesterAndAndLesson(user, "2023년 2학기", lesson).get();
UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "2023년 2학기", lesson).get();
NoteRequestDTO.NoteCreateDTO request2 = new NoteRequestDTO.NoteCreateDTO("2023년 2학기", "노트제목");
noteService.createUserNote(user, findUsesrLesson.getId(), request2);
Slice<NoteResponseDTO.NoteGetDTO> userNotes = noteService.getUserNotes(user, findUsesrLesson.getId(), "2023년 2학기", Pageable.ofSize(10));
Expand All @@ -104,7 +104,7 @@ void getAllUserNotes() {
void createUserNote() {
User user = userRepository.findByClientId("test").get();
Lesson lesson = lessonRepository.findByLessonName("객체지향프로그래밍 2").get();
UserLesson findUsesrLesson = userLessonRepository.findByUserAndAndAttendedSemesterAndAndLesson(user, "2023년 2학기", lesson).get();
UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "2023년 2학기", lesson).get();
NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("2023년 2학기", "노트제목");

// when
Expand All @@ -121,7 +121,7 @@ void createUserNote() {
void updateNoteName() {
User user = userRepository.findByClientId("test").get();
Lesson lesson = lessonRepository.findByLessonName("객체지향프로그래밍 2").get();
UserLesson findUsesrLesson = userLessonRepository.findByUserAndAndAttendedSemesterAndAndLesson(user, "2023년 2학기", lesson).get();
UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "2023년 2학기", lesson).get();
NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("2023년 2학기", "노트제목");
NoteResponseDTO.NoteCreateDTO noteCreateDTO = noteService.createUserNote(user, findUsesrLesson.getId(), request);
Note note = noteRepository.findByNoteName("노트제목").get();
Expand All @@ -142,7 +142,7 @@ void updateNoteName() {
void deleteNote() {
User user = userRepository.findByClientId("test").get();
Lesson lesson = lessonRepository.findByLessonName("객체지향프로그래밍 2").get();
UserLesson findUsesrLesson = userLessonRepository.findByUserAndAndAttendedSemesterAndAndLesson(user, "2023년 2학기", lesson).get();
UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "2023년 2학기", lesson).get();
NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("2023년 2학기", "노트제목");
NoteResponseDTO.NoteCreateDTO noteCreateDTO = noteService.createUserNote(user, findUsesrLesson.getId(), request);
Note note = noteRepository.findByNoteName("노트제목").get();
Expand Down

0 comments on commit eb6cf61

Please sign in to comment.