-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor/201 쪽지 상세조회시 읽음처리 기능 추가 #202
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/somemore/note/service/NoteMarkAsReadService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.somemore.note.service; | ||
|
|
||
| import com.somemore.global.exception.NoSuchElementException; | ||
| import com.somemore.note.domain.Note; | ||
| import com.somemore.note.repository.NoteRepository; | ||
| import com.somemore.note.usecase.NoteMarkAsReadUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_NOTE; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| @Transactional | ||
| public class NoteMarkAsReadService implements NoteMarkAsReadUseCase { | ||
|
|
||
| private final NoteRepository noteRepository; | ||
|
|
||
| @Override | ||
| public void noteMarkAsRead(Long noteId) { | ||
| Note note = getNote(noteId); | ||
| note.markAsRead(); | ||
| } | ||
|
|
||
| private Note getNote(Long noteId) { | ||
| return noteRepository.findById(noteId) | ||
| .orElseThrow(() -> new NoSuchElementException(NOT_EXISTS_NOTE)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| import com.somemore.note.repository.mapper.NoteDetailViewForVolunteer; | ||
| import com.somemore.note.repository.mapper.NoteReceiverViewForCenter; | ||
| import com.somemore.note.repository.mapper.NoteReceiverViewForVolunteer; | ||
| import com.somemore.note.usecase.NoteMarkAsReadUseCase; | ||
| import com.somemore.note.usecase.NoteQueryUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
|
|
@@ -22,6 +23,7 @@ | |
| @Transactional(readOnly = true) | ||
| public class NoteQueryService implements NoteQueryUseCase { | ||
|
|
||
| private final NoteMarkAsReadUseCase noteMarkAsReadUseCase; | ||
| private final NoteRepository noteRepository; | ||
|
|
||
| @Override | ||
|
|
@@ -36,12 +38,16 @@ public Page<NoteReceiverViewForVolunteer> getNotesForVolunteer(UUID volunteerId, | |
|
|
||
| @Override | ||
| public NoteDetailViewForCenter getNoteDetailForCenter(Long noteId) { | ||
| noteMarkAsReadUseCase.noteMarkAsRead(noteId); | ||
|
|
||
| return noteRepository.findNoteDetailViewReceiverIsCenter(noteId) | ||
| .orElseThrow(() -> new NoSuchElementException(NOT_EXISTS_NOTE)); | ||
| } | ||
|
|
||
| @Override | ||
| public NoteDetailViewForVolunteer getNoteDetailForVolunteer(Long noteId) { | ||
| noteMarkAsReadUseCase.noteMarkAsRead(noteId); | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도요!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다 큰 실수를 할 뻔했습니다 |
||
| return noteRepository.findNoteDetailViewReceiverIsVolunteer(noteId) | ||
| .orElseThrow(() -> new NoSuchElementException(NOT_EXISTS_NOTE)); | ||
| } | ||
|
|
||
5 changes: 5 additions & 0 deletions
5
src/main/java/com/somemore/note/usecase/NoteMarkAsReadUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.somemore.note.usecase; | ||
|
|
||
| public interface NoteMarkAsReadUseCase { | ||
| void noteMarkAsRead(Long noteId); | ||
| } |
54 changes: 54 additions & 0 deletions
54
src/test/java/com/somemore/note/service/NoteMarkAsReadServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.somemore.note.service; | ||
|
|
||
| import com.somemore.IntegrationTestSupport; | ||
| import com.somemore.global.exception.NoSuchElementException; | ||
| import com.somemore.note.domain.Note; | ||
| import com.somemore.note.repository.NoteRepository; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_NOTE; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class NoteMarkAsReadServiceTest extends IntegrationTestSupport { | ||
|
|
||
| @Autowired | ||
| private NoteMarkAsReadService noteMarkAsReadService; | ||
|
|
||
| @Autowired | ||
| private NoteRepository noteRepository; | ||
|
|
||
| @DisplayName("쪽지를 읽음 처리할 수 있다.") | ||
| @Test | ||
| void noteMarkAsRead() { | ||
| // given | ||
| Long noteId = 1L; | ||
|
|
||
| Note note = Note.create(UUID.randomUUID(), UUID.randomUUID(), "제목", "내용"); | ||
| noteRepository.save(note); | ||
|
|
||
| // when | ||
| noteMarkAsReadService.noteMarkAsRead(noteId); | ||
|
|
||
| // then | ||
| Note updatedNote = noteRepository.findById(noteId) | ||
| .orElseThrow(() -> new NoSuchElementException(NOT_EXISTS_NOTE)); | ||
|
|
||
| assertTrue(updatedNote.getIsRead(), "노트가 읽음 상태로 변경되어야 한다."); | ||
| } | ||
|
|
||
| @DisplayName("존재하지 않는 쪽지에 대한 업데이트 요청은 예외를 반환한다.") | ||
| @Test | ||
| void noteMarkAsRead_throwsException_WhenNoteNotFound() { | ||
| // given | ||
| Long nonExistentNoteId = 999L; | ||
|
|
||
| // when & then | ||
| assertThrows(NoSuchElementException.class, | ||
| () -> noteMarkAsReadService.noteMarkAsRead(nonExistentNoteId), | ||
| "존재하지 않는 노트에 대해 예외가 발생해야 한다."); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 일단은 QueryService 라 transactional read true 일텐데
레포지토리로 .save 해주면 좋을것 같아요.