Skip to content

Commit

Permalink
split stock and inventory pages
Browse files Browse the repository at this point in the history
  • Loading branch information
drseveriano committed Nov 11, 2024
1 parent 3a1d78a commit fed47e1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/main/java/context/UserContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package context;

import io.quarkus.security.identity.SecurityIdentity;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;

@RequestScoped
public class UserContext {
@Inject
SecurityIdentity identity;

public String getCurrentUsername() {
return identity != null ? identity.getPrincipal().getName() : "anonymous";
}
}
13 changes: 11 additions & 2 deletions src/main/java/controller/AggregatorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ public class AggregatorController {
private AggregatorService aggregatorService;

@GET
@Path("/inventory")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({Role.ROLE_ADMIN, Role.ROLE_GENERIC, Role.ROLE_READ_ONLY})
public Response getStatisticsCards() {
return Response.ok(aggregatorService.getStatistics()).build();
public Response getStatisticsCardsForInventoryPage() {
return Response.ok(aggregatorService.getStatisticsForInventoryPage()).build();
}

@GET
@Path("/stock")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({Role.ROLE_ADMIN, Role.ROLE_GENERIC, Role.ROLE_READ_ONLY})
public Response getStatisticsCardsForStockPage() {
return Response.ok(aggregatorService.getStatisticsForStockPage()).build();
}

}
4 changes: 1 addition & 3 deletions src/main/java/model/ItemCategory.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import jakarta.persistence.*;
import lombok.*;

import java.io.Serial;
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/service/AggregatorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ public class AggregatorService {
@Inject
private InventoryService inventoryService;

public List<StatisticCard> getStatistics() {
public List<StatisticCard> getStatisticsForInventoryPage() {
return List.of(
createStatisticCard("Inventory Items", getTotalNumberOfItems(), "ri-box-1-fill", "primary", false),
createStatisticCard("Purchase Orders (Pendind Delivery)", getTotalNumberOfPurchaseOrdersPendingDelivery(), "ri-ship-2-line", "info", false),
createStatisticCard("Inventory Price", getInventoryTotalPrice(), "ri-money-euro-circle-line", "info", true),
createStatisticCard("Inventory Alerts", getTotalNumberOfInventoryAlerts(), "ri-alert-line", "error", false)
);
}

public List<StatisticCard> getStatisticsForStockPage() {
return List.of(
createStatisticCard("Inventory Items", getTotalNumberOfItems(), "ri-box-1-fill", "primary", false),
createStatisticCard("Stock (Beer) Items", getTotalNumberOfFinishedProducts(), "ri-beer-line", "success", false),
createStatisticCard("Purchase Orders (Pendind Delivery)", getTotalNumberOfPurchaseOrdersPendingDelivery(), "ri-ship-2-line", "info", false),
createStatisticCard("Inventory Alerts", getTotalNumberOfInventoryAlerts(), "ri-alert-line", "error", false),
createStatisticCard("Inventory Price", getInventoryTotalPrice(), "ri-money-euro-circle-line", "info", true),
createStatisticCard("Stock Price", getStockPrice(), "ri-money-euro-circle-line", "info", true),
createStatisticCard("Potential Profit", getPotentialProfit(), "ri-money-euro-circle-line", "warning", true)
createStatisticCard("Potential Profit", getPotentialProfit(), "ri-money-euro-circle-line", "warning", true),
createStatisticCard("Stock Alerts", getTotalNumberOfInventoryAlerts(), "ri-alert-line", "error", false)
);
}

Expand Down

0 comments on commit fed47e1

Please sign in to comment.