-
Notifications
You must be signed in to change notification settings - Fork 0
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
✨ list blocked users and unblock #451
Open
github-actions
wants to merge
5
commits into
be/dev
Choose a base branch
from
be/feat/450
base: be/dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6945612
Create PR for #450
github-actions[bot] d9e2076
:sparkles: unblock user
hyxrxn 1ae05fa
Merge branch 'be/dev' of https://github.com/woowacourse-teams/2024-pe…
hyxrxn b28e1d2
:sparkles: list blocked users
hyxrxn 117ad76
Merge branch 'be/dev' into be/feat/450
hyxrxn 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
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/net/pengcook/user/dto/UserBlockResponse.java
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,4 +1,10 @@ | ||
package net.pengcook.user.dto; | ||
|
||
import net.pengcook.user.domain.UserBlock; | ||
|
||
public record UserBlockResponse(UserResponse blocker, UserResponse blockee) { | ||
|
||
public UserBlockResponse(UserBlock userBlock) { | ||
this(new UserResponse(userBlock.getBlocker()), new UserResponse(userBlock.getBlockee())); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import net.pengcook.user.dto.UpdateProfileRequest; | ||
import net.pengcook.user.dto.UpdateProfileResponse; | ||
import net.pengcook.user.dto.UserBlockRequest; | ||
import net.pengcook.user.repository.UserBlockRepository; | ||
import net.pengcook.user.dto.UserFollowRequest; | ||
import net.pengcook.user.repository.UserRepository; | ||
import org.junit.jupiter.api.DisplayName; | ||
|
@@ -42,7 +43,8 @@ class UserControllerTest extends RestDocsSetting { | |
|
||
@Autowired | ||
UserRepository userRepository; | ||
|
||
@Autowired | ||
UserBlockRepository userBlockRepository; | ||
@Autowired | ||
ImageClientService imageClientService; | ||
|
||
|
@@ -349,7 +351,86 @@ void blockUser() { | |
} | ||
|
||
@Test | ||
@WithLoginUser | ||
@WithLoginUser(email = "[email protected]") | ||
@DisplayName("사용자 차단을 해제한다.") | ||
void deleteBlock() { | ||
UserBlockRequest userBlockRequest = new UserBlockRequest(3L); | ||
|
||
RestAssured.given(spec).log().all() | ||
.filter(document(DEFAULT_RESTDOCS_PATH, | ||
"사용자 차단을 해제합니다.", | ||
"사용자 차단 해제 API", | ||
requestFields( | ||
fieldWithPath("blockeeId").description("차단한 사용자 ID") | ||
) | ||
)) | ||
.contentType(ContentType.JSON) | ||
.body(userBlockRequest) | ||
.when().delete("/user/block") | ||
.then().log().all() | ||
.statusCode(204); | ||
|
||
boolean exists = userBlockRepository.existsByBlockerIdAndBlockeeId(1L, 3L); | ||
|
||
assertThat(exists).isFalse(); | ||
} | ||
|
||
@Test | ||
@WithLoginUser(email = "[email protected]") | ||
@DisplayName("사용자의 차단 목록을 불러온다.") | ||
void getBlockeesOf() { | ||
RestAssured.given(spec).log().all() | ||
.filter(document(DEFAULT_RESTDOCS_PATH, | ||
"로그인한 사용자의 차단 목록을 조회합니다.", | ||
"차단 목록 조회 API", | ||
responseFields( | ||
fieldWithPath("[]").description("차단 목록"), | ||
fieldWithPath("[].blocker.id").description("차단자 ID"), | ||
fieldWithPath("[].blocker.email").description("차단자 이메일"), | ||
fieldWithPath("[].blocker.username").description("차단자 아이디"), | ||
fieldWithPath("[].blocker.nickname").description("차단자 닉네임"), | ||
fieldWithPath("[].blocker.image").description("차단자 프로필 이미지"), | ||
fieldWithPath("[].blocker.region").description("차단자 국가"), | ||
fieldWithPath("[].blockee.id").description("차단대상 ID"), | ||
fieldWithPath("[].blockee.email").description("차단대상 이메일"), | ||
fieldWithPath("[].blockee.username").description("차단대상 아이디"), | ||
fieldWithPath("[].blockee.nickname").description("차단대상 닉네임"), | ||
fieldWithPath("[].blockee.image").description("차단대상 프로필 이미지"), | ||
fieldWithPath("[].blockee.region").description("차단대상 국가") | ||
) | ||
)) | ||
.contentType(ContentType.JSON) | ||
.when().get("/user/block/list") | ||
.then().log().all() | ||
.statusCode(200) | ||
.body("[0].blocker.id", equalTo(1)) | ||
.body("[0].blocker.email", equalTo("[email protected]")) | ||
.body("[0].blocker.username", equalTo("loki")) | ||
.body("[0].blocker.nickname", equalTo("로키")) | ||
.body("[0].blocker.image", equalTo("loki.jpg")) | ||
.body("[0].blocker.region", equalTo("KOREA")) | ||
.body("[0].blockee.id", equalTo(3)) | ||
.body("[0].blockee.email", equalTo("[email protected]")) | ||
.body("[0].blockee.username", equalTo("crocodile")) | ||
.body("[0].blockee.nickname", equalTo("악어")) | ||
.body("[0].blockee.image", equalTo("crocodile.jpg")) | ||
.body("[0].blockee.region", equalTo("KOREA")) | ||
.body("[1].blocker.id", equalTo(1)) | ||
.body("[1].blocker.email", equalTo("[email protected]")) | ||
.body("[1].blocker.username", equalTo("loki")) | ||
.body("[1].blocker.nickname", equalTo("로키")) | ||
.body("[1].blocker.image", equalTo("loki.jpg")) | ||
.body("[1].blocker.region", equalTo("KOREA")) | ||
.body("[1].blockee.id", equalTo(4)) | ||
.body("[1].blockee.email", equalTo("[email protected]")) | ||
.body("[1].blockee.username", equalTo("birdsheep")) | ||
.body("[1].blockee.nickname", equalTo("새양")) | ||
.body("[1].blockee.image", equalTo("birdsheep.jpg")) | ||
.body("[1].blockee.region", equalTo("KOREA")); | ||
} | ||
|
||
@Test | ||
@WithLoginUser(email = "[email protected]") | ||
@DisplayName("사용자를 삭제한다.") | ||
void deleteUser() { | ||
RestAssured.given(spec).log().all() | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import java.util.List; | ||
import net.pengcook.authentication.domain.UserInfo; | ||
import net.pengcook.comment.repository.CommentRepository; | ||
import net.pengcook.image.service.ImageClientService; | ||
|
@@ -195,7 +196,11 @@ void blockUser() { | |
|
||
UserBlockResponse actual = userService.blockUser(blockerId, blockeeId); | ||
|
||
assertThat(actual).isEqualTo(expected); | ||
assertAll( | ||
() -> assertThat(actual).isEqualTo(expected), | ||
() -> assertThat(userBlockRepository.existsByBlockerIdAndBlockeeId(1L, 2L)).isTrue() | ||
|
||
); | ||
Comment on lines
+199
to
+203
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. 👍👍 |
||
} | ||
|
||
@Test | ||
|
@@ -249,6 +254,58 @@ void blockUserWhenNotExistBlockee() { | |
.hasMessage("차단할 사용자를 찾을 수 없습니다."); | ||
} | ||
|
||
@Test | ||
@DisplayName("사용자 차단을 해제한다.") | ||
void deleteBlock() { | ||
long blockerId = 1L; | ||
long blockeeId = 3L; | ||
|
||
userService.deleteBlock(blockerId, blockeeId); | ||
|
||
assertThat(userBlockRepository.existsByBlockerIdAndBlockeeId(1L, 3L)).isFalse(); | ||
} | ||
|
||
@Test | ||
@DisplayName("차단을 해제하는 사용자가 존재하지 않으면 예외가 발생한다.") | ||
void deleteBlockWhenNotExistBlocker() { | ||
long blockerId = 2000L; | ||
long blockeeId = 3L; | ||
|
||
assertThatThrownBy(() -> userService.deleteBlock(blockerId, blockeeId)) | ||
.isInstanceOf(UserNotFoundException.class) | ||
.hasMessage("정상적으로 로그인되지 않았습니다."); | ||
} | ||
|
||
@Test | ||
@DisplayName("차단당한 사용자가 존재하지 않으면 예외가 발생한다.") | ||
void deleteBlockWhenNotExistBlockee() { | ||
long blockerId = 1L; | ||
long blockeeId = 2000L; | ||
|
||
assertThatThrownBy(() -> userService.deleteBlock(blockerId, blockeeId)) | ||
.isInstanceOf(UserNotFoundException.class) | ||
.hasMessage("차단한 사용자를 찾을 수 없습니다."); | ||
} | ||
|
||
@Test | ||
@DisplayName("차단 목록을 불러온다.") | ||
void getBlockeesOf() { | ||
long blockerId = 1L; | ||
List<UserBlockResponse> expected = List.of( | ||
new UserBlockResponse( | ||
new UserResponse(blockerId, "[email protected]", "loki", "로키", "loki.jpg", "KOREA"), | ||
new UserResponse(3L, "[email protected]", "crocodile", "악어", "crocodile.jpg", "KOREA") | ||
), | ||
new UserBlockResponse( | ||
new UserResponse(blockerId, "[email protected]", "loki", "로키", "loki.jpg", "KOREA"), | ||
new UserResponse(4L, "[email protected]", "birdsheep", "새양", "birdsheep.jpg", "KOREA") | ||
)); | ||
|
||
List<UserBlockResponse> userBlockResponses = userService.getBlockeesOf(blockerId); | ||
|
||
assertThat(userBlockResponses).containsExactlyElementsOf(expected); | ||
} | ||
|
||
@Test | ||
@DisplayName("차단한 사용자들의 목록을 불러올 수 있다.") | ||
void getBlockedUserGroup() { | ||
|
@@ -257,9 +314,9 @@ void getBlockedUserGroup() { | |
BlockedUserGroup blockedUserGroup = userService.getBlockedUserGroup(blockerId); | ||
|
||
assertAll( | ||
() -> assertThat(blockedUserGroup.isBlocked(2L)).isTrue(), | ||
() -> assertThat(blockedUserGroup.isBlocked(2L)).isFalse(), | ||
() -> assertThat(blockedUserGroup.isBlocked(3L)).isTrue(), | ||
() -> assertThat(blockedUserGroup.isBlocked(4L)).isFalse() | ||
() -> assertThat(blockedUserGroup.isBlocked(4L)).isTrue() | ||
); | ||
} | ||
|
||
|
Oops, something went wrong.
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.
👍