Skip to content

Commit

Permalink
refactor : delete friend
Browse files Browse the repository at this point in the history
  • Loading branch information
NameIsUser06 committed Jan 8, 2024
1 parent e917729 commit cbe065a
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.investment.findfriend.domain.friend.service;

import com.investment.findfriend.domain.feed.repository.FeedRepository;
import com.investment.findfriend.domain.friend.domain.Friend;
import com.investment.findfriend.domain.friend.exception.FriendNotFoundException;
import com.investment.findfriend.domain.friend.repository.FriendRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -12,8 +15,14 @@
public class DeleteFriendService {

private final FriendRepository friendRepository;
private final FeedRepository feedRepository;

public ResponseEntity<String> execute(Long friendId) {
Friend friend = friendRepository.findById(friendId).orElseThrow(
() -> FriendNotFoundException.EXCEPTION
);
// 피드 내용 삭제
friend.getFeed().forEach(feed -> feedRepository.deleteById(feed.getId()));
// 친구 id 값을 통한 삭제
friendRepository.deleteById(friendId);
// 성공 여부 return
Expand Down

0 comments on commit cbe065a

Please sign in to comment.