Skip to content

Commit

Permalink
[Feat]: 친구 요청 여부 확인 API
Browse files Browse the repository at this point in the history
관련 로직 작성

Related to: #70
  • Loading branch information
dev-Crayon committed Jan 31, 2024
1 parent dc088eb commit 4a04857
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum SuccessCode {
GET_FRIEND_LIST_SUCCESS(HttpStatus.OK, "친구 리스트 조회에 성공했습니다."),
HANDLE_FRIEND_REQUEST_SUCCESS(HttpStatus.OK, "공유 응답에 성공했습니다."),
UPDATE_FRIEND_NAME_SUCCESS(HttpStatus.OK, "멤버 이름 수정에 성공했습니다."),
GET_REQUEST_FRIEND_SUCCESS(HttpStatus.OK, "친구 요청 여부 조회에 성공했습니다."),

// notice
GET_NOTICE_LIST_SUCCESS(HttpStatus.OK, "알림 리스트 조회에 성공했습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.sobok.SobokSobok.exception.model.NotFoundException;
import io.sobok.SobokSobok.friend.domain.Friend;
import io.sobok.SobokSobok.friend.domain.SendFriend;
import io.sobok.SobokSobok.friend.infrastructure.FriendQueryRepository;
import io.sobok.SobokSobok.friend.infrastructure.FriendRepository;
import io.sobok.SobokSobok.friend.infrastructure.SendFriendRepository;
import io.sobok.SobokSobok.friend.ui.dto.AddFriendRequest;
Expand Down Expand Up @@ -40,6 +41,7 @@ public class FriendService {
private final SendFriendRepository sendFriendRepository;
private final FriendRepository friendRepository;
private final NoticeQueryRepository noticeQueryRepository;
private final FriendQueryRepository friendQueryRepository;

@Transactional
public AddFriendResponse addFriend(Long userId, AddFriendRequest request) {
Expand Down Expand Up @@ -165,4 +167,19 @@ public UpdateFriendNameResponse updateFriendName(Long userId, Long friendId, Upd
.friendName(request.friendName())
.build();
}

@Transactional
public Boolean checkFriendRequest(Long userId, Long friendId) {

boolean AlreadyFriendRequest = false;

UserServiceUtil.existsUserById(userRepository, userId);
UserServiceUtil.existsUserById(userRepository, friendId);

if (friendQueryRepository.isAlreadyFriend(userId, friendId) || noticeRepository.existsBySenderIdAndReceiverIdAndIsOkay(userId, friendId, NoticeStatus.WAITING)) {
AlreadyFriendRequest = true;
}

return AlreadyFriendRequest;
}
}
18 changes: 18 additions & 0 deletions src/main/java/io/sobok/SobokSobok/friend/ui/FriendController.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,22 @@ public ResponseEntity<ApiResponse<UpdateFriendNameResponse>> updateFriendName(
friendService.updateFriendName(user.getId(), friendId, request)
));
}

@GetMapping("/request/{friendId}")
@Operation(
summary = "친구 신청 여부 확인 API 메서드",
description = "친구 신청을 했는지 확인하는 메서드입니다."
)
public ResponseEntity<ApiResponse<Boolean>> checkFriendRequest(
@AuthenticationPrincipal User user,
@PathVariable Long friendId
) {

return ResponseEntity
.status(HttpStatus.OK)
.body(ApiResponse.success(
SuccessCode.GET_REQUEST_FRIEND_SUCCESS,
friendService.checkFriendRequest(user.getId(), friendId)
));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package io.sobok.SobokSobok.notice.infrastructure;

import io.sobok.SobokSobok.notice.domain.Notice;
import io.sobok.SobokSobok.notice.domain.NoticeStatus;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface NoticeRepository extends JpaRepository<Notice, Long> {

// READ
Boolean existsBySenderIdAndReceiverIdAndIsOkay(Long senderId, Long receiverId, NoticeStatus isOkay);
}

0 comments on commit 4a04857

Please sign in to comment.