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/#160-memories-getF4FStatus-api] 추억페이지 맞팔 상태 조회 #161

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ProfileResponse {
private long followerCount;
private long followingCount;
private Boolean isFollow;
private Boolean isF4F;
private PageInfo pageInfo;
private List<PostElement> postList;

Expand All @@ -33,6 +34,7 @@ public ProfileResponse(final Member member,
final long followerCount,
final long followingCount,
final Boolean isFollow,
final Boolean isF4F,
final Page<Post> postPage
) {
this.handle = member.getHandle();
Expand All @@ -43,6 +45,7 @@ public ProfileResponse(final Member member,
this.followerCount = followerCount;
this.followingCount = followingCount;
this.isFollow = isFollow;
this.isF4F = isF4F;
this.pageInfo = new PageInfo(postPage);
this.postList = postPage.getContent().stream().map(
PostElement::from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ public ProfileResponse getProfileDetail(
final Page<Post> taggedPost = postRepository.findTaggedPost(member, loginMember, pageable);
final Boolean isFollow = (handle.equals(loginMember.getHandle())) ?
null : followRepository.existsBySenderAndReceiver(loginMember, member);
final Boolean isF4F = (handle.equals(loginMember.getHandle())) ?
null : followRepository.existsBySenderAndReceiver(loginMember, member)
&& followRepository.existsBySenderAndReceiver(member, loginMember);

return ProfileResponse.of()
.member(member)
.postPage(taggedPost)
.followerCount(followerCount)
.followingCount(followingCount)
.isFollow(isFollow)
.isF4F(isF4F)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("api/v1/memories")
@RequestMapping("api/v1/memories/{handle}")
public class MemoriesController {

private final MemoriesService memoriesService;

@GetMapping("{handle}")
@GetMapping("")
@MemberOnly
public ApiResponse<MemoriesPreviewResponse> getMemories(
@Auth final Accessor accessor,
Expand All @@ -33,7 +33,7 @@ public ApiResponse<MemoriesPreviewResponse> getMemories(
return ApiResponse.onSuccess(memoriesService.getMemories(accessor, handle));
}

@GetMapping("{handle}/pochak")
@GetMapping("/pochak")
@MemberOnly
public ApiResponse<MemoriesPostResponse> getPochak(
@Auth final Accessor accessor,
Expand All @@ -43,7 +43,7 @@ public ApiResponse<MemoriesPostResponse> getPochak(
return ApiResponse.onSuccess(memoriesService.getPochak(accessor, handle, pageable));
}

@GetMapping("{handle}/pochaked")
@GetMapping("/pochaked")
@MemberOnly
public ApiResponse<MemoriesPostResponse> getPochaked(
@Auth final Accessor accessor,
Expand All @@ -53,7 +53,7 @@ public ApiResponse<MemoriesPostResponse> getPochaked(
return ApiResponse.onSuccess(memoriesService.getPochaked(accessor, handle, pageable));
}

@GetMapping("{handle}/bonded")
@GetMapping("/bonded")
@MemberOnly
public ApiResponse<MemoriesPostResponse> getBonded(
@Auth final Accessor accessor,
Expand All @@ -63,4 +63,12 @@ public ApiResponse<MemoriesPostResponse> getBonded(
return ApiResponse.onSuccess(memoriesService.getBonded(accessor, handle, pageable));
}

@GetMapping("/f4f/status")
@MemberOnly
public ApiResponse<Boolean> getF4FStatus(
@Auth final Accessor accessor,
@PathVariable("handle") final String handle
) {
return ApiResponse.onSuccess(memoriesService.getF4FStatus(accessor, handle));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ public MemoriesPostResponse getBonded(Accessor accessor, String handle, Pageable
final Page<Tag> tag = tagRepository.findTaggedWith(loginMember, member, pageable);
return MemoriesPostResponse.from(tag);
}

public Boolean getF4FStatus(Accessor accessor, String handle) {
final Member loginMember = memberRepository.findMemberById(accessor.getMemberId());
final Member member = memberRepository.findByHandle(handle, loginMember);

final boolean following = followRepository.existsBySenderAndReceiver(loginMember, member);
final boolean follower = followRepository.existsBySenderAndReceiver(member, loginMember);

return following && follower;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void getProfileTest() throws Exception {
.followerCount(1)
.followingCount(1)
.isFollow(null)
.isF4F(true)
.build()
);

Expand Down Expand Up @@ -117,6 +118,9 @@ void getProfileTest() throws Exception {
fieldWithPath("result.isFollow").type(BOOLEAN)
.description("현재 로그인한 멤버가 조회한 멤버를 팔로우하고 있는지의 여부 : 만약 본인이라면 null이 전달됩니다.")
.optional(),
fieldWithPath("result.isF4F").type(BOOLEAN)
.description("현재 로그인한 멤버가 조회한 멤버와 맞팔로우하고 있는지의 여부 : 만약 본인이라면 null이 전달됩니다.")
.optional(),
fieldWithPath("result.pageInfo").type(OBJECT).description("게시물 페이징 정보"),
fieldWithPath("result.pageInfo.lastPage").type(BOOLEAN)
.description(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,36 @@ void getBonded() throws Exception {
)
);
}

@Test
@DisplayName("[추억 페이지] 상대방과의 맞팔 상태를 조회한다.")
void getF4FStatus() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 문서화만 하면 끝날 것 같아요!! memories.adoc에!

when(memoriesService.getF4FStatus(any(), any()))
.thenReturn(true);

this.mockMvc.perform(
RestDocumentationRequestBuilders
.get("/api/v1/memories/{handle}/f4f/status", "member2")
.header(ACCESS_TOKEN_HEADER, ACCESS_TOKEN)
.contentType(APPLICATION_JSON)
).andExpect(status().isOk())
.andDo(
document("get-f4f-status",
getDocumentRequest(),
getDocumentResponse(),
requestHeaders(
headerWithName("Authorization").description("Basic auth credentials")
),
pathParameters(
parameterWithName("handle").description("친구의 아이디")
),
responseFields(
fieldWithPath("isSuccess").type(BOOLEAN).description("성공 여부"),
fieldWithPath("code").type(STRING).description("결과 코드"),
fieldWithPath("message").type(STRING).description("결과 메세지"),
fieldWithPath("result").type(BOOLEAN).description("결과 데이터")
)
)
);
}
}