|
|
|
@ -171,6 +171,16 @@ public class ToBuysService { |
|
|
|
|
return toBuysRepository.findByUserIdOrderByTobuyIdAsc(user.getId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 指定された購入リストIDに基づいて「数量」を変更する |
|
|
|
|
* |
|
|
|
|
* @param tobuyId 購入リストID |
|
|
|
|
*/ |
|
|
|
|
@Transactional |
|
|
|
|
public int updateToBuysAmountByTobuyId(Long tobuyId, int amount) { |
|
|
|
|
return toBuysRepository.updateAmountByTobuyId(tobuyId, amount); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 指定された購入リストIDに基づいて「買うもの」を削除する |
|
|
|
|
* |
|
|
|
@ -207,9 +217,17 @@ public class ToBuysService { |
|
|
|
|
stock.setBuyDate(dto.getBuyDate()); |
|
|
|
|
stock.setExpDate(dto.getExpDate()); |
|
|
|
|
|
|
|
|
|
// 買うものリストから削除
|
|
|
|
|
// まだ買うべき数量を計算
|
|
|
|
|
int remainAmount = Math.max(tobuy.getAmount() - dto.getAmount(), 0); |
|
|
|
|
System.out.println("remainAmount=" + remainAmount); |
|
|
|
|
|
|
|
|
|
// 買うものリストから削除または数量変更
|
|
|
|
|
System.out.println("tobuy.getTobuyId()=" + tobuy.getTobuyId()); |
|
|
|
|
deleteToBuysByTobuyId(tobuy.getTobuyId()); |
|
|
|
|
if (remainAmount > 0) { |
|
|
|
|
updateToBuysAmountByTobuyId(tobuy.getTobuyId(), remainAmount); |
|
|
|
|
} else { |
|
|
|
|
deleteToBuysByTobuyId(tobuy.getTobuyId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// データベースに保存
|
|
|
|
|
return stocksRepository.save(stock); |
|
|
|
|