|
|
|
@ -69,26 +69,25 @@ public class ToBuysService { |
|
|
|
|
User user = userRepository.findByUsername(username) |
|
|
|
|
.orElseThrow(() -> new RuntimeException("ユーザーが見つかりません: " + username)); |
|
|
|
|
|
|
|
|
|
Stuffs stuffs; |
|
|
|
|
Stuffs stuff; |
|
|
|
|
if (toBuyDTO.getStuff_id() == null) { |
|
|
|
|
// 新しい材料を作成
|
|
|
|
|
stuffs = new Stuffs(); |
|
|
|
|
stuffs.setStuff_name(toBuyDTO.getStuff_name()); |
|
|
|
|
stuffs.setCategory(toBuyDTO.getCategory()); |
|
|
|
|
stuffs = stuffsRepository.save(stuffs); |
|
|
|
|
stuff = new Stuffs(); |
|
|
|
|
stuff.setStuff_name(toBuyDTO.getStuff_name()); |
|
|
|
|
stuff.setCategory(toBuyDTO.getCategory()); |
|
|
|
|
stuff = stuffsRepository.save(stuff); |
|
|
|
|
} else { |
|
|
|
|
// 材料情報を取得
|
|
|
|
|
int stuff_id = toBuyDTO.getStuff_id(); |
|
|
|
|
Optional<Stuffs> optionalStuffs = stuffsRepository.findById(stuff_id); |
|
|
|
|
Optional<Stuffs> optionalStuffs = stuffsRepository.findById(toBuyDTO.getStuff_id()); |
|
|
|
|
if (!optionalStuffs.isPresent()) { |
|
|
|
|
throw new RuntimeException("材料がありません"); |
|
|
|
|
} |
|
|
|
|
stuffs = optionalStuffs.get(); |
|
|
|
|
stuff = optionalStuffs.get(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ToBuys toBuys = new ToBuys(); |
|
|
|
|
toBuys.setUser_id(user); |
|
|
|
|
toBuys.setStuffs(stuffs); |
|
|
|
|
toBuys.setStuff_id(stuff.getStuff_id()); |
|
|
|
|
toBuys.setAmount(toBuyDTO.getAmount()); |
|
|
|
|
toBuys.setStore(toBuyDTO.getShop()); |
|
|
|
|
|
|
|
|
@ -134,7 +133,7 @@ public class ToBuysService { |
|
|
|
|
|
|
|
|
|
ToBuys toBuys = new ToBuys(); |
|
|
|
|
toBuys.setUser_id(user); |
|
|
|
|
toBuys.setStuffs(stuffs); |
|
|
|
|
toBuys.setStuff_id(stuffs.getStuff_id()); |
|
|
|
|
toBuys.setAmount(toBuyDTO.getAmount()); |
|
|
|
|
toBuys.setStore(toBuyDTO.getShop()); |
|
|
|
|
|
|
|
|
|