From 5925ede2f815efa5b065cd16c18a4538489bdddd Mon Sep 17 00:00:00 2001 From: Theo Reichert Date: Sat, 11 Nov 2023 18:14:30 +0100 Subject: [PATCH] Add classes Consumable and Rentable to package catering.catalog --- .../java/catering/catalog/Consumable.java | 47 +++++++++++++++++++ src/main/java/catering/catalog/Rentable.java | 21 +++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/main/java/catering/catalog/Consumable.java create mode 100644 src/main/java/catering/catalog/Rentable.java diff --git a/src/main/java/catering/catalog/Consumable.java b/src/main/java/catering/catalog/Consumable.java new file mode 100644 index 0000000..04f989d --- /dev/null +++ b/src/main/java/catering/catalog/Consumable.java @@ -0,0 +1,47 @@ +package catering.catalog; + +import javax.money.MonetaryAmount; +import com.mysema.commons.lang.Assert; +import jakarta.persistence.Entity; +import org.salespointframework.catalog.Product; +import org.springframework.lang.NonNull; + +@Entity +class Consumable extends Product { + private MonetaryAmount wholesalePrice; + private MonetaryAmount promotionPrice; + public Consumable(String name, MonetaryAmount price, Iterable categories) { + super(name,price); + Assert.notNull(price, "Price must not be null!"); +// for (String category : categories) { +// this.addCategory(category); +// } + categories.forEach(this::addCategory); + } + + @Override + public @NonNull MonetaryAmount getPrice() { + MonetaryAmount normal_price = super.getPrice(); + return normal_price.isGreaterThan(promotionPrice) ? promotionPrice : normal_price; + } + @NonNull MonetaryAmount getRetailPrice() { + return super.getPrice(); + } + @NonNull MonetaryAmount getPromotionPrice() { + return promotionPrice; + } + @NonNull MonetaryAmount getWholesalePrice() { + return wholesalePrice; + } + + public void setPromotionPrice(MonetaryAmount price) { + Assert.notNull(price, "promotionPrice must not be null!"); + promotionPrice = price; + } + public void setWholesalePrice(MonetaryAmount price) { + Assert.notNull(price, "wholesalePrice must not be null!"); + wholesalePrice = price; + } + + +} diff --git a/src/main/java/catering/catalog/Rentable.java b/src/main/java/catering/catalog/Rentable.java new file mode 100644 index 0000000..6a3cf98 --- /dev/null +++ b/src/main/java/catering/catalog/Rentable.java @@ -0,0 +1,21 @@ +package catering.catalog; + +import com.mysema.commons.lang.Assert; +import jakarta.persistence.Entity; +import org.salespointframework.catalog.Product; +import org.springframework.lang.NonNull; + +import javax.money.MonetaryAmount; + +@Entity +class Rentable extends Product { + public Rentable(String name, javax.money.MonetaryAmount price, Iterable categories) { + super(name,price); + Assert.notNull(price, "Price must not be null!"); +// for (String category : categories) { +// this.addCategory(category); +// } + categories.forEach(this::addCategory); + } + +}