Skip to content

Commit 1bb798d

Browse files
authored
Merge pull request #123 from Dugout-Developers/feat/#122
[FEAT] 유저 차단 API 기능 구현
2 parents 42b282d + 197d98f commit 1bb798d

File tree

15 files changed

+262
-12
lines changed

15 files changed

+262
-12
lines changed

src/main/java/com/back/catchmate/domain/board/repository/BoardRepositoryCustom.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
import java.util.List;
99

1010
public interface BoardRepositoryCustom {
11-
Page<Board> findFilteredBoards(LocalDate gameDate, Integer maxPerson, List<Long> preferredTeamIdList, Pageable pageable);
11+
Page<Board> findFilteredBoards(Long userId, LocalDate gameDate, Integer maxPerson, List<Long> preferredTeamIdList, Pageable pageable);
1212
}

src/main/java/com/back/catchmate/domain/board/repository/BoardRepositoryImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.back.catchmate.domain.board.entity.QBoard;
55
import com.back.catchmate.domain.club.entity.QClub;
66
import com.back.catchmate.domain.game.entity.QGame;
7+
import com.back.catchmate.domain.user.repository.BlockedUserRepository;
78
import com.querydsl.core.BooleanBuilder;
89
import com.querydsl.jpa.impl.JPAQuery;
910
import com.querydsl.jpa.impl.JPAQueryFactory;
@@ -18,9 +19,10 @@
1819
@RequiredArgsConstructor
1920
public class BoardRepositoryImpl implements BoardRepositoryCustom {
2021
private final JPAQueryFactory queryFactory;
22+
private final BlockedUserRepository blockedUserRepository;
2123

2224
@Override
23-
public Page<Board> findFilteredBoards(LocalDate gameDate, Integer maxPerson, List<Long> preferredTeamIdList, Pageable pageable) {
25+
public Page<Board> findFilteredBoards(Long userId, LocalDate gameDate, Integer maxPerson, List<Long> preferredTeamIdList, Pageable pageable) {
2426
QBoard board = QBoard.board;
2527
QGame game = QGame.game;
2628
QClub club = QClub.club;
@@ -48,6 +50,12 @@ public Page<Board> findFilteredBoards(LocalDate gameDate, Integer maxPerson, Lis
4850
builder.and(board.game.gameStartDate.lt(gameDate.plusDays(1).atStartOfDay()));
4951
}
5052

53+
// 차단된 유저의 게시글 제외
54+
List<Long> blockedUserIds = blockedUserRepository.findBlockedUserIdListByUserId(userId);
55+
if (!blockedUserIds.isEmpty()) {
56+
builder.and(board.user.id.notIn(blockedUserIds));
57+
}
58+
5159
// 쿼리 실행
5260
JPAQuery<Board> query = queryFactory
5361
.selectFrom(board)

src/main/java/com/back/catchmate/domain/board/service/BoardServiceImpl.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import com.back.catchmate.domain.game.dto.GameRequest.CreateGameRequest;
2424
import com.back.catchmate.domain.game.entity.Game;
2525
import com.back.catchmate.domain.game.repository.GameRepository;
26-
import com.back.catchmate.domain.notification.service.FCMService;
2726
import com.back.catchmate.domain.user.entity.User;
27+
import com.back.catchmate.domain.user.repository.BlockedUserRepository;
2828
import com.back.catchmate.domain.user.repository.UserRepository;
2929
import com.back.catchmate.global.error.ErrorCode;
3030
import com.back.catchmate.global.error.exception.BaseException;
@@ -45,7 +45,6 @@
4545
@RequiredArgsConstructor
4646
public class BoardServiceImpl implements BoardService {
4747
private static final Long DEFAULT_CLUB_ID = 0L;
48-
private final FCMService fcmService;
4948
private final BoardRepository boardRepository;
5049
private final GameRepository gameRepository;
5150
private final ClubRepository clubRepository;
@@ -54,6 +53,7 @@ public class BoardServiceImpl implements BoardService {
5453
private final EnrollRepository enrollRepository;
5554
private final ChatRoomRepository chatRoomRepository;
5655
private final UserChatRoomRepository userChatRoomRepository;
56+
private final BlockedUserRepository blockedUserRepository;
5757
private final BoardConverter boardConverter;
5858
private final GameConverter gameConverter;
5959
private final ChatRoomConverter chatRoomConverter;
@@ -174,6 +174,10 @@ public BoardInfo getBoard(Long userId, Long boardId) {
174174
Board board = boardRepository.findByIdAndDeletedAtIsNullAndIsCompleted(boardId)
175175
.orElseThrow(() -> new BaseException(ErrorCode.BOARD_NOT_FOUND));
176176

177+
if (isUserBlocked(user.getId(), board.getUser().getId())) {
178+
throw new BaseException(ErrorCode.BLOCKED_USER_BOARD);
179+
}
180+
177181
boolean isBookMarked = bookMarkRepository.existsByUserIdAndBoardIdAndDeletedAtIsNull(user.getId(), board.getId());
178182

179183
// 타 유저 게시물 여부 확인
@@ -203,7 +207,7 @@ public PagedBoardInfo getBoardList(Long userId, LocalDate gameStartDate, Integer
203207
User user = userRepository.findById(userId)
204208
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));
205209

206-
Page<Board> boardList = boardRepository.findFilteredBoards(gameStartDate, maxPerson, preferredTeamIdList, pageable);
210+
Page<Board> boardList = boardRepository.findFilteredBoards(user.getId(), gameStartDate, maxPerson, preferredTeamIdList, pageable);
207211
return boardConverter.toPagedBoardInfoFromBoardList(boardList);
208212
}
209213

@@ -216,10 +220,18 @@ public PagedBoardInfo getBoardListByUserId(Long loginUserId, Long userId, Pageab
216220
User user = userRepository.findById(userId)
217221
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));
218222

223+
if (isUserBlocked(loginUserId, userId)) {
224+
throw new BaseException(ErrorCode.BLOCKED_USER_BOARD_LIST);
225+
}
226+
219227
Page<Board> boardList = boardRepository.findAllByUserIdAndDeletedAtIsNullAndIsCompletedIsTrue(user.getId(), pageable);
220228
return boardConverter.toPagedBoardInfoFromBoardList(boardList);
221229
}
222230

231+
private boolean isUserBlocked(Long blockerId, Long blockedId) {
232+
return blockedUserRepository.existsByBlockerIdAndBlockedIdAndDeletedAtIsNull(blockerId, blockedId);
233+
}
234+
223235
@Override
224236
@Transactional(readOnly = true)
225237
public TempBoardInfo getTempBoard(Long userId) {

src/main/java/com/back/catchmate/domain/chat/controller/ChatRoomController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
import org.springframework.data.domain.Pageable;
1414
import org.springframework.data.domain.Sort;
1515
import org.springframework.data.web.PageableDefault;
16-
import org.springframework.web.bind.annotation.*;
16+
import org.springframework.web.bind.annotation.DeleteMapping;
17+
import org.springframework.web.bind.annotation.GetMapping;
18+
import org.springframework.web.bind.annotation.PatchMapping;
19+
import org.springframework.web.bind.annotation.PathVariable;
20+
import org.springframework.web.bind.annotation.RequestMapping;
21+
import org.springframework.web.bind.annotation.RequestParam;
22+
import org.springframework.web.bind.annotation.RestController;
1723
import org.springframework.web.multipart.MultipartFile;
1824

1925
import java.io.IOException;

src/main/java/com/back/catchmate/domain/chat/entity/UserChatRoom.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import lombok.AllArgsConstructor;
1616
import lombok.Builder;
1717
import lombok.Getter;
18-
import lombok.NoArgsConstructor;;
18+
import lombok.NoArgsConstructor;
1919
import java.time.LocalDateTime;
2020

2121
@Entity

src/main/java/com/back/catchmate/domain/chat/service/UserChatRoomServiceImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.back.catchmate.domain.chat.converter.UserChatRoomConverter;
44
import com.back.catchmate.domain.chat.entity.UserChatRoom;
55
import com.back.catchmate.domain.chat.repository.UserChatRoomRepository;
6-
import com.back.catchmate.domain.user.dto.UserResponse;
76
import com.back.catchmate.domain.user.dto.UserResponse.UserInfoList;
87
import com.back.catchmate.global.error.ErrorCode;
98
import com.back.catchmate.global.error.exception.BaseException;

src/main/java/com/back/catchmate/domain/user/controller/UserController.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,31 @@
22

33
import com.back.catchmate.domain.user.dto.UserRequest;
44
import com.back.catchmate.domain.user.dto.UserResponse.LoginInfo;
5+
import com.back.catchmate.domain.user.dto.UserResponse.PagedUserInfo;
56
import com.back.catchmate.domain.user.dto.UserResponse.UpdateAlarmInfo;
67
import com.back.catchmate.domain.user.dto.UserResponse.UserInfo;
78
import com.back.catchmate.domain.user.entity.AlarmType;
9+
import com.back.catchmate.domain.user.service.BlockedUserService;
810
import com.back.catchmate.domain.user.service.UserService;
911
import com.back.catchmate.global.dto.StateResponse;
1012
import com.back.catchmate.global.jwt.JwtValidation;
1113
import io.swagger.v3.oas.annotations.Operation;
14+
import io.swagger.v3.oas.annotations.Parameter;
1215
import io.swagger.v3.oas.annotations.tags.Tag;
1316
import jakarta.validation.Valid;
1417
import lombok.RequiredArgsConstructor;
18+
import org.springframework.data.domain.Pageable;
19+
import org.springframework.data.domain.Sort;
20+
import org.springframework.data.web.PageableDefault;
21+
import org.springframework.web.bind.annotation.DeleteMapping;
1522
import org.springframework.web.bind.annotation.GetMapping;
1623
import org.springframework.web.bind.annotation.PatchMapping;
1724
import org.springframework.web.bind.annotation.PathVariable;
1825
import org.springframework.web.bind.annotation.PostMapping;
19-
import org.springframework.web.bind.annotation.RequestBody;
2026
import org.springframework.web.bind.annotation.RequestMapping;
2127
import org.springframework.web.bind.annotation.RequestParam;
2228
import org.springframework.web.bind.annotation.RequestPart;
29+
import org.springframework.web.bind.annotation.RequestBody;
2330
import org.springframework.web.bind.annotation.RestController;
2431
import org.springframework.web.multipart.MultipartFile;
2532

@@ -31,6 +38,7 @@
3138
@RequiredArgsConstructor
3239
public class UserController {
3340
private final UserService userService;
41+
private final BlockedUserService blockedUserService;
3442

3543
@PostMapping("/additional-info")
3644
@Operation(summary = "추가 정보 입력 API", description = "최초 로그인시, 추가 정보를 입력하는 API 입니다.")
@@ -53,9 +61,9 @@ public UserInfo getOtherUserProfile(@JwtValidation Long userId,
5361

5462
@PatchMapping("/profile")
5563
@Operation(summary = "나의 정보 수정 API", description = "마이페이지에서 나의 정보를 수정하는 API 입니다.")
56-
public StateResponse updateProfile(@RequestPart("request") @Valid UserRequest.UserProfileUpdateRequest request,
57-
@RequestPart(value = "profileImage", required = false) MultipartFile profileImage,
58-
@JwtValidation Long userId) throws IOException {
64+
public StateResponse updateProfile(@JwtValidation Long userId,
65+
@RequestPart("request") @Valid UserRequest.UserProfileUpdateRequest request,
66+
@RequestPart(value = "profileImage", required = false) MultipartFile profileImage) throws IOException {
5967
return userService.updateProfile(request, profileImage, userId);
6068
}
6169

@@ -66,4 +74,26 @@ public UpdateAlarmInfo updateAlarm(@JwtValidation Long userId,
6674
@RequestParam("isEnabled") char isEnabled) {
6775
return userService.updateAlarm(userId, alarmType, isEnabled);
6876
}
77+
78+
@PostMapping("/block/{blockedUserId}")
79+
@Operation(summary = "유저 차단 API", description = "특정 유저를 차단하는 API 입니다.")
80+
public StateResponse blockUser(@JwtValidation Long userId,
81+
@PathVariable Long blockedUserId) {
82+
return blockedUserService.blockUser(userId, blockedUserId);
83+
}
84+
85+
@DeleteMapping("/block/{blockedUserId}")
86+
@Operation(summary = "유저 차단 해제 API", description = "차단한 유저를 해제하는 API 입니다.")
87+
public StateResponse unblockUser(@JwtValidation Long userId,
88+
@PathVariable Long blockedUserId) {
89+
return blockedUserService.unblockUser(userId, blockedUserId);
90+
}
91+
92+
@GetMapping("/block")
93+
@Operation(summary = "차단한 유저 목록 API", description = "내가 차단한 유저 목록을 조회하는 API 입니다.")
94+
public PagedUserInfo getBlockedUsers(@JwtValidation Long userId,
95+
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
96+
@Parameter(hidden = true) Pageable pageable) {
97+
return blockedUserService.getBlockedUserList(userId, pageable);
98+
}
6999
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.back.catchmate.domain.user.converter;
2+
3+
import com.back.catchmate.domain.user.entity.BlockedUser;
4+
import com.back.catchmate.domain.user.entity.User;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
public class BlockerUserConverter {
9+
public BlockedUser toEntity(User blocker, User blockerUser) {
10+
return BlockedUser.builder()
11+
.blocker(blocker)
12+
.blocked(blockerUser)
13+
.build();
14+
}
15+
}

src/main/java/com/back/catchmate/domain/user/converter/UserConverter.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@
33
import com.back.catchmate.domain.club.converter.ClubConverter;
44
import com.back.catchmate.domain.club.dto.ClubResponse.ClubInfo;
55
import com.back.catchmate.domain.club.entity.Club;
6+
import com.back.catchmate.domain.notification.dto.NotificationResponse;
7+
import com.back.catchmate.domain.notification.entity.Notification;
68
import com.back.catchmate.domain.user.dto.UserRequest;
9+
import com.back.catchmate.domain.user.dto.UserResponse;
710
import com.back.catchmate.domain.user.dto.UserResponse.LoginInfo;
811
import com.back.catchmate.domain.user.dto.UserResponse.UpdateAlarmInfo;
912
import com.back.catchmate.domain.user.dto.UserResponse.UserInfo;
1013
import com.back.catchmate.domain.user.entity.AlarmType;
14+
import com.back.catchmate.domain.user.entity.BlockedUser;
1115
import com.back.catchmate.domain.user.entity.Provider;
1216
import com.back.catchmate.domain.user.entity.User;
1317
import lombok.RequiredArgsConstructor;
18+
import org.springframework.data.domain.Page;
1419
import org.springframework.stereotype.Component;
1520

1621
import java.time.LocalDateTime;
22+
import java.util.List;
23+
import java.util.stream.Collectors;
1724

1825
@Component
1926
@RequiredArgsConstructor
@@ -71,6 +78,20 @@ public UserInfo toUserInfo(User user) {
7178
.build();
7279
}
7380

81+
public UserResponse.PagedUserInfo toPagedUserInfo(Page<BlockedUser> blockedUserList) {
82+
List<UserResponse.UserInfo> blockedUserInfoList = blockedUserList.stream()
83+
.map(blockedUser -> toUserInfo(blockedUser.getBlocked())) // 차단된 유저 정보 변환
84+
.collect(Collectors.toList());
85+
86+
return UserResponse.PagedUserInfo.builder()
87+
.userInfoList(blockedUserInfoList)
88+
.totalPages(blockedUserList.getTotalPages())
89+
.totalElements(blockedUserList.getTotalElements())
90+
.isFirst(blockedUserList.isFirst())
91+
.isLast(blockedUserList.isLast())
92+
.build();
93+
}
94+
7495
public UpdateAlarmInfo toUpdateAlarmInfo(User user, AlarmType alarmType, char isEnabled) {
7596
return UpdateAlarmInfo.builder()
7697
.userId(user.getId())

src/main/java/com/back/catchmate/domain/user/dto/UserResponse.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.back.catchmate.domain.user.dto;
22

33
import com.back.catchmate.domain.club.dto.ClubResponse.ClubInfo;
4+
import com.back.catchmate.domain.notification.dto.NotificationResponse;
45
import com.back.catchmate.domain.user.entity.AlarmType;
56
import lombok.AllArgsConstructor;
67
import lombok.Builder;
@@ -50,6 +51,18 @@ public static class UserInfoList {
5051
private List<UserInfo> userInfoList;
5152
}
5253

54+
@Getter
55+
@Builder
56+
@AllArgsConstructor
57+
@NoArgsConstructor
58+
public static class PagedUserInfo {
59+
private List<UserInfo> userInfoList;
60+
private Integer totalPages;
61+
private Long totalElements;
62+
private Boolean isFirst;
63+
private Boolean isLast;
64+
}
65+
5366
@Getter
5467
@Builder
5568
@AllArgsConstructor

0 commit comments

Comments
 (0)