-
Notifications
You must be signed in to change notification settings - Fork 0
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
독후감 리스트 반환 api #98
독후감 리스트 반환 api #98
Changes from all commits
ee4562b
4da1cb2
c2e6d13
f4726d4
37c1a43
f75f57f
c3ed979
5ad0aa6
c0378e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.mindway.server.v2.domain.book.presentation.dto.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Builder | ||
@Getter | ||
public class BookListResponse { | ||
private Long id; | ||
private String title; | ||
private String plot; | ||
private LocalDate date; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package com.mindway.server.v2.domain.book.repository; | ||
|
||
import com.mindway.server.v2.domain.book.entity.Book; | ||
import com.mindway.server.v2.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface BookRepository extends JpaRepository<Book, Long> { | ||
|
||
List<Book> findAllByUser(User user); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.mindway.server.v2.domain.book.service; | ||
|
||
import com.mindway.server.v2.domain.book.presentation.dto.response.BookListResponse; | ||
|
||
import java.util.List; | ||
|
||
public interface GetBookListService { | ||
List<BookListResponse> execute(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.mindway.server.v2.domain.book.service.impl; | ||
|
||
import com.mindway.server.v2.domain.book.entity.Book; | ||
import com.mindway.server.v2.domain.book.exception.NotSameAuthorException; | ||
import com.mindway.server.v2.domain.book.presentation.dto.response.BookListResponse; | ||
import com.mindway.server.v2.domain.book.repository.BookRepository; | ||
import com.mindway.server.v2.domain.book.service.GetBookListService; | ||
import com.mindway.server.v2.domain.book.util.BookConverter; | ||
import com.mindway.server.v2.domain.user.entity.User; | ||
import com.mindway.server.v2.domain.user.util.UserUtil; | ||
import com.mindway.server.v2.global.annotation.ServiceWithReadOnlyTransaction; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@ServiceWithReadOnlyTransaction | ||
@RequiredArgsConstructor | ||
public class GetBookListServiceImpl implements GetBookListService { | ||
private final UserUtil userUtil; | ||
private final BookRepository bookRepository; | ||
private final BookConverter bookConverter; | ||
|
||
public List<BookListResponse> execute() { | ||
User user = userUtil.getCurrentUser(); | ||
List<Book> books = bookRepository.findAllByUser(user); | ||
|
||
if (user != books.get(0).getUser()) { | ||
throw new NotSameAuthorException(); | ||
} | ||
|
||
return books.stream() | ||
.map(bookConverter::toListDto) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,14 @@ | |
import com.mindway.server.v2.domain.book.entity.Book; | ||
import com.mindway.server.v2.domain.book.presentation.dto.request.BookWriteRequest; | ||
import com.mindway.server.v2.domain.book.presentation.dto.response.BookInfoResponse; | ||
import com.mindway.server.v2.domain.book.presentation.dto.response.BookListResponse; | ||
import com.mindway.server.v2.domain.book.util.BookConverter; | ||
import com.mindway.server.v2.domain.user.entity.User; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
@Component | ||
public class BookConverterImpl implements BookConverter { | ||
|
||
|
@@ -24,4 +28,13 @@ public BookInfoResponse toDto(Book book) { | |
.plot(book.getPlot()) | ||
.build(); | ||
} | ||
|
||
public BookListResponse toListDto(Book book) { | ||
return BookListResponse.builder() | ||
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.
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. 수정했습니다 |
||
.id(book.getId()) | ||
.title(book.getTitle()) | ||
.plot(book.getPlot()) | ||
.date(LocalDate.from(book.getCreateAt())) | ||
.build(); | ||
} | ||
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. public BookListResponse toListDto(Book book) {
return BookListResponse.builder()
.id(book.getId())
.title(book.getTitle())
.plot(book.getPlot())
.date(LocalDate.from(book.getCreateAt()))
.build();
} 이렇게 수정하면 될거같아요오 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. 수정했습니다 |
||
} |
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.
date를 String말구 LocalDate로 하는 건 어떤가요??
그러면 BookConverter에서 굳이 형식을 지정하지 않아도 되고 간결해질 거 같아요!
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.
5ad0aa6
수정했습니다