-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add review functionality * Add review functionality * [BOOK-16]-refactor: 독후감 생성 및 조회 api 수정 * [BOOK-16]-refactor: 코멘트 수정 사항 반영 * [BOOK-16]-refactor: 수정 기능 관련 수정 * [BOOK-16]-refactor: 추가 코멘트 사항 수정 --------- Co-authored-by: sunny2you <[email protected]>
- Loading branch information
1 parent
06726c0
commit 67c9d0c
Showing
23 changed files
with
565 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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
10 changes: 10 additions & 0 deletions
10
src/main/java/goorm/unit/booklog/domain/book/domain/BookRepository.java
This file contains 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 |
---|---|---|
@@ -1,4 +1,14 @@ | ||
package goorm.unit.booklog.domain.book.domain; | ||
|
||
|
||
import java.util.Optional; | ||
|
||
public interface BookRepository { | ||
|
||
Book save(Book book); | ||
|
||
Optional<Book> findById(Long id); | ||
|
||
Optional<Book> findByTitleAndAuthor(String title, String author); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/goorm/unit/booklog/domain/book/infrastructure/BookRepositoryImpl.java
This file contains 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 |
---|---|---|
@@ -1,13 +1,30 @@ | ||
package goorm.unit.booklog.domain.book.infrastructure; | ||
|
||
import goorm.unit.booklog.domain.book.domain.Book; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import goorm.unit.booklog.domain.book.domain.BookRepository; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class BookRepositoryImpl implements BookRepository { | ||
private final JpaBookRepository jpaBookRepository; | ||
|
||
@Override | ||
public Book save(Book book) { | ||
return jpaBookRepository.save(book); | ||
} | ||
|
||
@Override | ||
public Optional<Book> findById(Long id) { | ||
return jpaBookRepository.findById(id); | ||
} | ||
|
||
@Override | ||
public Optional<Book> findByTitleAndAuthor(String title, String author){ | ||
return jpaBookRepository.findByTitleAndAuthor(title,author); | ||
}; | ||
} |
This file contains 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 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 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
74 changes: 74 additions & 0 deletions
74
src/main/java/goorm/unit/booklog/domain/review/application/ReviewService.java
This file contains 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,74 @@ | ||
package goorm.unit.booklog.domain.review.application; | ||
|
||
import goorm.unit.booklog.domain.book.application.BookService; | ||
import goorm.unit.booklog.domain.book.domain.Book; | ||
import goorm.unit.booklog.domain.book.infrastructure.BookRepositoryImpl; | ||
import goorm.unit.booklog.domain.file.domain.File; | ||
import goorm.unit.booklog.domain.review.domain.Review; | ||
import goorm.unit.booklog.domain.review.domain.ReviewRepository; | ||
import goorm.unit.booklog.domain.review.domain.ReviewStatus; | ||
import goorm.unit.booklog.domain.review.presentation.request.ReviewCreateRequest; | ||
import goorm.unit.booklog.domain.review.presentation.response.ReviewPersistResponse; | ||
import goorm.unit.booklog.domain.review.presentation.response.ReviewResponse; | ||
import goorm.unit.booklog.domain.user.application.UserService; | ||
import goorm.unit.booklog.domain.user.domain.User; | ||
import goorm.unit.booklog.domain.review.presentation.exception.ReviewNotFoundException; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReviewService { | ||
private final ReviewRepository reviewRepository; | ||
private final BookRepositoryImpl bookRepository; | ||
private final UserService userService; | ||
private final BookService bookService; | ||
|
||
@Transactional | ||
public ReviewPersistResponse createReview(ReviewCreateRequest request) { | ||
User user = userService.me(); | ||
File file=File.of(request.title(), request.img()); | ||
Book book = bookService.getBook(request.bookResponse().id()); | ||
Review review = Review.create( | ||
request.title(), | ||
request.content(), | ||
file, | ||
user, | ||
book | ||
); | ||
Long id = reviewRepository.save(review).getId(); | ||
return ReviewPersistResponse.of(id); | ||
} | ||
|
||
@Transactional | ||
public ReviewResponse getReview(Long id) { | ||
Review review= reviewRepository.findById(id).orElseThrow(ReviewNotFoundException::new); | ||
return ReviewResponse.of(review); | ||
} | ||
|
||
@Transactional | ||
public ReviewResponse updateReview(Long id, ReviewCreateRequest request) { | ||
Review review = reviewRepository.findById(id) | ||
.orElseThrow(ReviewNotFoundException::new); | ||
Book book = bookService.getBook(request.bookResponse().id()); | ||
review.updateTitle(request.title()); | ||
review.updateContent(request.content()); | ||
review.updateBook(book); | ||
|
||
File file=review.getFile(); | ||
file.updateFile(request.img()); | ||
|
||
return ReviewResponse.of(review); | ||
} | ||
|
||
@Transactional | ||
public void deleteReview(Long id) { | ||
Review review = reviewRepository.findById(id).orElseThrow(ReviewNotFoundException::new); | ||
review.updateStatus(ReviewStatus.INACTIVE); | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/goorm/unit/booklog/domain/review/domain/Review.java
This file contains 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,75 @@ | ||
package goorm.unit.booklog.domain.review.domain; | ||
|
||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import goorm.unit.booklog.common.domain.BaseTimeEntity; | ||
import goorm.unit.booklog.domain.book.domain.Book; | ||
import goorm.unit.booklog.domain.file.domain.File; | ||
import goorm.unit.booklog.domain.user.domain.User; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Getter | ||
@Entity | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access= AccessLevel.PROTECTED) | ||
public class Review extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String title; | ||
|
||
@Column(nullable = false, length = 2000) | ||
private String content; | ||
|
||
@OneToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "file_id") | ||
private File file; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(nullable = false, length = 10) | ||
private ReviewStatus status = ReviewStatus.ACTIVE; // 기본값 설정 | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id",referencedColumnName = "id") // 외래 키 설정 | ||
private User user; | ||
|
||
@ManyToOne | ||
@JoinColumn(name="book_id") | ||
private Book book; | ||
|
||
public static Review create( String title, String content, File file,User user, Book book ) { | ||
return Review.builder() | ||
.title(title) | ||
.content(content) | ||
.file(file) | ||
.user(user) | ||
.status(ReviewStatus.ACTIVE) | ||
.book(book) | ||
.build(); | ||
} | ||
|
||
public void updateTitle( String title) { | ||
this.title = title; | ||
} | ||
|
||
public void updateContent(String content) { | ||
this.content = content; | ||
} | ||
|
||
public void updateBook( Book book ) { | ||
this.book = book; | ||
} | ||
|
||
public void updateStatus(ReviewStatus status) { | ||
this.status = status; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/goorm/unit/booklog/domain/review/domain/ReviewRepository.java
This file contains 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,11 @@ | ||
package goorm.unit.booklog.domain.review.domain; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ReviewRepository { | ||
|
||
Review save(Review review); | ||
|
||
Optional<Review> findById(Long id); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/goorm/unit/booklog/domain/review/domain/ReviewStatus.java
This file contains 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,13 @@ | ||
package goorm.unit.booklog.domain.review.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ReviewStatus { | ||
ACTIVE("활성화된 게시물 입니다."), | ||
INACTIVE("삭제된 게시물 입니다."); | ||
|
||
private final String description; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/goorm/unit/booklog/domain/review/infrastructure/JpaReviewRepository.java
This file contains 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,7 @@ | ||
package goorm.unit.booklog.domain.review.infrastructure; | ||
|
||
import goorm.unit.booklog.domain.review.domain.Review; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface JpaReviewRepository extends JpaRepository<Review,Long> { | ||
} |
Oops, something went wrong.