-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 차단 관련 api 구현 #513
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
Merged
Gyuhyeok99
merged 15 commits into
solid-connection:develop
from
Gyuhyeok99:feat/506-user-block-api
Sep 27, 2025
Merged
feat: 차단 관련 api 구현 #513
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
919e9e2
feat: 유저 차단 api 추가
Gyuhyeok99 e56bd40
teat: 유저 차단 api 테스트 추가
Gyuhyeok99 55ce185
feat: 유저 차단 취소 api 추가
Gyuhyeok99 760ba02
test: 유저 차단 관련 fixture 추가
Gyuhyeok99 0e7705c
test: 유저 차단 취소 api 테스트 추가
Gyuhyeok99 61d0f53
feat: 유저 차단 조회 api 추가
Gyuhyeok99 fd1f33f
test: 유저 차단 조회 api 테스트 추가
Gyuhyeok99 f231b3a
feat: 차단한 유저의 게시글은 보이지 않도록 수정
Gyuhyeok99 159781f
feat: 차단한 유저의 게시글 댓글도 보이지 않도록 수정
Gyuhyeok99 82b4046
test: 코드리뷰 반영
Gyuhyeok99 d9c7b63
style: 불필요한 개행 제거
Gyuhyeok99 7fd42c4
style: 불필요한 개행 제거
Gyuhyeok99 a94ae52
style: 함수명 명확하게 변경
Gyuhyeok99 a4a6e5f
style: 개행 컨벤션 준수
Gyuhyeok99 d6331ba
refactor: validated 함수 분리
Gyuhyeok99 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -16,6 +16,15 @@ public interface PostRepository extends JpaRepository<Post, Long> { | |
|
|
||
| List<Post> findByBoardCode(String boardCode); | ||
|
|
||
| @Query(""" | ||
| SELECT p FROM Post p | ||
| WHERE p.boardCode = :boardCode | ||
| AND p.siteUserId NOT IN ( | ||
| SELECT ub.blockedId FROM UserBlock ub WHERE ub.blockerId = :siteUserId | ||
| ) | ||
| """) | ||
| List<Post> findByBoardCodeExcludingBlockedUsers(@Param("boardCode") String boardCode, @Param("siteUserId") Long siteUserId); | ||
|
Member
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. 여기도 todo 관련해서
Contributor
Author
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. 위에 말씀드린 것과 같은 이야기입니다! |
||
|
|
||
| @EntityGraph(attributePaths = {"postImageList"}) | ||
| Optional<Post> findPostById(Long id); | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/example/solidconnection/siteuser/dto/UserBlockResponse.java
This file contains hidden or 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,12 @@ | ||
| package com.example.solidconnection.siteuser.dto; | ||
|
|
||
| import java.time.ZonedDateTime; | ||
|
|
||
| public record UserBlockResponse( | ||
| long id, | ||
| long blockedId, | ||
| String nickname, | ||
| ZonedDateTime createdAt | ||
| ) { | ||
|
|
||
| } |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/example/solidconnection/siteuser/repository/UserBlockRepository.java
This file contains hidden or 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,27 @@ | ||
| package com.example.solidconnection.siteuser.repository; | ||
|
|
||
| import com.example.solidconnection.siteuser.domain.UserBlock; | ||
| import com.example.solidconnection.siteuser.dto.UserBlockResponse; | ||
| import java.util.Optional; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Slice; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| public interface UserBlockRepository extends JpaRepository<UserBlock, Long> { | ||
|
|
||
| boolean existsByBlockerIdAndBlockedId(long blockerId, long blockedId); | ||
|
|
||
| Optional<UserBlock> findByBlockerIdAndBlockedId(long blockerId, long blockedId); | ||
|
|
||
| @Query(""" | ||
| SELECT new com.example.solidconnection.siteuser.dto.UserBlockResponse( | ||
| ub.id, ub.blockedId, su.nickname, ub.createdAt | ||
| ) | ||
| FROM UserBlock ub | ||
| JOIN SiteUser su ON ub.blockedId = su.id | ||
| WHERE ub.blockerId = :blockerId | ||
| """) | ||
| Slice<UserBlockResponse> findBlockedUsersWithNickname(@Param("blockerId") long blockerId, Pageable pageable); | ||
| } |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/example/solidconnection/siteuser/service/SiteUserService.java
This file contains hidden or 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,18 +1,71 @@ | ||
| package com.example.solidconnection.siteuser.service; | ||
|
|
||
| import static com.example.solidconnection.common.exception.ErrorCode.ALREADY_BLOCKED_BY_CURRENT_USER; | ||
| import static com.example.solidconnection.common.exception.ErrorCode.BLOCK_USER_NOT_FOUND; | ||
| import static com.example.solidconnection.common.exception.ErrorCode.CANNOT_BLOCK_YOURSELF; | ||
| import static com.example.solidconnection.common.exception.ErrorCode.USER_NOT_FOUND; | ||
|
|
||
| import com.example.solidconnection.common.dto.SliceResponse; | ||
| import com.example.solidconnection.common.exception.CustomException; | ||
| import com.example.solidconnection.siteuser.domain.UserBlock; | ||
| import com.example.solidconnection.siteuser.dto.NicknameExistsResponse; | ||
| import com.example.solidconnection.siteuser.dto.UserBlockResponse; | ||
| import com.example.solidconnection.siteuser.repository.SiteUserRepository; | ||
| import com.example.solidconnection.siteuser.repository.UserBlockRepository; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Slice; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class SiteUserService { | ||
|
|
||
| private final SiteUserRepository siteUserRepository; | ||
| private final UserBlockRepository userBlockRepository; | ||
|
|
||
| public NicknameExistsResponse checkNicknameExists(String nickname) { | ||
| boolean exists = siteUserRepository.existsByNickname(nickname); | ||
| return NicknameExistsResponse.from(exists); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public SliceResponse<UserBlockResponse> getBlockedUsers(long siteUserId, Pageable pageable) { | ||
| Slice<UserBlockResponse> slice = userBlockRepository.findBlockedUsersWithNickname(siteUserId, pageable); | ||
|
|
||
| List<UserBlockResponse> content = slice.getContent(); | ||
| return SliceResponse.of(content, slice); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void blockUser(long blockerId, long blockedId) { | ||
| validateBlockUser(blockerId, blockedId); | ||
| UserBlock userBlock = new UserBlock(blockerId, blockedId); | ||
| userBlockRepository.save(userBlock); | ||
| } | ||
|
|
||
| private void validateBlockUser(long blockerId, long blockedId) { | ||
| if (Objects.equals(blockerId, blockedId)) { | ||
| throw new CustomException(CANNOT_BLOCK_YOURSELF); | ||
| } | ||
| if (!siteUserRepository.existsById(blockedId)) { | ||
| throw new CustomException(USER_NOT_FOUND); | ||
| } | ||
| if (userBlockRepository.existsByBlockerIdAndBlockedId(blockerId, blockedId)) { | ||
| throw new CustomException(ALREADY_BLOCKED_BY_CURRENT_USER); | ||
| } | ||
| } | ||
|
|
||
| @Transactional | ||
| public void cancelUserBlock(long blockerId, long blockedId) { | ||
| if (!siteUserRepository.existsById(blockedId)) { | ||
| throw new CustomException(USER_NOT_FOUND); | ||
| } | ||
| UserBlock userBlock = userBlockRepository.findByBlockerIdAndBlockedId(blockerId, blockedId) | ||
| .orElseThrow(() -> new CustomException(BLOCK_USER_NOT_FOUND)); | ||
| userBlockRepository.delete(userBlock); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
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.
todo 관련해서
OrderByCreatedAtDesc적용하면 될 거 같습니다 !오래된 순으로 응답이 만들어지는 게 당연한 로직이었네요 ...
Uh oh!
There was an error while loading. Please reload this page.
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.
앗 이건 일부로 적용 안했습니다! 차단기능 바로 상용 나갈건데 이러면 프론트 강제배포가 필요해서요!
서버만 먼저 나가면 오래된순으로 보이는 문제가 발생할 거 같습니다..
왜 아무도 몰랐을까요 🥲
인성님이 작업해주실테니 그때 수정해서 프론트랑 같이 배포나가면 좋을 거 같습니다! @Hexeong