From be8519cdf1790faa3a202b62d8ef0f64612d4cae Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 5 Nov 2023 16:10:59 +0100 Subject: [PATCH] Implement dummy catalogue to enable inventory prototype The initializer is partially taken from videoshop. --- .../catalog/CatalogDataInitializer.java | 49 ++++++++++++ .../java/catering/catalog/CatalogDummy.java | 79 +++++++++++++++++++ .../catering/catalog/CatalogDummyType.java | 22 ++++++ .../catering/catalog/CateringCatalog.java | 24 ++++++ 4 files changed, 174 insertions(+) create mode 100644 src/main/java/catering/catalog/CatalogDataInitializer.java create mode 100644 src/main/java/catering/catalog/CatalogDummy.java create mode 100644 src/main/java/catering/catalog/CatalogDummyType.java create mode 100644 src/main/java/catering/catalog/CateringCatalog.java diff --git a/src/main/java/catering/catalog/CatalogDataInitializer.java b/src/main/java/catering/catalog/CatalogDataInitializer.java new file mode 100644 index 0000000..d473750 --- /dev/null +++ b/src/main/java/catering/catalog/CatalogDataInitializer.java @@ -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 . + */ +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))); + } +} diff --git a/src/main/java/catering/catalog/CatalogDummy.java b/src/main/java/catering/catalog/CatalogDummy.java new file mode 100644 index 0000000..28424e3 --- /dev/null +++ b/src/main/java/catering/catalog/CatalogDummy.java @@ -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 . + */ +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 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; + } +} diff --git a/src/main/java/catering/catalog/CatalogDummyType.java b/src/main/java/catering/catalog/CatalogDummyType.java new file mode 100644 index 0000000..26c815c --- /dev/null +++ b/src/main/java/catering/catalog/CatalogDummyType.java @@ -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 . + */ +package catering.catalog; + +public enum CatalogDummyType { + CONSUMABLE, + RENTABLE, +} diff --git a/src/main/java/catering/catalog/CateringCatalog.java b/src/main/java/catering/catalog/CateringCatalog.java new file mode 100644 index 0000000..0231ed5 --- /dev/null +++ b/src/main/java/catering/catalog/CateringCatalog.java @@ -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 . + */ +package catering.catalog; + +import org.salespointframework.catalog.Catalog; +import org.springframework.data.domain.Sort; + +public interface CateringCatalog extends Catalog { + static final Sort DEFAULT_SORT = Sort.sort(CatalogDummy.class).by(CatalogDummy::getId).descending(); +}