From e1e88cfd3aa68d97554cd52160a78a261327af2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EA=B7=9C=ED=98=81?= <126947828+Gyuhyeok99@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:27:01 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=85=B8=ED=8A=B8=20API=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=9C=A0=EC=A0=80=EB=A0=88=EC=8A=A8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20?= =?UTF-8?q?semester->attendedSemester=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20(#95?= =?UTF-8?q?)=20(#96)=20(#97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../note/controller/NoteController.java | 4 +-- .../campusNote/note/dto/NoteRequestDTO.java | 4 +-- .../campusNote/note/service/NoteService.java | 2 +- .../note/service/NoteServiceImpl.java | 10 +++---- .../note/service/NoteServiceImplTest.java | 26 +++++++++---------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/UMC/campusNote/note/controller/NoteController.java b/src/main/java/UMC/campusNote/note/controller/NoteController.java index 573961f..d8afc7e 100644 --- a/src/main/java/UMC/campusNote/note/controller/NoteController.java +++ b/src/main/java/UMC/campusNote/note/controller/NoteController.java @@ -55,8 +55,8 @@ public ApiResponse getUserNote(@AuthenticationPrinci @Parameter(name = "lessonId", description = "레슨의 아이디, path variable 입니다"), @Parameter(name = "semester", description = "학기, query string 입니다") }) - public ApiResponse> getUserNotes(@AuthenticationPrincipal User user, @PathVariable("lessonId") Long lessonId, @RequestParam("semester") String semester, Pageable pageable) { - return ApiResponse.of(NOTE_GET_ALL, noteService.getUserNotes(user, lessonId, semester, pageable)); + public ApiResponse> getUserNotes(@AuthenticationPrincipal User user, @PathVariable("lessonId") Long lessonId, @RequestParam("attendedSemester") String attendedSemester, Pageable pageable) { + return ApiResponse.of(NOTE_GET_ALL, noteService.getUserNotes(user, lessonId, attendedSemester, pageable)); } @PostMapping("/{lessonId}") diff --git a/src/main/java/UMC/campusNote/note/dto/NoteRequestDTO.java b/src/main/java/UMC/campusNote/note/dto/NoteRequestDTO.java index 545369c..0192bb8 100644 --- a/src/main/java/UMC/campusNote/note/dto/NoteRequestDTO.java +++ b/src/main/java/UMC/campusNote/note/dto/NoteRequestDTO.java @@ -28,9 +28,9 @@ public static class NoteGetDTO{ @Builder public static class NoteCreateDTO{ - @Schema(description = "현재 학기", example = "2024-1") + @Schema(description = "현재 학기", example = "3-1") @NotNull - String semester; + String attendedSemester; @Schema(description = "노트이름", example = "노트이름") @NotNull diff --git a/src/main/java/UMC/campusNote/note/service/NoteService.java b/src/main/java/UMC/campusNote/note/service/NoteService.java index 42a2622..51343c1 100644 --- a/src/main/java/UMC/campusNote/note/service/NoteService.java +++ b/src/main/java/UMC/campusNote/note/service/NoteService.java @@ -9,7 +9,7 @@ public interface NoteService { NoteResponseDTO.NoteGetDTO getUserNote(User user, Long noteId); - Slice getUserNotes(User user, Long lessonId, String semester, Pageable pageable); + Slice getUserNotes(User user, Long lessonId, String attendedSemester, Pageable pageable); NoteResponseDTO.NoteCreateDTO createUserNote(User user, Long lessonId, NoteRequestDTO.NoteCreateDTO request); NoteResponseDTO.NoteUpdateDTO updateUserNote(User user, Long noteId, NoteRequestDTO.NoteUpdateDTO request); NoteResponseDTO.NoteDeleteDTO deleteUserNote(User user, Long noteId); diff --git a/src/main/java/UMC/campusNote/note/service/NoteServiceImpl.java b/src/main/java/UMC/campusNote/note/service/NoteServiceImpl.java index 2f71b20..24c209b 100644 --- a/src/main/java/UMC/campusNote/note/service/NoteServiceImpl.java +++ b/src/main/java/UMC/campusNote/note/service/NoteServiceImpl.java @@ -45,8 +45,8 @@ public NoteResponseDTO.NoteGetDTO getUserNote(User user, Long noteId) { } @Override - public Slice getUserNotes(User user, Long lessonId, String semester, Pageable pageable) { - UserLesson userLesson = getUserLesson(user, lessonId, semester); + public Slice getUserNotes(User user, Long lessonId, String attendedSemester, Pageable pageable) { + UserLesson userLesson = getUserLesson(user, lessonId, attendedSemester); Page userLessonNotePage = userLessonNoteRepository.findByUserLessonId(userLesson.getId(), pageable); List noteGetDTOS = userLessonNotePage.getContent().stream().map(NoteConverter::toNoteGetDTO).toList(); return new SliceImpl<>(noteGetDTOS, pageable, userLessonNotePage.hasNext()); @@ -55,7 +55,7 @@ public Slice getUserNotes(User user, Long lessonId, @Override @Transactional public NoteResponseDTO.NoteCreateDTO createUserNote(User user, Long lessonId, NoteRequestDTO.NoteCreateDTO request) { - return NoteConverter.toNoteCreateDTO(createNote(request.getNoteName(), getUserLesson(user, lessonId, request.getSemester()))); + return NoteConverter.toNoteCreateDTO(createNote(request.getNoteName(), getUserLesson(user, lessonId, request.getAttendedSemester()))); } @Override @@ -75,10 +75,10 @@ public NoteResponseDTO.NoteDeleteDTO deleteUserNote(User user, Long noteId) { } - private UserLesson getUserLesson(User user, Long lessonId, String semester) { + private UserLesson getUserLesson(User user, Long lessonId, String attendedSemester) { Lesson lesson = lessonRepository.findById(lessonId).orElseThrow( () -> new GeneralException(LESSON_NOT_FOUND)); - return userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, semester, lesson) + return userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, attendedSemester, lesson) .orElseThrow(() -> new GeneralException(USER_LESSON_NOT_FOUND)); } diff --git a/src/test/java/UMC/campusNote/note/service/NoteServiceImplTest.java b/src/test/java/UMC/campusNote/note/service/NoteServiceImplTest.java index 167c328..b435423 100644 --- a/src/test/java/UMC/campusNote/note/service/NoteServiceImplTest.java +++ b/src/test/java/UMC/campusNote/note/service/NoteServiceImplTest.java @@ -60,7 +60,7 @@ void setUp() { UserLesson userLesson = UserLesson.builder() .user(user) .lesson(lesson) - .attendedSemester("2023년 2학기") + .attendedSemester("3-1") .build(); userRepository.save(user); @@ -74,8 +74,8 @@ void setUp() { void getAllUserNote() { User user = userRepository.findByClientId("test").get(); Lesson lesson = lessonRepository.findByLessonName("객체지향프로그래밍 2").get(); - UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "2023년 2학기", lesson).get(); - NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("2023년 2학기", "노트제목"); + UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "3-1", lesson).get(); + NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("3-1", "노트제목"); NoteResponseDTO.NoteCreateDTO noteCreateDTO = noteService.createUserNote(user, findUsesrLesson.getId(), request); // when Note note = noteRepository.findByNoteName("노트제목").get(); @@ -90,10 +90,10 @@ void getAllUserNote() { void getAllUserNotes() { User user = userRepository.findByClientId("test").get(); Lesson lesson = lessonRepository.findByLessonName("객체지향프로그래밍 2").get(); - UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "2023년 2학기", lesson).get(); - NoteRequestDTO.NoteCreateDTO request2 = new NoteRequestDTO.NoteCreateDTO("2023년 2학기", "노트제목"); + UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "3-1", lesson).get(); + NoteRequestDTO.NoteCreateDTO request2 = new NoteRequestDTO.NoteCreateDTO("3-1", "노트제목"); noteService.createUserNote(user, findUsesrLesson.getId(), request2); - Slice userNotes = noteService.getUserNotes(user, findUsesrLesson.getId(), "2023년 2학기", Pageable.ofSize(10)); + Slice userNotes = noteService.getUserNotes(user, findUsesrLesson.getId(), "3-1", Pageable.ofSize(10)); // then assert userNotes.getContent().size() == 1; } @@ -104,8 +104,8 @@ void getAllUserNotes() { void createUserNote() { User user = userRepository.findByClientId("test").get(); Lesson lesson = lessonRepository.findByLessonName("객체지향프로그래밍 2").get(); - UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "2023년 2학기", lesson).get(); - NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("2023년 2학기", "노트제목"); + UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "3-1", lesson).get(); + NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("3-1", "노트제목"); // when NoteResponseDTO.NoteCreateDTO noteCreateDTO = noteService.createUserNote(user, findUsesrLesson.getId(), request); @@ -121,8 +121,8 @@ void createUserNote() { void updateNoteName() { User user = userRepository.findByClientId("test").get(); Lesson lesson = lessonRepository.findByLessonName("객체지향프로그래밍 2").get(); - UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "2023년 2학기", lesson).get(); - NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("2023년 2학기", "노트제목"); + UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "3-1", lesson).get(); + NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("3-1", "노트제목"); NoteResponseDTO.NoteCreateDTO noteCreateDTO = noteService.createUserNote(user, findUsesrLesson.getId(), request); Note note = noteRepository.findByNoteName("노트제목").get(); // when @@ -142,9 +142,9 @@ void updateNoteName() { void deleteNote() { User user = userRepository.findByClientId("test").get(); Lesson lesson = lessonRepository.findByLessonName("객체지향프로그래밍 2").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); + UserLesson findUsesrLesson = userLessonRepository.findByUserAndAttendedSemesterAndLesson(user, "3-1", lesson).get(); + NoteRequestDTO.NoteCreateDTO request = new NoteRequestDTO.NoteCreateDTO("3-1", "노트제목"); + noteService.createUserNote(user, findUsesrLesson.getId(), request); Note note = noteRepository.findByNoteName("노트제목").get(); // when NoteResponseDTO.NoteDeleteDTO noteDeleteDTO = noteService.deleteUserNote(user, note.getId());