Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/202] 모든 친구 id 목록 조회 API 구현 #206

Merged
merged 1 commit into from
Sep 5, 2024
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
10 changes: 10 additions & 0 deletions src/main/java/com/gamegoo/controller/member/FriendController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public ApiResponse<List<MemberResponse.friendInfoDTO>> getFriendList() {

}

@Operation(summary = "모든 친구 id 조회 API", description = "해당 회원의 모든 친구 id 목록을 조회하는 API 입니다.\n\n"
+ "정렬 기능 없음, socket서버용 API 입니다.")
@GetMapping("/ids")
public ApiResponse<List<Long>> getFriendIds() {
Long memberId = JWTUtil.getCurrentUserId();

return ApiResponse.onSuccess(friendService.getFriendIds(memberId));

}

@Operation(summary = "친구 요청 전송 API", description = "대상 회원에게 친구 요청을 전송하는 API 입니다."
+ "대상 회원에게 친구 요청 알림을 전송하며, 대상 회원이 현재 접속 중인 경우 socket을 통해 실시간 알림을 전송합니다.")
@Parameter(name = "memberId", description = "친구 요청을 전송할 대상 회원의 id 입니다.")
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/gamegoo/service/member/FriendService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.gamegoo.util.SortUtil;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -46,6 +47,20 @@ public List<Friend> getFriends(Long memberId) {
return friendList;
}

/**
* memberId에 해당하는 회원의 모든 친구 id 조회
*
* @param memberId
* @return
*/
public List<Long> getFriendIds(Long memberId) {
Member member = profileService.findMember(memberId);

List<Friend> friendList = friendRepository.findAllByFromMemberId(member.getId());

return friendList.stream().map(friend -> friend.getToMember().getId())
.collect(Collectors.toList());
}

/**
* targetMemberId에 해당하는 회원에게 친구 요청 전송
Expand Down
Loading