Skip to content

Commit

Permalink
Merge pull request #60 from SorinPopteanu/table
Browse files Browse the repository at this point in the history
FactoryInventoryController
  • Loading branch information
SorinPopteanu authored Apr 26, 2024
2 parents a34a529 + 278de6f commit dd97637
Show file tree
Hide file tree
Showing 11 changed files with 795 additions and 22 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/chainoptim/desktop/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.chainoptim.desktop.features.client.model.ClientOrder;
import org.chainoptim.desktop.features.client.service.*;
import org.chainoptim.desktop.features.factory.model.Factory;
import org.chainoptim.desktop.features.factory.model.FactoryInventoryItem;
import org.chainoptim.desktop.features.factory.service.*;
import org.chainoptim.desktop.features.product.model.Product;
import org.chainoptim.desktop.features.product.service.*;
Expand Down Expand Up @@ -139,6 +140,8 @@ protected void configure() {
bind(FactoryWriteService.class).to(FactoryWriteServiceImpl.class);
bind(FactoryStageService.class).to(FactoryStageServiceImpl.class);
bind(FactoryStageWriteService.class).to(FactoryStageWriteServiceImpl.class);
bind(FactoryInventoryItemService.class).to(FactoryInventoryItemServiceImpl.class);
bind(FactoryInventoryItemWriteService.class).to(FactoryInventoryItemWriteServiceImpl.class);

// - Warehouse
bind(WarehouseService.class).to(WarehouseServiceImpl.class);
Expand Down Expand Up @@ -196,6 +199,9 @@ protected void configure() {
bind(new TypeLiteral<CachingService<PaginatedResults<Factory>>>() {})
.to(new TypeLiteral<CachingServiceImpl<PaginatedResults<Factory>>>() {})
.in(Singleton.class);
bind(new TypeLiteral<CachingService<PaginatedResults<FactoryInventoryItem>>>() {})
.to(new TypeLiteral<CachingServiceImpl<PaginatedResults<FactoryInventoryItem>>>() {})
.in(Singleton.class);
bind(new TypeLiteral<CachingService<PaginatedResults<Warehouse>>>() {})
.to(new TypeLiteral<CachingServiceImpl<PaginatedResults<Warehouse>>>() {})
.in(Singleton.class);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package org.chainoptim.desktop.features.factory.dto;

import org.chainoptim.desktop.features.product.model.Product;
import org.chainoptim.desktop.features.productpipeline.model.Component;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CreateFactoryInventoryItemDTO {

private Integer factoryId;
Expand All @@ -11,4 +18,5 @@ public class CreateFactoryInventoryItemDTO {
private Integer componentId;
private Float quantity;
private Float minimumRequiredQuantity;
private String companyId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class UpdateFactoryInventoryItemDTO {
private Integer componentId;
private Float quantity;
private Float minimumRequiredQuantity;
private String companyId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@
public class FactoryInventoryItem {

private Integer id;

private Integer factoryId;

private String companyId;
private Component component;

private Product product;

private LocalDateTime createdAt;

private LocalDateTime updatedAt;

private Float quantity;

private Float minimumRequiredQuantity;

public FactoryInventoryItem(FactoryInventoryItem nweFactoryInventoryItem) {
this.id = nweFactoryInventoryItem.getId();
this.factoryId = nweFactoryInventoryItem.getFactoryId();
this.companyId = nweFactoryInventoryItem.getCompanyId();
this.component = nweFactoryInventoryItem.getComponent();
this.product = nweFactoryInventoryItem.getProduct();
this.createdAt = nweFactoryInventoryItem.getCreatedAt();
this.updatedAt = nweFactoryInventoryItem.getUpdatedAt();
this.quantity = nweFactoryInventoryItem.getQuantity();
this.minimumRequiredQuantity = nweFactoryInventoryItem.getMinimumRequiredQuantity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public FactoryInventoryItemServiceImpl(CachingService<PaginatedResults<FactoryIn
}

public CompletableFuture<Result<List<FactoryInventoryItem>>> getFactoryInventoryItemsByOrganizationId(Integer organizationId) {
String routeAddress = "http://localhost:8080/api/v1/factory-inventory-items/organization/" + organizationId.toString();
String routeAddress = "http://localhost:8080/api/v1/factory-inventory-items/factory/" + organizationId.toString();

HttpRequest request = requestBuilder.buildReadRequest(routeAddress, tokenManager.getToken());
if (request == null) return requestHandler.getParsingErrorResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import org.chainoptim.desktop.features.factory.model.FactoryInventoryItem;
import org.chainoptim.desktop.shared.httphandling.Result;

import java.util.List;
import java.util.concurrent.CompletableFuture;

public interface FactoryInventoryItemWriteService {

CompletableFuture<Result<FactoryInventoryItem>> createFactoryInventoryItem(CreateFactoryInventoryItemDTO orderDTO);
CompletableFuture<Result<FactoryInventoryItem>> updateFactoryInventoryItem(UpdateFactoryInventoryItemDTO orderDTO);
CompletableFuture<Result<Integer>> deleteFactoryInventoryItem(Integer orderId);
CompletableFuture<Result<List<FactoryInventoryItem>>> createFactoryInventoryItemsInBulk(List<CreateFactoryInventoryItemDTO> itemDTOs);
CompletableFuture<Result<List<FactoryInventoryItem>>> updateFactoryInventoryItemsInBulk(List<UpdateFactoryInventoryItemDTO> itemDTOs);
CompletableFuture<Result<List<Integer>>> deleteFactoryInventoryItemsInBulk(List<Integer> itemIds);
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,58 @@
package org.chainoptim.desktop.features.factory.service;

import org.chainoptim.desktop.core.user.service.TokenManager;
import org.chainoptim.desktop.features.client.dto.CreateClientOrderDTO;
import org.chainoptim.desktop.features.client.model.ClientOrder;
import org.chainoptim.desktop.features.factory.dto.CreateFactoryInventoryItemDTO;
import org.chainoptim.desktop.features.factory.dto.UpdateFactoryInventoryItemDTO;
import org.chainoptim.desktop.features.factory.model.FactoryInventoryItem;
import org.chainoptim.desktop.shared.caching.CachingService;
import org.chainoptim.desktop.shared.httphandling.HttpMethod;
import org.chainoptim.desktop.shared.httphandling.RequestBuilder;
import org.chainoptim.desktop.shared.httphandling.RequestHandler;
import org.chainoptim.desktop.shared.httphandling.Result;
import org.chainoptim.desktop.shared.search.model.PaginatedResults;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.inject.Inject;

import java.net.http.HttpRequest;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public class FactoryInventoryItemWriteServiceImpl implements FactoryInventoryItemWriteService {

private final CachingService<PaginatedResults<FactoryInventoryItem>> cachingService;
private final RequestHandler requestHandler;
private final RequestBuilder requestBuilder;
private final TokenManager tokenManager;

@Inject
public FactoryInventoryItemWriteServiceImpl(RequestHandler requestHandler,
RequestBuilder requestBuilder,
TokenManager tokenManager) {
public FactoryInventoryItemWriteServiceImpl(CachingService<PaginatedResults<FactoryInventoryItem>> cachingService,
RequestHandler requestHandler,
RequestBuilder requestBuilder,
TokenManager tokenManager) {
this.cachingService = cachingService;
this.requestHandler = requestHandler;
this.requestBuilder = requestBuilder;
this.tokenManager = tokenManager;
}

public CompletableFuture<Result<FactoryInventoryItem>> createFactoryInventoryItem(CreateFactoryInventoryItemDTO orderDTO) {
public CompletableFuture<Result<FactoryInventoryItem>> createFactoryInventoryItem(CreateFactoryInventoryItemDTO itemDTO) {
String routeAddress = "http://localhost:8080/api/v1/factory-inventory-items/create";

HttpRequest request = requestBuilder.buildWriteRequest(
HttpMethod.POST, routeAddress, tokenManager.getToken(), orderDTO);
HttpMethod.POST, routeAddress, tokenManager.getToken(), itemDTO);
if (request == null) return requestHandler.getParsingErrorResult();

return requestHandler.sendRequest(request, new TypeReference<FactoryInventoryItem>() {});
}

public CompletableFuture<Result<FactoryInventoryItem>> updateFactoryInventoryItem(UpdateFactoryInventoryItemDTO orderDTO) {
public CompletableFuture<Result<FactoryInventoryItem>> updateFactoryInventoryItem(UpdateFactoryInventoryItemDTO itemDTO) {
String routeAddress = "http://localhost:8080/api/v1/factory-inventory-items/update";

HttpRequest request = requestBuilder.buildWriteRequest(
HttpMethod.PUT, routeAddress, tokenManager.getToken(), orderDTO);
HttpMethod.PUT, routeAddress, tokenManager.getToken(), itemDTO);
if (request == null) return requestHandler.getParsingErrorResult();

return requestHandler.sendRequest(request, new TypeReference<FactoryInventoryItem>() {});
Expand All @@ -59,4 +67,37 @@ public CompletableFuture<Result<Integer>> deleteFactoryInventoryItem(Integer ord

return requestHandler.sendRequest(request, new TypeReference<Integer>() {});
}

public CompletableFuture<Result<List<FactoryInventoryItem>>> createFactoryInventoryItemsInBulk(List<CreateFactoryInventoryItemDTO> itemDTOs) {
String routeAddress = "http://localhost:8080/api/v1/factory-inventory-items/create/bulk";

HttpRequest request = requestBuilder.buildWriteRequest(
HttpMethod.POST, routeAddress, tokenManager.getToken(), itemDTOs);

return requestHandler.sendRequest(request, new TypeReference<List<FactoryInventoryItem>>() {}, orders -> {
cachingService.clear(); // Invalidate cache
});
}

public CompletableFuture<Result<List<FactoryInventoryItem>>> updateFactoryInventoryItemsInBulk(List<UpdateFactoryInventoryItemDTO> itemDTOs) {
String routeAddress = "http://localhost:8080/api/v1/factory-inventory-items/update/bulk";

HttpRequest request = requestBuilder.buildWriteRequest(
HttpMethod.PUT, routeAddress, tokenManager.getToken(), itemDTOs);

return requestHandler.sendRequest(request, new TypeReference<List<FactoryInventoryItem>>() {}, orders -> {
cachingService.clear(); // Invalidate cache
});
}

public CompletableFuture<Result<List<Integer>>> deleteFactoryInventoryItemsInBulk(List<Integer> itemIds) {
String routeAddress = "http://localhost:8080/api/v1/factory-inventory-items/delete/bulk";

HttpRequest request = requestBuilder.buildWriteRequest(
HttpMethod.DELETE, routeAddress, tokenManager.getToken(), itemIds);

return requestHandler.sendRequest(request, new TypeReference<List<Integer>>() {}, ids -> {
cachingService.clear(); // Invalidate cache
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,29 @@ private SearchOptionsConfiguration() {
)
);

private static final SearchOptions FACTORY_INVENTORY_OPTIONS = new SearchOptions(
List.of(
new FilterOption(
new UIItem("Created At Start", "createdAtStart"),
new ArrayList<>(),
FilterType.DATE
),
new FilterOption(
new UIItem("Quantity", "greaterThanQuantity"),
new ArrayList<>(),
FilterType.NUMBER
)
),
Map.of(
"createdAt", "Created At",
"updatedAt", "Updated At",
"quantity", "Quantity"
)
);

private static final Map<Feature, SearchOptions> SEARCH_OPTIONS_MAP = Map.of(
Feature.SUPPLIER_ORDER, SUPPLIER_ORDER_OPTIONS
Feature.SUPPLIER_ORDER, SUPPLIER_ORDER_OPTIONS,
Feature.FACTORY_INVENTORY, FACTORY_INVENTORY_OPTIONS
);

public static SearchOptions getSearchOptions(Feature feature) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane xmlns="http://javafx.com/javafx"
<StackPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.chainoptim.desktop.features.factory.controller.FactoryInventoryController"
prefHeight="400.0" prefWidth="600.0">
fx:controller="org.chainoptim.desktop.features.factory.controller.FactoryInventoryController">

<VBox VBox.vgrow="ALWAYS">
<StackPane fx:id="tableToolbarContainer"/>
<ScrollPane fx:id="factoryInventoryScrollPane" VBox.vgrow="ALWAYS" fitToWidth="true" fitToHeight="true">
<VBox>
<TableView fx:id="tableView" styleClass="table-view">
<columns>
<TableColumn fx:id="selectRowColumn" prefWidth="50"/>
<TableColumn text="Inventory ID" fx:id="inventoryIdColumn" minWidth="120"/>
<TableColumn text="Company ID" fx:id="companyIdColumn" minWidth="150"/>
<TableColumn text="Factory" fx:id="factoryNameColumn" minWidth="150"/>
<TableColumn text="Component" fx:id="componentNameColumn" minWidth="150"/>
<TableColumn text="Product" fx:id="productNameColumn" minWidth="150"/>
<TableColumn text="Quantity" fx:id="quantityColumn" minWidth="150"/>
<TableColumn text="Minimum Required Quantity" fx:id="minimumRequiredQuantityColumn" minWidth="150"/>
<TableColumn text="Created At" fx:id="createdAtColumn" minWidth="200"/>
<TableColumn text="Updated At" fx:id="updatedAtColumn" minWidth="200"/>
</columns>
</TableView>
<StackPane fx:id="pageSelectorContainer"/>
</VBox>
</ScrollPane>
</VBox>

<StackPane fx:id="confirmUpdateDialogContainer" style="-fx-padding: 64px;"/>
<StackPane fx:id="confirmDeleteDialogContainer" style="-fx-padding: 64px;"/>
<StackPane fx:id="confirmCreateDialogContainer" style="-fx-padding: 64px;"/>


</AnchorPane>
</StackPane>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<columns>
<TableColumn fx:id="selectRowColumn" prefWidth="50"/>
<TableColumn text="Order ID" fx:id="orderIdColumn" minWidth="120"/>
<TableColumn text="Company Order ID" fx:id="companyIdColumn" minWidth="150"/>
<TableColumn text="Company ID" fx:id="companyIdColumn" minWidth="150"/>
<TableColumn text="Supplier" fx:id="supplierNameColumn" minWidth="150"/>
<TableColumn text="Component" fx:id="componentNameColumn" minWidth="150"/>
<TableColumn text="Quantity" fx:id="quantityColumn" minWidth="150"/>
Expand Down

0 comments on commit dd97637

Please sign in to comment.