From e13da3ddaa616956b0b3baec3c5d06b4b2fe33b6 Mon Sep 17 00:00:00 2001 From: kyeong-hyeok Date: Thu, 14 Sep 2023 13:50:49 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B9=9C=EA=B5=AC=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EC=8B=9C=20=ED=95=B4=EB=8B=B9=20=EC=B9=9C=EA=B5=AC=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#43)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/mapdagu/domain/friend/service/FriendService.java | 5 +++++ .../friendRequest/repository/FriendRequestRepository.java | 5 +++++ src/main/java/com/project/mapdagu/error/ErrorCode.java | 1 + 3 files changed, 11 insertions(+) diff --git a/src/main/java/com/project/mapdagu/domain/friend/service/FriendService.java b/src/main/java/com/project/mapdagu/domain/friend/service/FriendService.java index 546cccf..44a711a 100644 --- a/src/main/java/com/project/mapdagu/domain/friend/service/FriendService.java +++ b/src/main/java/com/project/mapdagu/domain/friend/service/FriendService.java @@ -3,6 +3,8 @@ import com.project.mapdagu.domain.friend.dto.response.FriendSearchResponseDto; import com.project.mapdagu.domain.friend.entity.Friend; import com.project.mapdagu.domain.friend.repository.FriendRepository; +import com.project.mapdagu.domain.friendRequest.entity.FriendRequest; +import com.project.mapdagu.domain.friendRequest.repository.FriendRequestRepository; import com.project.mapdagu.domain.member.entity.Member; import com.project.mapdagu.domain.member.repository.MemberRepository; import com.project.mapdagu.error.ErrorCode; @@ -22,6 +24,7 @@ public class FriendService { private final MemberRepository memberRepository; private final FriendRepository friendRepository; + private final FriendRequestRepository friendRequestRepository; @Transactional(readOnly = true) public Slice searchMember(String email, String search, Pageable pageable) { @@ -33,6 +36,8 @@ public Slice searchMember(String email, String search, public void saveFriend(String email, Long friendId) { Member member = memberRepository.findByEmail(email).orElseThrow(() -> new BusinessException(ErrorCode.MEMBER_NOT_FOUND)); Member friend = memberRepository.findById(friendId).orElseThrow(() -> new BusinessException(ErrorCode.MEMBER_NOT_FOUND)); + FriendRequest friendRequest = friendRequestRepository.findByFromMemberAndToMember(friend, member).orElseThrow(() -> new BusinessException(ErrorCode.FRIEND_REQUEST_NOT_FOUND)); + friendRequestRepository.delete(friendRequest); friendRepository.save(new Friend(member, friend)); } } diff --git a/src/main/java/com/project/mapdagu/domain/friendRequest/repository/FriendRequestRepository.java b/src/main/java/com/project/mapdagu/domain/friendRequest/repository/FriendRequestRepository.java index 6dd17a1..0801aa7 100644 --- a/src/main/java/com/project/mapdagu/domain/friendRequest/repository/FriendRequestRepository.java +++ b/src/main/java/com/project/mapdagu/domain/friendRequest/repository/FriendRequestRepository.java @@ -1,7 +1,12 @@ package com.project.mapdagu.domain.friendRequest.repository; import com.project.mapdagu.domain.friendRequest.entity.FriendRequest; +import com.project.mapdagu.domain.member.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface FriendRequestRepository extends JpaRepository { + + Optional findByFromMemberAndToMember(Member fromMember, Member toMember); } diff --git a/src/main/java/com/project/mapdagu/error/ErrorCode.java b/src/main/java/com/project/mapdagu/error/ErrorCode.java index 754d048..8b06af0 100644 --- a/src/main/java/com/project/mapdagu/error/ErrorCode.java +++ b/src/main/java/com/project/mapdagu/error/ErrorCode.java @@ -17,6 +17,7 @@ public enum ErrorCode { MEMBER_NOT_FOUND(NOT_FOUND, "해당 회원을 찾을 수 없습니다"), FOOD_NOT_FOUND(NOT_FOUND, "해당 음식을 찾을 수 없습니다"), EVALUATION_NOT_FOUND(NOT_FOUND, "해당 평가를 찾을 수 없습니다"), + FRIEND_REQUEST_NOT_FOUND(NOT_FOUND, "해당 친구 요청을 찾을 수 없습니다"), WRONG_SEARCH(BAD_REQUEST, "검색어를 입력해야 합니다."), ALREADY_EXIST_EVALUATION(BAD_REQUEST, "이미 존재하는 평가입니다."),