Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@AllArgsConstructor
public class ReviewItemDTO {
private Long postId; // 게시글 ID
private Long memberId; // 사용자 ID
private String nickname; // 사용자 닉네임
private ReadingTasteType readingTasteType; // 독서 취향
private String profileImage; // 사용자 프로필 이미지
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private ReviewItemDTO convertToReviewItemDTO(Post post) {

return ReviewItemDTO.builder()
.postId(post.getId())
.memberId(post.getMember().getId())
.nickname(post.getMember().getNickname())
.readingTasteType(post.getMember().getReadingTasteType())
.profileImage(post.getMember().getProfileImage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.moongeul.backend.api.book.entity.Book;
import com.moongeul.backend.api.bookshelf.entity.DoneReadBookshelf;
import com.moongeul.backend.api.member.entity.Member;
import com.moongeul.backend.api.post.entity.Post;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -25,4 +26,7 @@ public interface DoneReadBookshelfRepository extends JpaRepository<DoneReadBooks
@Modifying(clearAutomatically = true)
@Query("DELETE FROM DoneReadBookshelf d WHERE d.member.id = :memberId")
void deleteAllByMemberId(@Param("memberId") Long memberId);

// 연동된 게시글 삭제 시 책장의 책도 삭제
void deleteByArticle(Post article);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.moongeul.backend.api.post.repository.PostRepository;
import com.moongeul.backend.api.post.repository.QuoteRepository;
import com.moongeul.backend.api.post.util.WritingGuideGenerator;
import com.moongeul.backend.api.story.entity.Story;
import com.moongeul.backend.api.story.repository.StoryRepository;
import com.moongeul.backend.common.annotation.Timer;
import com.moongeul.backend.common.exception.NotFoundException;
import com.moongeul.backend.common.exception.UnauthorizedException;
Expand Down Expand Up @@ -47,8 +49,9 @@ public class PostService {
private final CategoryRepository categoryRepository;
private final QuoteRepository quoteRepository;
private final DoneReadBookshelfRepository doneReadBookshelfRepository;
private final BookshelfCalculator bookshelfCalculator;
private final StoryRepository storyRepository;

private final BookshelfCalculator bookshelfCalculator;
private final NotificationTriggerService notificationTriggerService;
private final WritingGuideGenerator writingGuideGenerator;

Expand Down Expand Up @@ -338,6 +341,8 @@ public void deletePost(Long postId, String email){

Post post = getPost(postId);
Book book = post.getBook();
Story story = storyRepository.findByPostId(postId)
.orElseThrow(() -> new NotFoundException(ErrorStatus.STORY_NOTFOUND_EXCEPTION.getMessage()));

// 예외처리: 수정하는 사람과 게시글 주인이 같은지 확인 (본인의 게시글인지)
if (!post.getMember().getEmail().equals(email)) {
Expand All @@ -347,6 +352,12 @@ public void deletePost(Long postId, String email){
// 인상깊은구절 일괄 삭제
quoteRepository.deleteAllByPostId(postId);

// 연동된 Story 삭제
storyRepository.delete(story);

// 읽은 책장 데이터 삭제
doneReadBookshelfRepository.deleteByArticle(post);

// 게시글 삭제
postRepository.delete(post);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.data.repository.query.Param;

import java.time.LocalDateTime;
import java.util.Optional;

public interface StoryRepository extends JpaRepository<Story, Long> {

Expand Down Expand Up @@ -47,4 +48,7 @@ Page<Story> findAllFollowerStories(
"WHERE s.member.email = :email " +
"ORDER BY s.createdAt DESC")
Page<Story> findAllMyStories(@Param("email") String email, Pageable pageable);

// postId로 스토리 조회
Optional<Story> findByPostId(Long postId);
}
Loading