Skip to content

Commit 33013f6

Browse files
[Refactor] BlockList API to simplify request handling
Replaced BlockReq DTO with direct method parameters for better clarity and reduced complexity. Updated controller methods to use `@AuthenticationPrincipal` for user context, streamlining data flow and enhancing maintainability.
1 parent 2e57c6a commit 33013f6

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
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.BlockReq;
76
import org.dfbf.soundlink.domain.blocklist.service.BlockListService;
87
import org.dfbf.soundlink.global.exception.ResponseResult;
8+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
99
import org.springframework.web.bind.annotation.*;
1010

1111
@RestController
@@ -20,25 +20,31 @@ public class BlockListController {
2020
summary = "유저 차단",
2121
description = "특정 유저를 차단합니다."
2222
)
23-
public ResponseResult blockUser(@RequestBody BlockReq blockReq) {
24-
return blockListService.blockUser(blockReq);
23+
public ResponseResult blockUser(
24+
@AuthenticationPrincipal Long userId,
25+
@AuthenticationPrincipal Long blockUserId
26+
) {
27+
return blockListService.blockUser(userId, blockUserId);
2528
}
2629

2730
@DeleteMapping
2831
@Operation(
2932
summary = "유저 차단 해제",
3033
description = "차단한 유저를 해제합니다."
3134
)
32-
public ResponseResult unblockUser(@RequestBody BlockReq blockReq) {
33-
return blockListService.unblockUser(blockReq);
35+
public ResponseResult unblockUser(
36+
@AuthenticationPrincipal Long userId,
37+
@AuthenticationPrincipal Long blockUserId
38+
) {
39+
return blockListService.unblockUser(userId, blockUserId);
3440
}
3541

36-
@GetMapping("/{userId}")
42+
@GetMapping
3743
@Operation(
3844
summary = "차단 목록 조회",
3945
description = "해당 유저의 차단 목록을 가져옵니다."
4046
)
41-
public ResponseResult getBlockList(@PathVariable Long userId) {
47+
public ResponseResult getBlockList(@AuthenticationPrincipal Long userId) {
4248
return blockListService.getBlockListByUserId(userId);
4349
}
4450
}

src/main/java/org/dfbf/soundlink/domain/blocklist/dto/BlockReq.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import jakarta.transaction.Transactional;
44
import lombok.RequiredArgsConstructor;
5-
import org.dfbf.soundlink.domain.blocklist.dto.BlockReq;
65
import org.dfbf.soundlink.domain.blocklist.dto.BlockRes;
76
import org.dfbf.soundlink.domain.blocklist.entity.Blocklist;
87
import org.dfbf.soundlink.domain.blocklist.exception.AlreadyBlockedUser;
@@ -25,18 +24,18 @@ public class BlockListService {
2524
private final UserRepository userRepository;
2625

2726
@Transactional
28-
public ResponseResult blockUser(BlockReq blockReq) {
27+
public ResponseResult blockUser(Long userId, Long blockedUserId) {
2928
try {
30-
User user = userRepository.findById(blockReq.userId())
29+
User user = userRepository.findById(userId)
3130
.orElseThrow(
3231
BlockedUserNotFound::new
3332
);
34-
User blockedUser = userRepository.findById(blockReq.blockedUserId())
33+
User blockedUser = userRepository.findById(blockedUserId)
3534
.orElseThrow(
3635
BlockingUserNotFound::new
3736
);
3837
blockListRepository.findByUserIdAndBlockedUserId(
39-
blockReq.userId(), blockReq.blockedUserId()
38+
userId, blockedUserId
4039
).ifPresent(block -> {
4140
throw new AlreadyBlockedUser();
4241
});
@@ -76,10 +75,10 @@ public ResponseResult blockUser(BlockReq blockReq) {
7675
}
7776

7877
@Transactional
79-
public ResponseResult unblockUser(BlockReq blockReq) {
78+
public ResponseResult unblockUser(Long userId, Long blockedUserId) {
8079
try {
8180
Blocklist block = blockListRepository.findByUserIdAndBlockedUserId(
82-
blockReq.userId(), blockReq.blockedUserId()
81+
userId, blockedUserId
8382
).orElseThrow(BlockingUserNotFound::new);
8483

8584
blockListRepository.delete(block);

0 commit comments

Comments
 (0)