mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-06-04 05:03:42 +02:00
Simon Bruder
bac025fd0a
This finally makes the licensing under AGPL-3.0-or-later explicit after I got the okay from the kickstart source owners. This also checks the REUSE compliance in a pre commit hook, and therefore also in CI.
64 lines
1.7 KiB
Java
64 lines
1.7 KiB
Java
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
// SPDX-FileCopyrightText: 2023 swt23w23
|
|
package catering.catalog;
|
|
|
|
import java.util.Optional;
|
|
import java.util.Set;
|
|
|
|
import javax.money.MonetaryAmount;
|
|
|
|
import org.salespointframework.catalog.Product;
|
|
import org.springframework.lang.NonNull;
|
|
import org.springframework.util.Assert;
|
|
|
|
import jakarta.persistence.Entity;
|
|
|
|
import catering.order.OrderType;
|
|
|
|
@Entity
|
|
public class Consumable extends Product {
|
|
private MonetaryAmount wholesalePrice;
|
|
private MonetaryAmount promotionPrice;
|
|
|
|
@SuppressWarnings({ "deprecation" })
|
|
public Consumable() {
|
|
}
|
|
|
|
public Consumable(String name, MonetaryAmount price, MonetaryAmount wholesalePrice,
|
|
Optional<MonetaryAmount> promotionPrice, Set<OrderType> categories) {
|
|
super(name, price);
|
|
Assert.notNull(wholesalePrice, "wholesalePrice must not be null!");
|
|
Assert.notNull(promotionPrice, "promotionPrice must not be null!");
|
|
this.wholesalePrice = wholesalePrice;
|
|
this.promotionPrice = promotionPrice.orElse(null);
|
|
categories.stream().map(OrderType::toString).forEach(this::addCategory);
|
|
}
|
|
|
|
@Override
|
|
public @NonNull MonetaryAmount getPrice() {
|
|
return getPromotionPrice().orElseGet(super::getPrice);
|
|
}
|
|
|
|
public @NonNull MonetaryAmount getRetailPrice() {
|
|
return super.getPrice();
|
|
}
|
|
|
|
public @NonNull Optional<MonetaryAmount> getPromotionPrice() {
|
|
return Optional.ofNullable(promotionPrice);
|
|
}
|
|
|
|
public @NonNull MonetaryAmount getWholesalePrice() {
|
|
return wholesalePrice;
|
|
}
|
|
|
|
public void setPromotionPrice(Optional<MonetaryAmount> price) {
|
|
promotionPrice = price.orElse(null);
|
|
}
|
|
|
|
public void setWholesalePrice(MonetaryAmount price) {
|
|
Assert.notNull(price, "wholesalePrice must not be null!");
|
|
wholesalePrice = price;
|
|
}
|
|
|
|
}
|