|
|
@ -33,7 +33,7 @@ import java.util.Optional; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 購入リストのサービスクラス |
|
|
|
* 購入リストのサービスクラス |
|
|
|
* <p> |
|
|
|
* <p> |
|
|
|
* このクラスは、購入リスト (to_buys) の登録処理を提供します。 |
|
|
|
* このクラスは、購入リスト (toBuys) の登録処理を提供します。 |
|
|
|
* 材料 (stuffs) の存在確認と新規作成、ユーザー情報の取得などを行います。 |
|
|
|
* 材料 (stuffs) の存在確認と新規作成、ユーザー情報の取得などを行います。 |
|
|
|
* </p> |
|
|
|
* </p> |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -73,7 +73,7 @@ public class ToBuysService { |
|
|
|
if (toBuyDTO.getStuffId() == null) { |
|
|
|
if (toBuyDTO.getStuffId() == null) { |
|
|
|
// 新しい材料を作成
|
|
|
|
// 新しい材料を作成
|
|
|
|
stuff = new Stuffs(); |
|
|
|
stuff = new Stuffs(); |
|
|
|
stuff.setStuffName(toBuyDTO.getStuff_name()); |
|
|
|
stuff.setStuffName(toBuyDTO.getStuffName()); |
|
|
|
stuff.setCategory(toBuyDTO.getCategory()); |
|
|
|
stuff.setCategory(toBuyDTO.getCategory()); |
|
|
|
stuff = stuffsRepository.save(stuff); |
|
|
|
stuff = stuffsRepository.save(stuff); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -112,7 +112,7 @@ public class ToBuysService { |
|
|
|
if (toBuyDTO.getStuffId() == null) { |
|
|
|
if (toBuyDTO.getStuffId() == null) { |
|
|
|
// 新しい材料を作成
|
|
|
|
// 新しい材料を作成
|
|
|
|
stuffs = new Stuffs(); |
|
|
|
stuffs = new Stuffs(); |
|
|
|
stuffs.setStuffName(toBuyDTO.getStuff_name()); |
|
|
|
stuffs.setStuffName(toBuyDTO.getStuffName()); |
|
|
|
stuffs.setCategory(toBuyDTO.getCategory()); |
|
|
|
stuffs.setCategory(toBuyDTO.getCategory()); |
|
|
|
stuffs = stuffsRepository.save(stuffs); |
|
|
|
stuffs = stuffsRepository.save(stuffs); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -124,7 +124,7 @@ public class ToBuysService { |
|
|
|
stuffs = optionalStuffs.get(); |
|
|
|
stuffs = optionalStuffs.get(); |
|
|
|
|
|
|
|
|
|
|
|
//update
|
|
|
|
//update
|
|
|
|
// stuffs.setStuff_name(toBuyDTO.getStuff_name());
|
|
|
|
// stuffs.setStuffName(toBuyDTO.getStuffName());
|
|
|
|
// stuffs.setCategory(toBuyDTO.getCategory());
|
|
|
|
// stuffs.setCategory(toBuyDTO.getCategory());
|
|
|
|
stuffs = stuffsRepository.save(stuffs); |
|
|
|
stuffs = stuffsRepository.save(stuffs); |
|
|
|
} |
|
|
|
} |
|
|
@ -160,7 +160,7 @@ public class ToBuysService { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
public int deleteToBuyByIds(Long userId, int tobuyId) { |
|
|
|
public int deleteToBuyByIds(Long userId, int tobuyId) { |
|
|
|
return toBuysRepository.deleteByUser_IdAndTobuyId(userId, tobuyId); |
|
|
|
return toBuysRepository.deleteByUserIdAndTobuyId(userId, tobuyId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Stocks buyToBuys(String username, ToBuysDTO dto) { |
|
|
|
public Stocks buyToBuys(String username, ToBuysDTO dto) { |
|
|
@ -174,9 +174,9 @@ public class ToBuysService { |
|
|
|
stock.setUser(user); |
|
|
|
stock.setUser(user); |
|
|
|
stock.setAmount(dto.getAmount()); |
|
|
|
stock.setAmount(dto.getAmount()); |
|
|
|
stock.setPrice(dto.getPrice()); |
|
|
|
stock.setPrice(dto.getPrice()); |
|
|
|
stock.setLast_update(dto.getLast_update()); |
|
|
|
stock.setLastUpdate(dto.getLastUpdate()); |
|
|
|
stock.setBuy_date(dto.getBuy_date()); |
|
|
|
stock.setBuyDate(dto.getBuyDate()); |
|
|
|
stock.setExp_date(dto.getExp_date()); |
|
|
|
stock.setExpDate(dto.getExpDate()); |
|
|
|
deleteToBuyByIds(dto.getUserId(), dto.getTobuyId()); |
|
|
|
deleteToBuyByIds(dto.getUserId(), dto.getTobuyId()); |
|
|
|
// データベースに保存
|
|
|
|
// データベースに保存
|
|
|
|
return stocksRepository.save(stock); |
|
|
|
return stocksRepository.save(stock); |
|
|
|