Implement dummy catalogue to enable inventory prototype

The initializer is partially taken from videoshop.
This commit is contained in:
Simon Bruder 2023-11-05 16:10:59 +01:00
parent d2925c1263
commit be8519cdf1
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
4 changed files with 174 additions and 0 deletions

View 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)));
}
}

View 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;
}
}

View 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,
}

View 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();
}