Add classes Consumable and Rentable to package catering.catalog

This commit is contained in:
Theo Reichert 2023-11-11 18:14:30 +01:00 committed by Simon Bruder
parent 2f24b9a80e
commit 5925ede2f8
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
2 changed files with 68 additions and 0 deletions

View file

@ -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<String> 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;
}
}

View file

@ -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<String> categories) {
super(name,price);
Assert.notNull(price, "Price must not be null!");
// for (String category : categories) {
// this.addCategory(category);
// }
categories.forEach(this::addCategory);
}
}