|
|
@ -7,6 +7,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
package com.example.todoapp.controller; |
|
|
|
package com.example.todoapp.controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.example.todoapp.dto.BuyRequestDTO; |
|
|
|
import com.example.todoapp.dto.DeleteToBuyRequest; |
|
|
|
import com.example.todoapp.dto.DeleteToBuyRequest; |
|
|
|
import com.example.todoapp.dto.ToBuyResponse; |
|
|
|
import com.example.todoapp.dto.ToBuyResponse; |
|
|
|
import com.example.todoapp.dto.ToBuysDTO; |
|
|
|
import com.example.todoapp.dto.ToBuysDTO; |
|
|
@ -47,9 +48,6 @@ public class ToBuysController { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private UserRepository userRepository; |
|
|
|
private UserRepository userRepository; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private StuffsRepository stuffsRepository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 新しい購入アイテムを追加する |
|
|
|
* 新しい購入アイテムを追加する |
|
|
|
* |
|
|
|
* |
|
|
@ -140,19 +138,11 @@ public class ToBuysController { |
|
|
|
public ResponseEntity<Map<String, Boolean>> deleteToBuy( |
|
|
|
public ResponseEntity<Map<String, Boolean>> deleteToBuy( |
|
|
|
@RequestBody DeleteToBuyRequest request, |
|
|
|
@RequestBody DeleteToBuyRequest request, |
|
|
|
Authentication authentication) { |
|
|
|
Authentication authentication) { |
|
|
|
|
|
|
|
|
|
|
|
// 認証されたユーザー名を取得
|
|
|
|
|
|
|
|
String username = authentication.getName(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ユーザー情報を取得
|
|
|
|
int deletedCount = toBuysService.deleteToBuyById(request.getTobuyId()); |
|
|
|
User user = userRepository.findByUsername(username) |
|
|
|
|
|
|
|
.orElseThrow(() -> new UsernameNotFoundException("User not found")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int deletedCount = toBuysService.deleteToBuyByIds(user.getId(), request.getTobuyId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Boolean> response = new HashMap<>(); |
|
|
|
Map<String, Boolean> response = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (deletedCount > 0) { |
|
|
|
if (deletedCount > 0) { |
|
|
|
response.put("result", true); |
|
|
|
response.put("result", true); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -162,12 +152,23 @@ public class ToBuysController { |
|
|
|
return ResponseEntity.ok(response); |
|
|
|
return ResponseEntity.ok(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/{id}") |
|
|
|
/** |
|
|
|
public ResponseEntity<?> buyToBuys( |
|
|
|
* 買うものリストの在庫登録(購入処理) |
|
|
|
|
|
|
|
* 買うものリストから削除し,追加情報を付加して在庫リストに追加 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param request 「買うもの」の情報を含むリクエストボディ |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@PostMapping("/buy") |
|
|
|
|
|
|
|
public ResponseEntity<Map<String, Boolean>> buyToBuys( |
|
|
|
Authentication authentication, |
|
|
|
Authentication authentication, |
|
|
|
@PathVariable("id") ToBuysDTO toBuysDTO) { |
|
|
|
@RequestBody BuyRequestDTO toBuysDTO) { |
|
|
|
|
|
|
|
|
|
|
|
toBuysService.buyToBuys(authentication.getName(), toBuysDTO); |
|
|
|
toBuysService.buyToBuys(authentication.getName(), toBuysDTO); |
|
|
|
return ResponseEntity.ok().build(); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Boolean> response = new HashMap<>(); |
|
|
|
|
|
|
|
response.put("result", true); |
|
|
|
|
|
|
|
return ResponseEntity.ok(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |