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
|
class MonetaryAmount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
package java.util {
|
||||||
|
class Optional
|
||||||
|
class Set
|
||||||
|
}
|
||||||
|
|
||||||
package Salespoint {
|
package Salespoint {
|
||||||
'https://st.inf.tu-dresden.de/SalesPoint/api//org/salespointframework/catalog/Catalog.html'
|
'https://st.inf.tu-dresden.de/SalesPoint/api//org/salespointframework/catalog/Catalog.html'
|
||||||
interface Catalog<T extends Product> {
|
interface Catalog<T extends Product> {
|
||||||
|
@ -33,43 +38,54 @@ package Salespoint {
|
||||||
' }
|
' }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
package catering.order {
|
||||||
|
enum OrderType
|
||||||
|
}
|
||||||
|
|
||||||
package catering.catalog {
|
package catering.catalog {
|
||||||
interface RentableCatalog {
|
|
||||||
|
interface CateringCatalog {
|
||||||
+ DEFAULT_SORT : Sort
|
+ DEFAULT_SORT : Sort
|
||||||
|
+ findByCategories()
|
||||||
|
+ findRentablesByCategories()
|
||||||
|
+ findConsumablesByCategories()
|
||||||
}
|
}
|
||||||
interface ConsumableCatalog {
|
CateringCatalog --|> Catalog
|
||||||
+ DEFAULT_SORT : Sort
|
|
||||||
}
|
|
||||||
RentableCatalog --|> Catalog
|
|
||||||
ConsumableCatalog --|> Catalog
|
|
||||||
|
|
||||||
class Consumable {
|
class Consumable {
|
||||||
- promotionPrice : MonetaryAmount
|
- promotionPrice : MonetaryAmount
|
||||||
- wholesalePrice : MonetaryAmount
|
- wholesalePrice : MonetaryAmount
|
||||||
+ Consumable(name : String, retailPrice : MonetaryAmount, wholesalePrice : MonetaryAmount) : Consumable
|
+ Consumable(name : String, retailPrice : MonetaryAmount, wholesalePrice : MonetaryAmount, promotionPrice : Optional<MonetaryAmount>, Set<OrderType> categories) : Consumable
|
||||||
+ Consumable(name : String, retailPrice : MonetaryAmount, wholesalePrice : MonetaryAmount, promotionPrice : MonetaryAmount) : Consumable
|
|
||||||
+ getPrice() : MonetaryAmount
|
+ getPrice() : MonetaryAmount
|
||||||
+ getRetailPrice() : MonetaryAmount
|
+ getRetailPrice() : MonetaryAmount
|
||||||
+ setPrice(price : MonetaryAmount) : void
|
+ setRetailPrice(price : MonetaryAmount) : void
|
||||||
+ getPromotionPrice(): MonetaryAmount
|
+ getPromotionPrice(): Optional<MonetaryAmount>
|
||||||
+ setPromotionPrice(price : MonetaryAmount)
|
+ setPromotionPrice(price : Optional<MonetaryAmount>)
|
||||||
+ getWholeSalePrice() : MonetaryAmount
|
+ getWholesalePrice() : MonetaryAmount
|
||||||
+ setWholeSalePrice(price : MonetaryAmount)
|
+ setWholesalePrice(price : MonetaryAmount)
|
||||||
}
|
}
|
||||||
Consumable --|> Product
|
Consumable --|> Product
|
||||||
Consumable ..> MonetaryAmount
|
Consumable ..> MonetaryAmount
|
||||||
|
Consumable ..> java.util.Optional
|
||||||
|
Consumable ..> java.util.Set
|
||||||
|
Consumable ..> catering.order.OrderType
|
||||||
|
|
||||||
class Rentable {
|
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 --|> Product
|
||||||
|
Rentable ..> java.util.Set
|
||||||
|
Rentable ..> catering.order.OrderType
|
||||||
|
|
||||||
class CatalogDataInitalizer {
|
class CatalogDataInitializer {
|
||||||
- rentableCatalog : RentableCatalog
|
- rentableCatalog : RentableCatalog
|
||||||
- consumableCatalog : ConsumableCatalog
|
- 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'
|
'#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;
|
package catering.catalog;
|
||||||
|
|
||||||
import org.salespointframework.catalog.Catalog;
|
import org.salespointframework.catalog.Catalog;
|
||||||
|
import org.salespointframework.catalog.Product;
|
||||||
import org.springframework.data.domain.Sort;
|
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;
|
package catering.catalog;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.money.MonetaryAmount;
|
import javax.money.MonetaryAmount;
|
||||||
import com.mysema.commons.lang.Assert;
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import org.salespointframework.catalog.Product;
|
import org.salespointframework.catalog.Product;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
|
||||||
|
import catering.order.OrderType;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
class Consumable extends Product {
|
public class Consumable extends Product {
|
||||||
private MonetaryAmount wholesalePrice;
|
private MonetaryAmount wholesalePrice;
|
||||||
private MonetaryAmount promotionPrice;
|
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);
|
super(name, price);
|
||||||
Assert.notNull(price, "Price must not be null!");
|
Assert.notNull(wholesalePrice, "wholesalePrice must not be null!");
|
||||||
// for (String category : categories) {
|
Assert.notNull(promotionPrice, "promotionPrice must not be null!");
|
||||||
// this.addCategory(category);
|
this.wholesalePrice = wholesalePrice;
|
||||||
// }
|
this.promotionPrice = promotionPrice.orElse(null);
|
||||||
categories.forEach(this::addCategory);
|
categories.stream().map(OrderType::toString).forEach(this::addCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull MonetaryAmount getPrice() {
|
public @NonNull MonetaryAmount getPrice() {
|
||||||
MonetaryAmount normal_price = super.getPrice();
|
return getPromotionPrice().orElseGet(super::getPrice);
|
||||||
return normal_price.isGreaterThan(promotionPrice) ? promotionPrice : normal_price;
|
|
||||||
}
|
}
|
||||||
@NonNull MonetaryAmount getRetailPrice() {
|
|
||||||
|
public @NonNull MonetaryAmount getRetailPrice() {
|
||||||
return super.getPrice();
|
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;
|
return wholesalePrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPromotionPrice(MonetaryAmount price) {
|
public void setPromotionPrice(Optional<MonetaryAmount> price) {
|
||||||
Assert.notNull(price, "promotionPrice must not be null!");
|
promotionPrice = price.orElse(null);
|
||||||
promotionPrice = price;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWholesalePrice(MonetaryAmount price) {
|
public void setWholesalePrice(MonetaryAmount price) {
|
||||||
Assert.notNull(price, "wholesalePrice must not be null!");
|
Assert.notNull(price, "wholesalePrice must not be null!");
|
||||||
wholesalePrice = price;
|
wholesalePrice = price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,44 @@
|
||||||
package catering.catalog;
|
package catering.catalog;
|
||||||
|
|
||||||
import com.mysema.commons.lang.Assert;
|
import java.util.Set;
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import org.salespointframework.catalog.Product;
|
|
||||||
import org.springframework.lang.NonNull;
|
|
||||||
|
|
||||||
import javax.money.MonetaryAmount;
|
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
|
@Entity
|
||||||
class Rentable extends Product {
|
public class Rentable extends Product {
|
||||||
public Rentable(String name, javax.money.MonetaryAmount price, Iterable<String> categories) {
|
|
||||||
super(name,price);
|
private MonetaryAmount wholesalePrice;
|
||||||
Assert.notNull(price, "Price must not be null!");
|
|
||||||
// for (String category : categories) {
|
@SuppressWarnings({ "deprecation" })
|
||||||
// this.addCategory(category);
|
public Rentable() {
|
||||||
// }
|
|
||||||
categories.forEach(this::addCategory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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