mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Fully adapt catalog to salespoint
Co-authored-by: Simon Bruder <simon.bruder@mailbox.tu-dresden.de>
This commit is contained in:
parent
0119b1cfa0
commit
a4099f1de0
|
@ -6,6 +6,11 @@ package javax.money {
|
|||
class MonetaryAmount
|
||||
}
|
||||
|
||||
package java.util {
|
||||
class Optional
|
||||
class Set
|
||||
}
|
||||
|
||||
package Salespoint {
|
||||
'https://st.inf.tu-dresden.de/SalesPoint/api//org/salespointframework/catalog/Catalog.html'
|
||||
interface Catalog<T extends Product> {
|
||||
|
@ -33,43 +38,54 @@ package Salespoint {
|
|||
' }
|
||||
}
|
||||
|
||||
package catering.order {
|
||||
enum OrderType
|
||||
}
|
||||
|
||||
package catering.catalog {
|
||||
interface RentableCatalog {
|
||||
|
||||
interface CateringCatalog {
|
||||
+ DEFAULT_SORT : Sort
|
||||
+ findByCategories()
|
||||
+ findRentablesByCategories()
|
||||
+ findConsumablesByCategories()
|
||||
}
|
||||
interface ConsumableCatalog {
|
||||
+ DEFAULT_SORT : Sort
|
||||
}
|
||||
RentableCatalog --|> Catalog
|
||||
ConsumableCatalog --|> Catalog
|
||||
CateringCatalog --|> Catalog
|
||||
|
||||
class Consumable {
|
||||
- promotionPrice : MonetaryAmount
|
||||
- wholesalePrice : MonetaryAmount
|
||||
+ Consumable(name : String, retailPrice : MonetaryAmount, wholesalePrice : MonetaryAmount) : Consumable
|
||||
+ Consumable(name : String, retailPrice : MonetaryAmount, wholesalePrice : MonetaryAmount, promotionPrice : MonetaryAmount) : Consumable
|
||||
+ Consumable(name : String, retailPrice : MonetaryAmount, wholesalePrice : MonetaryAmount, promotionPrice : Optional<MonetaryAmount>, Set<OrderType> categories) : Consumable
|
||||
+ getPrice() : MonetaryAmount
|
||||
+ getRetailPrice() : MonetaryAmount
|
||||
+ setPrice(price : MonetaryAmount) : void
|
||||
+ getPromotionPrice(): MonetaryAmount
|
||||
+ setPromotionPrice(price : MonetaryAmount)
|
||||
+ getWholeSalePrice() : MonetaryAmount
|
||||
+ setWholeSalePrice(price : MonetaryAmount)
|
||||
+ setRetailPrice(price : MonetaryAmount) : void
|
||||
+ getPromotionPrice(): Optional<MonetaryAmount>
|
||||
+ setPromotionPrice(price : Optional<MonetaryAmount>)
|
||||
+ getWholesalePrice() : MonetaryAmount
|
||||
+ setWholesalePrice(price : MonetaryAmount)
|
||||
}
|
||||
Consumable --|> Product
|
||||
Consumable ..> MonetaryAmount
|
||||
Consumable ..> java.util.Optional
|
||||
Consumable ..> java.util.Set
|
||||
Consumable ..> catering.order.OrderType
|
||||
|
||||
class Rentable {
|
||||
+ Rentable(name : String, pricePerHour : MonetaryAmount) : Rentable
|
||||
- wholesalePrice : MonetaryAmount
|
||||
+ Rentable(name : String, pricePerHour : MonetaryAmount, wholesalePrice : MonetaryAmount, Set<OrderType> categories) : Rentable
|
||||
+ getWholesalePrice() : MonetaryAmount
|
||||
+ setWholesalePrice(price : MonetaryAmount)
|
||||
}
|
||||
Rentable --|> Product
|
||||
Rentable ..> java.util.Set
|
||||
Rentable ..> catering.order.OrderType
|
||||
|
||||
class CatalogDataInitalizer {
|
||||
class CatalogDataInitializer {
|
||||
- rentableCatalog : RentableCatalog
|
||||
- consumableCatalog : ConsumableCatalog
|
||||
+ initalize()
|
||||
+ initialize()
|
||||
}
|
||||
CatalogDataInitalizer ..|> DataInitializer
|
||||
CatalogDataInitializer ..|> DataInitializer
|
||||
}
|
||||
|
||||
'#TODO: to determine which Products of a Category to offer I need to retrieve information about availability of e.g. Cooks and ServicePersonel from the <<use>>rs or Rentables from the Inventory'
|
||||
|
|
BIN
src/main/asciidoc/models/design/catalog.svg
(Stored with Git LFS)
BIN
src/main/asciidoc/models/design/catalog.svg
(Stored with Git LFS)
Binary file not shown.
|
@ -17,8 +17,37 @@
|
|||
package catering.catalog;
|
||||
|
||||
import org.salespointframework.catalog.Catalog;
|
||||
import org.salespointframework.catalog.Product;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import catering.order.OrderType;
|
||||
|
||||
public interface CateringCatalog extends Catalog<Product> {
|
||||
static final Sort DEFAULT_SORT = Sort.sort(Product.class).by(Product::getName).ascending();
|
||||
|
||||
/**
|
||||
* Returns all {@link Product}s by type ordered by the given {@link Sort}.
|
||||
*
|
||||
* @param category an element of {@link OrderType}, must not be {@literal null}.
|
||||
* @param sort must not be {@literal null}.
|
||||
* @return the consumables with the given category, never {@literal null}.
|
||||
*/
|
||||
Streamable<Product> findByCategories(OrderType category, Sort sort);
|
||||
|
||||
/**
|
||||
* Returns all {@link Product}s by type ordered by their identifier.
|
||||
*
|
||||
* @param category must not be {@literal null}.
|
||||
* @return the Product with the given category, never {@literal null}.
|
||||
*/
|
||||
default Streamable<Product> findByCategories(@NonNull OrderType category) {
|
||||
return findByCategories(category, DEFAULT_SORT);
|
||||
}
|
||||
|
||||
Streamable<Product> findRentablesByCategories(@NonNull String category);
|
||||
|
||||
Streamable<Product> findConsumablesByCategories(@NonNull String category);
|
||||
|
||||
public interface CateringCatalog extends Catalog<CatalogDummy> {
|
||||
static final Sort DEFAULT_SORT = Sort.sort(CatalogDummy.class).by(CatalogDummy::getId).descending();
|
||||
}
|
||||
|
|
|
@ -1,47 +1,61 @@
|
|||
package catering.catalog;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.money.MonetaryAmount;
|
||||
import com.mysema.commons.lang.Assert;
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
import org.salespointframework.catalog.Product;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
import catering.order.OrderType;
|
||||
|
||||
@Entity
|
||||
class Consumable extends Product {
|
||||
public class Consumable extends Product {
|
||||
private MonetaryAmount wholesalePrice;
|
||||
private MonetaryAmount promotionPrice;
|
||||
public Consumable(String name, MonetaryAmount price, Iterable<String> categories) {
|
||||
|
||||
@SuppressWarnings({ "deprecation" })
|
||||
public Consumable() {
|
||||
}
|
||||
|
||||
public Consumable(String name, MonetaryAmount price, MonetaryAmount wholesalePrice,
|
||||
Optional<MonetaryAmount> promotionPrice, Set<OrderType> categories) {
|
||||
super(name, price);
|
||||
Assert.notNull(price, "Price must not be null!");
|
||||
// for (String category : categories) {
|
||||
// this.addCategory(category);
|
||||
// }
|
||||
categories.forEach(this::addCategory);
|
||||
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() {
|
||||
MonetaryAmount normal_price = super.getPrice();
|
||||
return normal_price.isGreaterThan(promotionPrice) ? promotionPrice : normal_price;
|
||||
return getPromotionPrice().orElseGet(super::getPrice);
|
||||
}
|
||||
@NonNull MonetaryAmount getRetailPrice() {
|
||||
|
||||
public @NonNull MonetaryAmount getRetailPrice() {
|
||||
return super.getPrice();
|
||||
}
|
||||
@NonNull MonetaryAmount getPromotionPrice() {
|
||||
return promotionPrice;
|
||||
|
||||
public @NonNull Optional<MonetaryAmount> getPromotionPrice() {
|
||||
return Optional.ofNullable(promotionPrice);
|
||||
}
|
||||
@NonNull MonetaryAmount getWholesalePrice() {
|
||||
|
||||
public @NonNull MonetaryAmount getWholesalePrice() {
|
||||
return wholesalePrice;
|
||||
}
|
||||
|
||||
public void setPromotionPrice(MonetaryAmount price) {
|
||||
Assert.notNull(price, "promotionPrice must not be null!");
|
||||
promotionPrice = price;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,21 +1,44 @@
|
|||
package catering.catalog;
|
||||
|
||||
import com.mysema.commons.lang.Assert;
|
||||
import jakarta.persistence.Entity;
|
||||
import org.salespointframework.catalog.Product;
|
||||
import org.springframework.lang.NonNull;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.money.MonetaryAmount;
|
||||
|
||||
import org.salespointframework.catalog.Product;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import catering.order.OrderType;
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
@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);
|
||||
public class Rentable extends Product {
|
||||
|
||||
private MonetaryAmount wholesalePrice;
|
||||
|
||||
@SuppressWarnings({ "deprecation" })
|
||||
public Rentable() {
|
||||
}
|
||||
|
||||
public Rentable(String name, MonetaryAmount pricePerHour, MonetaryAmount wholesalePrice,
|
||||
Set<OrderType> categories) {
|
||||
super(name, pricePerHour);
|
||||
this.wholesalePrice = wholesalePrice;
|
||||
Assert.notNull(pricePerHour, "pricePerHour must not be null!");
|
||||
Assert.notNull(wholesalePrice, "wholesalePrice must not be null!");
|
||||
categories.stream().map(OrderType::toString).forEach(this::addCategory);
|
||||
}
|
||||
|
||||
public @NonNull MonetaryAmount getWholesalePrice() {
|
||||
return wholesalePrice;
|
||||
}
|
||||
|
||||
public void setWholesalePrice(MonetaryAmount price) {
|
||||
Assert.notNull(price, "wholesalePrice must not be null!");
|
||||
wholesalePrice = price;
|
||||
}
|
||||
|
||||
public MonetaryAmount getRetailPrice() {
|
||||
return super.getPrice();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue