|
|
|
@ -52,8 +52,10 @@ public class ToBuysController { |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
@PostMapping("/add") |
|
|
|
|
public ResponseEntity<String> addToBuys(@Valid @RequestBody ToBuysDTO dto) { |
|
|
|
|
toBuysService.addToBuys(dto); |
|
|
|
|
public ResponseEntity<String> addToBuys( |
|
|
|
|
@Valid @RequestBody ToBuysDTO dto, |
|
|
|
|
Authentication authentication) { |
|
|
|
|
toBuysService.addToBuys(dto, authentication); |
|
|
|
|
return ResponseEntity.ok("Item added to 'To Buys' successfully"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -66,11 +68,10 @@ public class ToBuysController { |
|
|
|
|
@GetMapping("/get") |
|
|
|
|
public ResponseEntity<?> getAllToBuysByUserId(Authentication authentication) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 認証されたユーザー名を取得
|
|
|
|
|
String username = authentication.getName(); |
|
|
|
|
|
|
|
|
|
// ユーザー情報を取得(例: userRepository経由)
|
|
|
|
|
// ユーザー情報を取得
|
|
|
|
|
User user = userRepository.findByUsername(username) |
|
|
|
|
.orElseThrow(() -> new UsernameNotFoundException("User not found")); |
|
|
|
|
|
|
|
|
@ -102,8 +103,18 @@ public class ToBuysController { |
|
|
|
|
* @return 削除が成功した場合にtrueを含むレスポンス |
|
|
|
|
*/ |
|
|
|
|
@DeleteMapping("/delete") |
|
|
|
|
public ResponseEntity<Map<String, Boolean>> deleteToBuy(@RequestBody DeleteToBuyRequest request) { |
|
|
|
|
int deletedCount = toBuysService.deleteToBuyByIds(request.getUser_id(), request.getTobuy_id()); |
|
|
|
|
public ResponseEntity<Map<String, Boolean>> deleteToBuy( |
|
|
|
|
@RequestBody DeleteToBuyRequest request, |
|
|
|
|
Authentication authentication) { |
|
|
|
|
|
|
|
|
|
// 認証されたユーザー名を取得
|
|
|
|
|
String username = authentication.getName(); |
|
|
|
|
|
|
|
|
|
// ユーザー情報を取得
|
|
|
|
|
User user = userRepository.findByUsername(username) |
|
|
|
|
.orElseThrow(() -> new UsernameNotFoundException("User not found")); |
|
|
|
|
|
|
|
|
|
int deletedCount = toBuysService.deleteToBuyByIds(user.getId(), request.getTobuy_id()); |
|
|
|
|
|
|
|
|
|
Map<String, Boolean> response = new HashMap<>(); |
|
|
|
|
|
|
|
|
|