Skip to content

Commit

Permalink
refactor: comment 작성시 발생하던 에러 해결 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
AHNYUNKI committed May 21, 2024
1 parent b7de573 commit b787792
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ public class CommentCreateRequest {

private List<String> imageUrls = new ArrayList<>();

@NotBlank(message = "isbn은 필수 입니다.")
private String isbn;

@Builder
private CommentCreateRequest(String content, List<String> imageUrls, String isbn) {
private CommentCreateRequest(String content, List<String> imageUrls) {
this.content = content;
this.imageUrls = imageUrls;
this.isbn = isbn;
}

public CommentCreateServiceRequest toService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.jisungin.application.comment.response.CommentQueryResponse;
import com.jisungin.application.comment.response.CommentResponse;
import com.jisungin.domain.ReadingStatus;
import com.jisungin.domain.book.Book;
import com.jisungin.domain.book.repository.BookRepository;
import com.jisungin.domain.comment.Comment;
import com.jisungin.domain.comment.repository.CommentRepository;
import com.jisungin.domain.commentimage.CommentImage;
Expand Down Expand Up @@ -43,7 +41,6 @@ public class CommentService {
private final UserLibraryRepository userLibraryRepository;
private final TalkRoomRoleRepository talkRoomRoleRepository;
private final CommentImageRepository commentImageRepository;
private final BookRepository bookRepository;

@Transactional
public CommentResponse writeComment(CommentCreateServiceRequest request, Long talkRoomId, Long userId,
Expand All @@ -54,10 +51,8 @@ public CommentResponse writeComment(CommentCreateServiceRequest request, Long ta
TalkRoom talkRoom = talkRoomRepository.findById(talkRoomId)
.orElseThrow(() -> new BusinessException(ErrorCode.TALK_ROOM_NOT_FOUND));

Book book = bookRepository.findById(request.getIsbn())
.orElseThrow(() -> new BusinessException(ErrorCode.BOOK_NOT_FOUND));

Optional<ReadingStatus> userReadingStatus = userLibraryRepository.findByUserId(user.getId(), book.getIsbn());
Optional<ReadingStatus> userReadingStatus = userLibraryRepository.findByUserId(user.getId(),
talkRoom.getBook().getIsbn());

List<ReadingStatus> talkRoomReadingStatus = talkRoomRoleRepository.findTalkRoomRoleByTalkRoomId(
talkRoom.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ public class CommentCreateServiceRequest {

private List<String> imageUrls = new ArrayList<>();

private String isbn;

@Builder
private CommentCreateServiceRequest(String content, List<String> imageUrls, String isbn) {
private CommentCreateServiceRequest(String content, List<String> imageUrls) {
this.content = content;
this.imageUrls = imageUrls;
this.isbn = isbn;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void writeComment() throws Exception {
// given
CommentCreateRequest request = CommentCreateRequest.builder()
.content("의견을 작성하다")
.isbn("isbn")
.build();

// when // then
Expand All @@ -44,7 +43,6 @@ void writeComment() throws Exception {
void writeCommentWithEmptyContent() throws Exception {
// given
CommentCreateRequest request = CommentCreateRequest.builder()
.isbn("isbn")
.build();

// when // then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ void writeComment() {

CommentCreateServiceRequest request = CommentCreateServiceRequest.builder()
.content("의견 남기기")
.isbn(book.getIsbn())
.build();

// when
Expand Down Expand Up @@ -147,7 +146,6 @@ void writeCommentWithInvalidStatus() {

CommentCreateServiceRequest request = CommentCreateServiceRequest.builder()
.content("의견 남기기")
.isbn(book.getIsbn())
.build();

// when
Expand Down Expand Up @@ -181,7 +179,6 @@ void writeCommentWithStatusEmpty() {

CommentCreateServiceRequest request = CommentCreateServiceRequest.builder()
.content("의견 남기기")
.isbn(book.getIsbn())
.build();

// when
Expand Down Expand Up @@ -213,7 +210,6 @@ void writeCommentWithEmpty() {

CommentCreateServiceRequest request = CommentCreateServiceRequest.builder()
.content("의견 남기기")
.isbn(book.getIsbn())
.build();

// when
Expand Down Expand Up @@ -250,7 +246,6 @@ void writeCommentWithImages() {
CommentCreateServiceRequest request = CommentCreateServiceRequest.builder()
.content("의견 남기기")
.imageUrls(List.of("이미지 URL"))
.isbn(book.getIsbn())
.build();

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void createComment() throws Exception {
CommentCreateRequest request = CommentCreateRequest.builder()
.content("의견 내용")
.imageUrls(List.of("이미지 URL"))
.isbn("isbn")
.build();

given(commentService.writeComment(any(CommentCreateServiceRequest.class), any(Long.class),
Expand Down Expand Up @@ -83,9 +82,7 @@ void createComment() throws Exception {
fieldWithPath("content").type(JsonFieldType.STRING)
.description("의견 내용"),
fieldWithPath("imageUrls").type(JsonFieldType.ARRAY)
.description("이미지 URL").optional(),
fieldWithPath("isbn").type(JsonFieldType.STRING)
.description("ISBN")
.description("이미지 URL").optional()
),
responseFields(
fieldWithPath("code").type(JsonFieldType.NUMBER)
Expand Down

0 comments on commit b787792

Please sign in to comment.