mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Implement dummy catalogue to enable inventory prototype
The initializer is partially taken from videoshop.
This commit is contained in:
parent
3fbacfb64b
commit
3bfab465af
49
src/main/java/catering/catalog/CatalogDataInitializer.java
Normal file
49
src/main/java/catering/catalog/CatalogDataInitializer.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (C) 2023 Simon Bruder
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package catering.catalog;
|
||||
|
||||
import static org.salespointframework.core.Currencies.EURO;
|
||||
|
||||
import org.javamoney.moneta.Money;
|
||||
import org.salespointframework.core.DataInitializer;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@Component
|
||||
@Order(20)
|
||||
class CatalogDataInitializer implements DataInitializer {
|
||||
|
||||
private final CateringCatalog cateringCatalog;
|
||||
|
||||
CatalogDataInitializer(CateringCatalog cateringCatalog) {
|
||||
Assert.notNull(cateringCatalog, "CateringCatalog must not be null!");
|
||||
this.cateringCatalog = cateringCatalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
if (cateringCatalog.findAll().iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
cateringCatalog.save(new CatalogDummy("Brötchen Vollkorn", CatalogDummyType.CONSUMABLE, Money.of(1, EURO), Money.of(0.5, EURO),
|
||||
Money.of(0.75, EURO)));
|
||||
cateringCatalog.save(new CatalogDummy("Kerze Rot", CatalogDummyType.CONSUMABLE, Money.of(2, EURO), Money.of(1.5, EURO)));
|
||||
cateringCatalog.save(new CatalogDummy("Brotschneidemaschine Power X 3000", CatalogDummyType.RENTABLE, Money.of(25, EURO), Money.of(10000, EURO)));
|
||||
}
|
||||
}
|
79
src/main/java/catering/catalog/CatalogDummy.java
Normal file
79
src/main/java/catering/catalog/CatalogDummy.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (C) 2023 Simon Bruder
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package catering.catalog;
|
||||
|
||||
import javax.money.MonetaryAmount;
|
||||
|
||||
import org.salespointframework.catalog.Product;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class CatalogDummy extends Product {
|
||||
MonetaryAmount wholesalePrice;
|
||||
// Optional<MonetaryAmount> promotionPrice;
|
||||
// enterprise java goes brrr
|
||||
MonetaryAmount promotionPrice;
|
||||
CatalogDummyType type;
|
||||
|
||||
// enterprise java goes brrr
|
||||
@SuppressWarnings({ "unused", "deprecation" })
|
||||
private CatalogDummy() {
|
||||
}
|
||||
|
||||
public CatalogDummy(String name, CatalogDummyType type, MonetaryAmount price, MonetaryAmount wholesalePrice,
|
||||
MonetaryAmount promotionPrice) {
|
||||
super(name, price);
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
Assert.notNull(wholesalePrice, "WholesalePricee must not be null!");
|
||||
// PromotionPrice can be null.
|
||||
this.type = type;
|
||||
this.wholesalePrice = wholesalePrice;
|
||||
this.promotionPrice = promotionPrice;
|
||||
}
|
||||
|
||||
public CatalogDummy(String name, CatalogDummyType type, MonetaryAmount price, MonetaryAmount wholesalePrice) {
|
||||
this(name, type, price, wholesalePrice, null);
|
||||
}
|
||||
|
||||
public MonetaryAmount getWholesalePrice() {
|
||||
return wholesalePrice;
|
||||
}
|
||||
|
||||
public void setWholesalePrice(MonetaryAmount wholesalePrice) {
|
||||
Assert.notNull(wholesalePrice, "WholesalePricee must not be null!");
|
||||
this.wholesalePrice = wholesalePrice;
|
||||
}
|
||||
|
||||
public MonetaryAmount getPromotionPrice() {
|
||||
return promotionPrice;
|
||||
}
|
||||
|
||||
public void setPromotionPrice(MonetaryAmount promotionPrice) {
|
||||
this.promotionPrice = promotionPrice;
|
||||
}
|
||||
|
||||
public CatalogDummyType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(CatalogDummyType type) {
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
this.type = type;
|
||||
}
|
||||
}
|
22
src/main/java/catering/catalog/CatalogDummyType.java
Normal file
22
src/main/java/catering/catalog/CatalogDummyType.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (C) 2023 Simon Bruder
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package catering.catalog;
|
||||
|
||||
public enum CatalogDummyType {
|
||||
CONSUMABLE,
|
||||
RENTABLE,
|
||||
}
|
24
src/main/java/catering/catalog/CateringCatalog.java
Normal file
24
src/main/java/catering/catalog/CateringCatalog.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2023 Simon Bruder
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package catering.catalog;
|
||||
|
||||
import org.salespointframework.catalog.Catalog;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
public interface CateringCatalog extends Catalog<CatalogDummy> {
|
||||
static final Sort DEFAULT_SORT = Sort.sort(CatalogDummy.class).by(CatalogDummy::getId).descending();
|
||||
}
|
Loading…
Reference in a new issue