Skip to content

Commit 6cc8380

Browse files
Refactor blocklist functionality to use loginId instead of IDs
Updated blocklist operations to work with user tags (loginId) instead of numeric IDs for better identification. Modified service, repository, and controller layers accordingly, and introduced BlockListReq DTO for request handling. Adjusted endpoint paths for consistency.
1 parent 1975a44 commit 6cc8380

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

src/main/java/org/dfbf/soundlink/domain/blocklist/controller/BlockListController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.swagger.v3.oas.annotations.Operation;
44
import io.swagger.v3.oas.annotations.tags.Tag;
55
import lombok.RequiredArgsConstructor;
6+
import org.dfbf.soundlink.domain.blocklist.dto.BlockListReq;
67
import org.dfbf.soundlink.domain.blocklist.dto.BlockReq;
78
import org.dfbf.soundlink.domain.blocklist.service.BlockListService;
89
import org.dfbf.soundlink.global.exception.ResponseResult;
@@ -25,22 +26,22 @@ public ResponseResult blockUser(
2526
@AuthenticationPrincipal Long userId,
2627
@RequestBody BlockReq req
2728
) {
28-
return blockListService.blockUser(userId, req.blockedUserId());
29+
return blockListService.blockUser(userId, req.tag());
2930
}
3031

31-
@DeleteMapping("/{blockedUserId}")
32+
@DeleteMapping
3233
@Operation(
3334
summary = "유저 차단 해제",
3435
description = "차단한 유저를 해제합니다."
3536
)
3637
public ResponseResult unblockUser(
3738
@AuthenticationPrincipal Long userId,
38-
@PathVariable Long blockedUserId
39+
@RequestBody BlockListReq req
3940
) {
40-
return blockListService.unblockUser(userId, blockedUserId);
41+
return blockListService.unblockUser(userId, req.blocklistId());
4142
}
4243

43-
@GetMapping
44+
@GetMapping("/mypage/blackListSearch")
4445
@Operation(
4546
summary = "차단 목록 조회",
4647
description = "해당 유저의 차단 목록을 가져옵니다."
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.dfbf.soundlink.domain.blocklist.dto;
2+
3+
public record BlockListReq (
4+
Long blocklistId
5+
){
6+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.dfbf.soundlink.domain.blocklist.dto;
22

33
public record BlockReq(
4-
Long blockedUserId
4+
String tag
55
) {
66
}

src/main/java/org/dfbf/soundlink/domain/blocklist/repository/BlockListRepository.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ public interface BlockListRepository extends JpaRepository<Blocklist, Long> {
1919
)
2020
List<Blocklist> findAllByUserId(@Param("userId") Long userId);
2121

22+
@Query(
23+
"SELECT b " +
24+
"FROM Blocklist b " +
25+
"WHERE b.user.userId = :userId " +
26+
"AND b.blockedUser.loginId = :loginId"
27+
)
28+
Optional<Blocklist> findByUserIdAndLoginId(
29+
@Param("userId") Long userId,
30+
@Param("loginId") String loginId
31+
);
32+
2233
@Query(
2334
"SELECT b " +
2435
"FROM Blocklist b " +
@@ -28,5 +39,5 @@ public interface BlockListRepository extends JpaRepository<Blocklist, Long> {
2839
Optional<Blocklist> findByUserIdAndBlockedUserId(
2940
@Param("userId") Long userId,
3041
@Param("blockedUserId") Long blockedUserId
31-
);
42+
);
3243
}

src/main/java/org/dfbf/soundlink/domain/blocklist/service/BlockListService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ public class BlockListService {
2424
private final UserRepository userRepository;
2525

2626
@Transactional
27-
public ResponseResult blockUser(Long userId, Long blockedUserId) {
27+
public ResponseResult blockUser(Long userId, String tag) {
2828
try {
2929
User user = userRepository.findById(userId)
3030
.orElseThrow(
3131
BlockedUserNotFound::new
3232
);
33-
User blockedUser = userRepository.findById(blockedUserId)
33+
User blockedUser = userRepository.findByLoginId(tag)
3434
.orElseThrow(
3535
BlockingUserNotFound::new
3636
);
37-
blockListRepository.findByUserIdAndBlockedUserId(
38-
userId, blockedUserId
37+
blockListRepository.findByUserIdAndLoginId(
38+
userId, tag
3939
).ifPresent(block -> {
4040
throw new AlreadyBlockedUser();
4141
});

0 commit comments

Comments
 (0)