Skip to content

Commit

Permalink
refactor: 노트 API에서 유저레슨 조회 시 파라미터 semester->attendedSemester로 변경 (#95) (
Browse files Browse the repository at this point in the history
#96) (#97)
  • Loading branch information
Gyuhyeok99 authored Feb 15, 2024
1 parent 5684966 commit e1e88cf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public ApiResponse<NoteResponseDTO.NoteGetDTO> getUserNote(@AuthenticationPrinci
@Parameter(name = "lessonId", description = "레슨의 아이디, path variable 입니다"),
@Parameter(name = "semester", description = "학기, query string 입니다")
})
public ApiResponse<Slice<NoteResponseDTO.NoteGetDTO>> 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<Slice<NoteResponseDTO.NoteGetDTO>> 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}")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/UMC/campusNote/note/dto/NoteRequestDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/UMC/campusNote/note/service/NoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public interface NoteService {

NoteResponseDTO.NoteGetDTO getUserNote(User user, Long noteId);
Slice<NoteResponseDTO.NoteGetDTO> getUserNotes(User user, Long lessonId, String semester, Pageable pageable);
Slice<NoteResponseDTO.NoteGetDTO> 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);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/UMC/campusNote/note/service/NoteServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public NoteResponseDTO.NoteGetDTO getUserNote(User user, Long noteId) {
}

@Override
public Slice<NoteResponseDTO.NoteGetDTO> getUserNotes(User user, Long lessonId, String semester, Pageable pageable) {
UserLesson userLesson = getUserLesson(user, lessonId, semester);
public Slice<NoteResponseDTO.NoteGetDTO> getUserNotes(User user, Long lessonId, String attendedSemester, Pageable pageable) {
UserLesson userLesson = getUserLesson(user, lessonId, attendedSemester);
Page<UserLessonNote> userLessonNotePage = userLessonNoteRepository.findByUserLessonId(userLesson.getId(), pageable);
List<NoteResponseDTO.NoteGetDTO> noteGetDTOS = userLessonNotePage.getContent().stream().map(NoteConverter::toNoteGetDTO).toList();
return new SliceImpl<>(noteGetDTOS, pageable, userLessonNotePage.hasNext());
Expand All @@ -55,7 +55,7 @@ public Slice<NoteResponseDTO.NoteGetDTO> 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
Expand All @@ -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));
}

Expand Down
26 changes: 13 additions & 13 deletions src/test/java/UMC/campusNote/note/service/NoteServiceImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void setUp() {
UserLesson userLesson = UserLesson.builder()
.user(user)
.lesson(lesson)
.attendedSemester("2023년 2학기")
.attendedSemester("3-1")
.build();

userRepository.save(user);
Expand All @@ -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();
Expand All @@ -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<NoteResponseDTO.NoteGetDTO> userNotes = noteService.getUserNotes(user, findUsesrLesson.getId(), "2023년 2학기", Pageable.ofSize(10));
Slice<NoteResponseDTO.NoteGetDTO> userNotes = noteService.getUserNotes(user, findUsesrLesson.getId(), "3-1", Pageable.ofSize(10));
// then
assert userNotes.getContent().size() == 1;
}
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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());
Expand Down

0 comments on commit e1e88cf

Please sign in to comment.