-
Notifications
You must be signed in to change notification settings - Fork 6
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
[User] 친구 신청 조회 API 구현 #174
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a001c3b
Merge branch 'dev' of https://github.com/kSideProject/kpring into dev
minahYu d41c13a
Merge branch 'dev' of https://github.com/kSideProject/kpring into dev
minahYu 6e61306
Merge branch 'dev' of https://github.com/kSideProject/kpring into dev
minahYu 8347daf
chore: 응답 dto 디렉토리명 response로 변경
minahYu a2da747
feat: GetFriendRequestResponse 생성
minahYu 1bbcbd0
feat: GetFriendRequestsResponse 생성
minahYu db0117c
feat: FriendController에 친구신청 조회 메서드 추가
minahYu 8640c9d
feat: FriendRepository에 findAllByUserIdAndRequestStatus 메서드 추가
minahYu 08effd9
feat: FriendServiceImpl에 getFriendRequests 메서드 추가
minahYu 419bf37
test: FriendControllerTest에 친구신청 조회 관련 테스트 코드 추가
minahYu 1763648
test: FriendServiceImplTest에 친구신청 조회 관련 테스트 코드 추가
minahYu c3d218a
refac: friendRequests immutable 한 타입으로 변경
minahYu e4ee4fa
refac: 가독성을 위해 stream api로 변환
minahYu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ring/user/dto/result/AddFriendResponse.kt → ...ng/user/dto/response/AddFriendResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
user/src/main/kotlin/kpring/user/dto/response/GetFriendRequestResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package kpring.user.dto.response | ||
|
||
data class GetFriendRequestResponse( | ||
val friendId: Long, | ||
val username: String, | ||
) |
6 changes: 6 additions & 0 deletions
6
user/src/main/kotlin/kpring/user/dto/response/GetFriendRequestsResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package kpring.user.dto.response | ||
|
||
data class GetFriendRequestsResponse( | ||
val userId: Long, | ||
var friendRequests: List<GetFriendRequestResponse>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
user/src/main/kotlin/kpring/user/repository/FriendRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
package kpring.user.repository | ||
|
||
import kpring.user.entity.Friend | ||
import kpring.user.entity.FriendRequestStatus | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface FriendRepository : JpaRepository<Friend, Long> { | ||
fun existsByUserIdAndFriendId( | ||
userId: Long, | ||
friendId: Long, | ||
): Boolean | ||
|
||
fun findAllByUserIdAndRequestStatus( | ||
userId: Long, | ||
requestStatus: FriendRequestStatus, | ||
): List<Friend> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 17 additions & 3 deletions
20
user/src/main/kotlin/kpring/user/service/FriendServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,12 @@ import kpring.core.auth.enums.TokenType | |
import kpring.core.global.dto.response.ApiResponse | ||
import kpring.core.global.exception.ServiceException | ||
import kpring.test.restdoc.dsl.restDoc | ||
import kpring.test.restdoc.json.JsonDataType | ||
import kpring.test.restdoc.json.JsonDataType.Strings | ||
import kpring.user.dto.response.AddFriendResponse | ||
import kpring.user.dto.response.FailMessageResponse | ||
import kpring.user.dto.result.AddFriendResponse | ||
import kpring.user.dto.response.GetFriendRequestResponse | ||
import kpring.user.dto.response.GetFriendRequestsResponse | ||
import kpring.user.exception.UserErrorCode | ||
import kpring.user.global.AuthValidator | ||
import kpring.user.global.CommonTest | ||
|
@@ -194,4 +197,151 @@ internal class FriendControllerTest( | |
} | ||
} | ||
} | ||
|
||
describe("친구신청 조회 API") { | ||
it("친구신청 조회 성공") { | ||
// given | ||
val friendRequest = | ||
GetFriendRequestResponse( | ||
friendId = CommonTest.TEST_FRIEND_ID, | ||
username = CommonTest.TEST_FRIEND_USERNAME, | ||
) | ||
val data = | ||
GetFriendRequestsResponse( | ||
userId = CommonTest.TEST_USER_ID, | ||
friendRequests = mutableListOf(friendRequest), | ||
) | ||
val response = ApiResponse(data = data) | ||
|
||
every { authClient.getTokenInfo(any()) }.returns( | ||
ApiResponse(data = TokenInfo(TokenType.ACCESS, CommonTest.TEST_USER_ID.toString())), | ||
) | ||
every { | ||
authValidator.checkIfAccessTokenAndGetUserId(any()) | ||
} returns CommonTest.TEST_USER_ID.toString() | ||
every { authValidator.checkIfUserIsSelf(any(), any()) } returns Unit | ||
every { | ||
friendService.getFriendRequests(CommonTest.TEST_USER_ID) | ||
} returns data | ||
|
||
// when | ||
val result = | ||
webTestClient.get() | ||
.uri( | ||
"/api/v1/user/{userId}/requests", | ||
CommonTest.TEST_USER_ID, | ||
) | ||
.header("Authorization", CommonTest.TEST_TOKEN) | ||
.exchange() | ||
|
||
// then | ||
val docsRoot = | ||
result | ||
.expectStatus().isOk | ||
.expectBody().json(objectMapper.writeValueAsString(response)) | ||
|
||
// docs | ||
docsRoot | ||
.restDoc( | ||
identifier = "getFriendRequests200", | ||
description = "친구신청 조회 API", | ||
) { | ||
request { | ||
path { | ||
"userId" mean "사용자 아이디" | ||
} | ||
header { "Authorization" mean "Bearer token" } | ||
} | ||
response { | ||
body { | ||
"data.userId" type Strings mean "사용자 아이디" | ||
"data.friendRequests" type JsonDataType.Arrays mean "친구신청한 사용자 리스트" | ||
"data.friendRequests[].friendId" type Strings mean "친구신청한 사용자 아이디" | ||
"data.friendRequests[].username" type Strings mean "친구신청한 사용자 닉네임" | ||
} | ||
Comment on lines
+258
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. frinedRequest는 무슨의미로 사용한 건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. friendReuqests는 로그인한 사용자가 받은 친구신청 목록을 의미합니다! |
||
} | ||
} | ||
} | ||
it("친구신청 조회 실패 : 권한이 없는 토큰") { | ||
// given | ||
val response = | ||
FailMessageResponse.builder().message(UserErrorCode.NOT_ALLOWED.message()).build() | ||
every { authClient.getTokenInfo(any()) } throws ServiceException(UserErrorCode.NOT_ALLOWED) | ||
|
||
// when | ||
val result = | ||
webTestClient.get() | ||
.uri( | ||
"/api/v1/user/{userId}/requests", | ||
CommonTest.TEST_USER_ID, | ||
) | ||
.header("Authorization", CommonTest.TEST_TOKEN) | ||
.exchange() | ||
|
||
// then | ||
val docsRoot = | ||
result | ||
.expectStatus().isForbidden | ||
.expectBody().json(objectMapper.writeValueAsString(response)) | ||
|
||
// docs | ||
docsRoot | ||
.restDoc( | ||
identifier = "getFriendRequests403", | ||
description = "친구신청 조회 API", | ||
) { | ||
request { | ||
path { | ||
"userId" mean "사용자 아이디" | ||
} | ||
header { "Authorization" mean "Bearer token" } | ||
} | ||
response { | ||
body { | ||
"message" type Strings mean "에러 메시지" | ||
} | ||
} | ||
} | ||
} | ||
it("친구신청 조회 실패 : 서버 내부 오류") { | ||
// given | ||
val response = FailMessageResponse.serverError | ||
every { authClient.getTokenInfo(any()) } throws RuntimeException("서버 내부 오류") | ||
|
||
// when | ||
val result = | ||
webTestClient.get() | ||
.uri( | ||
"/api/v1/user/{userId}/requests", | ||
CommonTest.TEST_USER_ID, | ||
) | ||
.header("Authorization", CommonTest.TEST_TOKEN) | ||
.exchange() | ||
|
||
// then | ||
val docsRoot = | ||
result | ||
.expectStatus().isEqualTo(500) | ||
.expectBody().json(objectMapper.writeValueAsString(response)) | ||
|
||
// docs | ||
docsRoot | ||
.restDoc( | ||
identifier = "getFriendRequests500", | ||
description = "친구신청 조회 API", | ||
) { | ||
request { | ||
path { | ||
"userId" mean "사용자 아이디" | ||
} | ||
header { "Authorization" mean "Bearer token" } | ||
} | ||
response { | ||
body { | ||
"message" type Strings mean "에러 메시지" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 토큰에서 뽑을 수 있는 userId랑은 다른 정보일까요?! 제가 생각하기에는 요청하는 user의 id를 토큰에서 뽑아와서 사용하면 될 것 같은데..! 입력을 따로 받는 이유가 있나요?! 궁금합니다 😽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
토큰에서 뽑을 수 있는 userId랑 같은 정보입니다! 기존에 작성되어 있던 코드들이 pathVariable로 userId를 받아와서 동일하게 코드 작성했었는데, user쪽 기능 구현 다 하면 수정해봐도 좋을 것 같아요! 추후에 수정하겠습니다~!