Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/main/java/com/Podzilla/analytics/config/DatabaseSeeder.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,37 +96,37 @@ public class DatabaseSeeder implements CommandLineRunner {
@Override
@Transactional
public void run(final String... args) {
System.out.println("Checking if database needs seeding...");
// System.out.println("Checking if database needs seeding...");

if (courierRepository.count() > 0) {
System.out.println("Database already seeded. Skipping.");
return;
}
// if (courierRepository.count() > 0) {
// System.out.println("Database already seeded. Skipping.");
// return;
// }

System.out.println("Seeding database...");
// System.out.println("Seeding database...");

List<Region> regions = seedRegions();
System.out.println("Seeded Regions: " + regions.size());
// List<Region> regions = seedRegions();
// System.out.println("Seeded Regions: " + regions.size());

List<Product> products = seedProducts();
System.out.println("Seeded Products: " + products.size());
// List<Product> products = seedProducts();
// System.out.println("Seeded Products: " + products.size());

List<Courier> couriers = seedCouriers();
System.out.println("Seeded Couriers: " + couriers.size());
// List<Courier> couriers = seedCouriers();
// System.out.println("Seeded Couriers: " + couriers.size());

List<Customer> customers = seedCustomers();
System.out.println("Seeded Customers: " + customers.size());
// List<Customer> customers = seedCustomers();
// System.out.println("Seeded Customers: " + customers.size());

System.out.println("Seeding Orders and SalesLineItems...");
seedOrders(customers, couriers, regions, products);
System.out.println("Seeded Orders: " + orderRepository.count());
// System.out.println("Seeding Orders and SalesLineItems...");
// seedOrders(customers, couriers, regions, products);
// System.out.println("Seeded Orders: " + orderRepository.count());

System.out.println("Seeding Inventory Snapshots...");
seedProductSnapshots(products);
System.out.println("Seeded Product Snapshots: "
+ productSnapshotRepository.count());
// System.out.println("Seeding Inventory Snapshots...");
// seedProductSnapshots(products);
// System.out.println("Seeded Product Snapshots: "
// + productSnapshotRepository.count());

System.out.println("Database seeding finished.");
// System.out.println("Database seeding finished.");
}

private List<Region> seedRegions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void invoke(final OrderDeliveryFailedEvent event) {
MarkOrderAsFailedToDeliverCommand command =
commandFactory.createMarkOrderAsFailedToDeliverCommand(
event.getOrderId(),
event.getCourierId(),
event.getReason(),
event.getTimestamp()
);
command.execute();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/Podzilla/analytics/models/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public class Order {
private BigDecimal courierRating;

@ManyToOne
@JoinColumn(name = "customer_id", nullable = false)
@JoinColumn(name = "customer_id", nullable = true)
private Customer customer;

@ManyToOne
@JoinColumn(name = "courier_id", nullable = true)
private Courier courier;

@ManyToOne
@JoinColumn(name = "region_id", nullable = false)
@JoinColumn(name = "region_id", nullable = true)
private Region region;

@OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ public void markOrderAsFailedToFulfill(
UUID orderUUID = StringToUUIDParser.parseStringToUUID(orderId);
LocalDateTime orderFulfillmentFailedTimestamp = DatetimeFormatter
.convertIntsantToDateTime(timeStamp);
Order order = orderRepository.findById(orderUUID)
.orElseThrow(() -> new RuntimeException(
"Order not found"));
order.setStatus(OrderStatus.FULFILLMENT_FAILED);
order.setFailureReason(reason);
order.setOrderFulfillmentFailedTimestamp(
orderFulfillmentFailedTimestamp);
order.setFinalStatusTimestamp(orderFulfillmentFailedTimestamp);
Order order = Order.builder()
.id(orderUUID)
.status(OrderStatus.FULFILLMENT_FAILED)
.failureReason(reason)
.orderFulfillmentFailedTimestamp(
orderFulfillmentFailedTimestamp)
.finalStatusTimestamp(orderFulfillmentFailedTimestamp)
.build();
orderRepository.save(order);
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
spring.application.name=analytics
server.servlet.context-path=/api

# Database Configuration
spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/analytics_db_dev}
Expand Down