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 : 친구 초대 받은 목록, 보낸 목록 조회 API 추가 #457 #464

Merged
merged 9 commits into from
Jun 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.time.ZonedDateTime;
import org.springframework.http.ResponseEntity;
import site.timecapsulearchive.core.domain.friend.data.request.SearchFriendsRequest;
import site.timecapsulearchive.core.domain.friend.data.response.FriendRequestsSliceResponse;
import site.timecapsulearchive.core.domain.friend.data.response.FriendsSliceResponse;
import site.timecapsulearchive.core.domain.friend.data.response.SearchFriendsResponse;
import site.timecapsulearchive.core.domain.friend.data.response.SearchTagFriendSummaryResponse;
Expand Down Expand Up @@ -65,8 +64,34 @@ ResponseEntity<ApiSpec<FriendsSliceResponse>> findFriendsBeforeGroupInvite(
);

@Operation(
summary = "소셜 친구 요청 목록 조회",
description = "사용자의 소셜 친구 요청 목록을 보여준다. 수락 대기 중인 요청만 해당한다.",
summary = "소셜 친구 요청 받은 목록 조회",
description = """
사용자가 <b><u>소셜 친구 요청을 받은 목록</u></b>을 보여준다.
<br>
수락 대기 중인 요청만 해당한다.
""",
security = {@SecurityRequirement(name = "user_token")},
tags = {"friend"}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "ok"
)
})
ResponseEntity<ApiSpec<FriendsSliceResponse>> findFriendReceivingInvites(
Long memberId,

@Parameter(in = ParameterIn.QUERY, description = "페이지 크기", required = true)
int size,

@Parameter(in = ParameterIn.QUERY, description = "마지막 데이터의 시간", required = true)
ZonedDateTime createdAt
);

@Operation(
summary = "소셜 친구 요청 보낸 목록 조회",
description = "사용자가 <b><u>소셜 친구 요청을 보낸 목록</u></b>을 보여준다.",
security = {@SecurityRequirement(name = "user_token")},
tags = {"friend"}
)
Expand All @@ -76,7 +101,7 @@ ResponseEntity<ApiSpec<FriendsSliceResponse>> findFriendsBeforeGroupInvite(
description = "ok"
)
})
ResponseEntity<ApiSpec<FriendRequestsSliceResponse>> findFriendRequests(
ResponseEntity<ApiSpec<FriendsSliceResponse>> findFriendSendingInvites(
Long memberId,

@Parameter(in = ParameterIn.QUERY, description = "페이지 크기", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import site.timecapsulearchive.core.domain.friend.data.dto.SearchFriendSummaryDtoByTag;
import site.timecapsulearchive.core.domain.friend.data.request.FriendBeforeGroupInviteRequest;
import site.timecapsulearchive.core.domain.friend.data.request.SearchFriendsRequest;
import site.timecapsulearchive.core.domain.friend.data.response.FriendRequestsSliceResponse;
import site.timecapsulearchive.core.domain.friend.data.response.FriendsSliceResponse;
import site.timecapsulearchive.core.domain.friend.data.response.SearchFriendsResponse;
import site.timecapsulearchive.core.domain.friend.data.response.SearchTagFriendSummaryResponse;
Expand Down Expand Up @@ -77,23 +76,45 @@ public ResponseEntity<ApiSpec<FriendsSliceResponse>> findFriendsBeforeGroupInvit
}

@GetMapping(
value = "/requests",
value = "/receiving-invites",
produces = {"application/json"}
)
@Override
public ResponseEntity<ApiSpec<FriendRequestsSliceResponse>> findFriendRequests(
public ResponseEntity<ApiSpec<FriendsSliceResponse>> findFriendReceivingInvites(
@AuthenticationPrincipal final Long memberId,
@RequestParam(defaultValue = "20", value = "size") final int size,
@RequestParam(value = "created_at") final ZonedDateTime createdAt
) {
final Slice<FriendSummaryDto> friendRequestsSlice = friendQueryService.findFriendRequestsSlice(
final Slice<FriendSummaryDto> friendReceivingInvitesSlice = friendQueryService.findFriendReceivingInvitesSlice(
memberId, size, createdAt);

return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
FriendRequestsSliceResponse.createOf(friendRequestsSlice.getContent(),
friendRequestsSlice.hasNext())
FriendsSliceResponse.createOf(friendReceivingInvitesSlice.getContent(),
friendReceivingInvitesSlice.hasNext())
)
);
}

@GetMapping(
value = "/sending-invites",
produces = {"application/json"}
)
@Override
public ResponseEntity<ApiSpec<FriendsSliceResponse>> findFriendSendingInvites(
@AuthenticationPrincipal final Long memberId,
@RequestParam(defaultValue = "20", value = "size") final int size,
@RequestParam(value = "created_at") final ZonedDateTime createdAt
) {
final Slice<FriendSummaryDto> friendSendingInvitesSlice = friendQueryService.findFriendSendingInvitesSlice(
memberId, size, createdAt);

return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
FriendsSliceResponse.createOf(friendSendingInvitesSlice.getContent(),
friendSendingInvitesSlice.hasNext())
)
);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
package site.timecapsulearchive.core.domain.friend.repository.friend_invite;

import java.time.ZonedDateTime;
import java.util.List;
import org.springframework.data.domain.Slice;
import site.timecapsulearchive.core.domain.friend.data.dto.FriendSummaryDto;

public interface FriendInviteQueryRepository {

void bulkSave(final Long ownerId, final List<Long> friendIds);


Slice<FriendSummaryDto> findFriendReceivingInvitesSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
);

Slice<FriendSummaryDto> findFriendSendingInvitesSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
);
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
package site.timecapsulearchive.core.domain.friend.repository.friend_invite;

import static site.timecapsulearchive.core.domain.friend.entity.QFriendInvite.friendInvite;
import static site.timecapsulearchive.core.domain.member.entity.QMember.member;

import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.ZonedDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import site.timecapsulearchive.core.domain.friend.data.dto.FriendSummaryDto;
import site.timecapsulearchive.core.global.util.SliceUtil;

@Repository
@RequiredArgsConstructor
public class FriendInviteQueryRepositoryImpl implements FriendInviteQueryRepository {

private final JdbcTemplate jdbcTemplate;
private final JPAQueryFactory jpaQueryFactory;

public void bulkSave(final Long ownerId, final List<Long> friendIds) {
if (friendIds.isEmpty()) {
Expand Down Expand Up @@ -47,4 +58,53 @@ public int getBatchSize() {
}
);
}

public Slice<FriendSummaryDto> findFriendReceivingInvitesSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
) {
final List<FriendSummaryDto> friends = jpaQueryFactory
.select(
Projections.constructor(
FriendSummaryDto.class,
friendInvite.owner.id,
friendInvite.owner.profileUrl,
friendInvite.owner.nickname,
friendInvite.createdAt
)
)
.from(friendInvite)
.join(friendInvite.owner, member)
.where(friendInvite.friend.id.eq(memberId).and(friendInvite.createdAt.lt(createdAt)))
.limit(size + 1)
.fetch();

return SliceUtil.makeSlice(size, friends);
}

@Override
public Slice<FriendSummaryDto> findFriendSendingInvitesSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
) {
final List<FriendSummaryDto> friends = jpaQueryFactory
.select(
Projections.constructor(
FriendSummaryDto.class,
friendInvite.friend.id,
friendInvite.friend.profileUrl,
friendInvite.friend.nickname,
friendInvite.createdAt
)
)
.from(friendInvite)
.join(friendInvite.owner, member)
.where(friendInvite.owner.id.eq(memberId).and(friendInvite.createdAt.lt(createdAt)))
.limit(size + 1)
.fetch();

return SliceUtil.makeSlice(size, friends);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ Slice<FriendSummaryDto> findFriendsSlice(
final ZonedDateTime createdAt
);

Slice<FriendSummaryDto> findFriendRequestsSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
);

List<SearchFriendSummaryDto> findFriendsByPhone(
final Long memberId,
final List<byte[]> hashes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,6 @@ public Slice<FriendSummaryDto> findFriendsBeforeGroupInvite(
return getFriendSummaryDtos(request.size(), friends);
}

public Slice<FriendSummaryDto> findFriendRequestsSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
) {
final List<FriendSummaryDto> friends = jpaQueryFactory
.select(
Projections.constructor(
FriendSummaryDto.class,
friendInvite.owner.id,
friendInvite.owner.profileUrl,
friendInvite.owner.nickname,
friendInvite.createdAt
)
)
.from(friendInvite)
.join(friendInvite.owner, member)
.where(friendInvite.friend.id.eq(memberId).and(friendInvite.createdAt.lt(createdAt)))
.limit(size + 1)
.fetch();

return getFriendSummaryDtos(size, friends);
}

public List<SearchFriendSummaryDto> findFriendsByPhone(
final Long memberId,
final List<byte[]> hashes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import site.timecapsulearchive.core.domain.friend.data.dto.SearchFriendSummaryDtoByTag;
import site.timecapsulearchive.core.domain.friend.data.request.FriendBeforeGroupInviteRequest;
import site.timecapsulearchive.core.domain.friend.exception.FriendNotFoundException;
import site.timecapsulearchive.core.domain.friend.repository.friend_invite.FriendInviteRepository;
import site.timecapsulearchive.core.domain.friend.repository.member_friend.MemberFriendRepository;
import site.timecapsulearchive.core.global.common.wrapper.ByteArrayWrapper;

Expand All @@ -20,6 +21,7 @@
public class FriendQueryService {

private final MemberFriendRepository memberFriendRepository;
private final FriendInviteRepository friendInviteRepository;

public Slice<FriendSummaryDto> findFriendsSlice(
final Long memberId,
Expand All @@ -34,12 +36,20 @@ public Slice<FriendSummaryDto> findFriendsBeforeGroupInviteSlice(
return memberFriendRepository.findFriendsBeforeGroupInvite(request);
}

public Slice<FriendSummaryDto> findFriendRequestsSlice(
public Slice<FriendSummaryDto> findFriendReceivingInvitesSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
) {
return memberFriendRepository.findFriendRequestsSlice(memberId, size, createdAt);
return friendInviteRepository.findFriendReceivingInvitesSlice(memberId, size, createdAt);
}

public Slice<FriendSummaryDto> findFriendSendingInvitesSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
) {
return friendInviteRepository.findFriendSendingInvitesSlice(memberId, size, createdAt);
}

public List<SearchFriendSummaryDto> findFriendsByPhone(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package site.timecapsulearchive.core.global.util;

import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;

public final class SliceUtil {

private SliceUtil() {

}

public static <T> Slice<T> makeSlice(final int size, final List<T> dtos) {
final boolean hasNext = dtos.size() > size;
if (hasNext) {
dtos.remove(size);
}

return new SliceImpl<>(dtos, Pageable.ofSize(size), hasNext);
}
}
Loading
Loading