Skip to content

Commit

Permalink
feat: 친구 추가 시 해당 친구 요청 삭제 로직 추가 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeong-hyeok committed Sep 14, 2023
1 parent 65ed766 commit e13da3d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +24,7 @@ public class FriendService {

private final MemberRepository memberRepository;
private final FriendRepository friendRepository;
private final FriendRequestRepository friendRequestRepository;

@Transactional(readOnly = true)
public Slice<FriendSearchResponseDto> searchMember(String email, String search, Pageable pageable) {
Expand All @@ -33,6 +36,8 @@ public Slice<FriendSearchResponseDto> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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<FriendRequest, Long> {

Optional<FriendRequest> findByFromMemberAndToMember(Member fromMember, Member toMember);
}
1 change: 1 addition & 0 deletions src/main/java/com/project/mapdagu/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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, "이미 존재하는 평가입니다."),
Expand Down

0 comments on commit e13da3d

Please sign in to comment.