public Collection<Coupon> getAllPurchasedCoupons() throws CouponSystemException { Collection<Coupon> result = new ArrayList<>(); for (Long couponId : custcouponDBDAO.getAllCouponsByCustomer(customer.getId())) { result.add(coupDBDAO.get(couponId)); } return result; }
public void purchaseCoupon(Coupon c) throws CouponSystemException { if (!(custcouponDBDAO.HasCouponBeenPurchased(c, customer))) { Coupon temp_coupon = coupDBDAO.get(c.getId()); if (temp_coupon.getAmount() == 0) { throw new CouponSystemException("cannot purchase coupon - no more left"); } else { // to do - check that coupon is not expired custcouponDBDAO.createCoupon(customer.getId(), c.getId()); temp_coupon.setAmount(c.getAmount() - 1); coupDBDAO.update(temp_coupon); } } }