swt23w23/src/main/java/catering/catalog/CatalogDataInitializer.java

67 lines
2.1 KiB
Java
Raw Normal View History

/*
* 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 java.util.Set;
import java.util.Optional;
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;
import catering.order.OrderType;
@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 Consumable(
"Brötchen Vollkorn",
Money.of(1, EURO),
Money.of(0.5, EURO),
Optional.of(Money.of(0.75, EURO)),
Set.of(OrderType.EVENT_CATERING, OrderType.MOBILE_BREAKFAST)));
cateringCatalog.save(new Rentable(
"Kerze Rot",
Money.of(2, EURO),
Money.of(1.5, EURO),
Set.of(OrderType.EVENT_CATERING, OrderType.MOBILE_BREAKFAST)));
cateringCatalog.save(new Rentable(
"Brotschneidemaschine Power X 3000",
Money.of(25, EURO),
Money.of(10000, EURO),
Set.of(OrderType.EVENT_CATERING, OrderType.MOBILE_BREAKFAST)));
}
}