Fix desktop ProductSupplier to use composite keys
- Remove id field from ProductSupplierResponse - Rename supplierPrice to cost in ProductSupplierResponse and ProductSupplierRequest - Update ProductSupplierApi to use composite keys (productId, supplierId) for update and delete - Update ProductSupplierController delete logic to iterate and delete with composite keys - Update ProductSupplierController mapping to use getCost() instead of getSupplierPrice() - Update ProductSupplierDialogController to pass both productId and supplierId to update - Update ProductSupplierDialogController to use setCost() instead of setSupplierPrice() - Remove unused selectedId field from ProductSupplierDialogController
This commit is contained in:
@@ -8,6 +8,9 @@ public class AdoptionRequest {
|
||||
private LocalDate adoptionDate;
|
||||
private String adoptionStatus;
|
||||
|
||||
public AdoptionRequest() {
|
||||
}
|
||||
|
||||
public Long getPetId() {
|
||||
return petId;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ public class AdoptionResponse {
|
||||
private LocalDate adoptionDate;
|
||||
private String adoptionStatus;
|
||||
|
||||
public AdoptionResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ public class DailySales {
|
||||
private LocalDate date;
|
||||
private BigDecimal totalSales;
|
||||
|
||||
public DailySales() {
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ public class DashboardResponse {
|
||||
private List<DailySales> dailySales;
|
||||
private List<TopProduct> topProducts;
|
||||
|
||||
public DashboardResponse() {
|
||||
}
|
||||
|
||||
public BigDecimal getTotalRevenue() {
|
||||
return totalRevenue;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ public class TopProduct {
|
||||
private Integer quantitySold;
|
||||
private BigDecimal totalRevenue;
|
||||
|
||||
public TopProduct() {
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ public class AppointmentRequest {
|
||||
private LocalTime appointmentTime;
|
||||
private String appointmentStatus;
|
||||
|
||||
public AppointmentRequest() {
|
||||
}
|
||||
|
||||
public List<Long> getPetIds() {
|
||||
return petIds;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ public class AppointmentResponse {
|
||||
private LocalTime appointmentTime;
|
||||
private String appointmentStatus;
|
||||
|
||||
public AppointmentResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ public class LoginResponse {
|
||||
private String username;
|
||||
private String role;
|
||||
|
||||
public LoginResponse() {
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ public class UserInfoResponse {
|
||||
private String username;
|
||||
private String role;
|
||||
|
||||
public UserInfoResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ public class DropdownOption {
|
||||
private Long id;
|
||||
private String label;
|
||||
|
||||
public DropdownOption() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,27 @@
|
||||
package org.example.petshopdesktop.api.dto.common;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class PageResponse<T> {
|
||||
private List<T> content;
|
||||
|
||||
@JsonProperty("number")
|
||||
private int pageNumber;
|
||||
|
||||
@JsonProperty("size")
|
||||
private int pageSize;
|
||||
|
||||
private long totalElements;
|
||||
private int totalPages;
|
||||
private boolean last;
|
||||
|
||||
public PageResponse() {
|
||||
}
|
||||
|
||||
public List<T> getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ public class InventoryRequest {
|
||||
private Integer stockQuantity;
|
||||
private Integer reorderLevel;
|
||||
|
||||
public InventoryRequest() {
|
||||
}
|
||||
|
||||
public Long getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ public class InventoryResponse {
|
||||
private Integer stockQuantity;
|
||||
private Integer reorderLevel;
|
||||
|
||||
public InventoryResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ public class PetRequest {
|
||||
private BigDecimal price;
|
||||
private String petStatus;
|
||||
|
||||
public PetRequest() {
|
||||
}
|
||||
|
||||
public String getPetName() {
|
||||
return petName;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ public class PetResponse {
|
||||
private BigDecimal price;
|
||||
private String petStatus;
|
||||
|
||||
public PetResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ public class ProductRequest {
|
||||
private BigDecimal price;
|
||||
private String description;
|
||||
|
||||
public ProductRequest() {
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ public class ProductResponse {
|
||||
private BigDecimal price;
|
||||
private String description;
|
||||
|
||||
public ProductResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ import java.math.BigDecimal;
|
||||
public class ProductSupplierRequest {
|
||||
private Long productId;
|
||||
private Long supplierId;
|
||||
private BigDecimal supplierPrice;
|
||||
private BigDecimal cost;
|
||||
|
||||
public ProductSupplierRequest() {
|
||||
}
|
||||
|
||||
public Long getProductId() {
|
||||
return productId;
|
||||
@@ -23,11 +26,11 @@ public class ProductSupplierRequest {
|
||||
this.supplierId = supplierId;
|
||||
}
|
||||
|
||||
public BigDecimal getSupplierPrice() {
|
||||
return supplierPrice;
|
||||
public BigDecimal getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
public void setSupplierPrice(BigDecimal supplierPrice) {
|
||||
this.supplierPrice = supplierPrice;
|
||||
public void setCost(BigDecimal cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,13 @@ package org.example.petshopdesktop.api.dto.productsupplier;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class ProductSupplierResponse {
|
||||
private Long id;
|
||||
private Long productId;
|
||||
private Long supplierId;
|
||||
private String productName;
|
||||
private String supplierName;
|
||||
private BigDecimal supplierPrice;
|
||||
private BigDecimal cost;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
public ProductSupplierResponse() {
|
||||
}
|
||||
|
||||
public Long getProductId() {
|
||||
@@ -50,11 +44,11 @@ public class ProductSupplierResponse {
|
||||
this.supplierName = supplierName;
|
||||
}
|
||||
|
||||
public BigDecimal getSupplierPrice() {
|
||||
return supplierPrice;
|
||||
public BigDecimal getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
public void setSupplierPrice(BigDecimal supplierPrice) {
|
||||
this.supplierPrice = supplierPrice;
|
||||
public void setCost(BigDecimal cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ public class PurchaseOrderResponse {
|
||||
private String orderStatus;
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
public PurchaseOrderResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ public class SaleItemRequest {
|
||||
private Integer quantity;
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
public SaleItemRequest() {
|
||||
}
|
||||
|
||||
public Long getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ public class SaleItemResponse {
|
||||
private BigDecimal unitPrice;
|
||||
private BigDecimal lineTotal;
|
||||
|
||||
public SaleItemResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ public class SaleRequest {
|
||||
private Boolean isRefund;
|
||||
private Long originalSaleId;
|
||||
|
||||
public SaleRequest() {
|
||||
}
|
||||
|
||||
public Long getStoreId() {
|
||||
return storeId;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ public class SaleResponse {
|
||||
private Long originalSaleId;
|
||||
private List<SaleItemResponse> items;
|
||||
|
||||
public SaleResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ public class ServiceRequest {
|
||||
private BigDecimal price;
|
||||
private String description;
|
||||
|
||||
public ServiceRequest() {
|
||||
}
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ public class ServiceResponse {
|
||||
private BigDecimal price;
|
||||
private String description;
|
||||
|
||||
public ServiceResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ public class SupplierRequest {
|
||||
private String email;
|
||||
private String address;
|
||||
|
||||
public SupplierRequest() {
|
||||
}
|
||||
|
||||
public String getSupplierName() {
|
||||
return supplierName;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ public class SupplierResponse {
|
||||
private String email;
|
||||
private String address;
|
||||
|
||||
public SupplierResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ public class UserRequest {
|
||||
private String role;
|
||||
private Boolean active;
|
||||
|
||||
public UserRequest() {
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ public class UserResponse {
|
||||
private Boolean active;
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
public UserResponse() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@ public class ProductSupplierApi {
|
||||
return apiClient.post("/api/v1/product-suppliers", request, ProductSupplierResponse.class);
|
||||
}
|
||||
|
||||
public ProductSupplierResponse updateProductSupplier(Long id, ProductSupplierRequest request) throws Exception {
|
||||
return apiClient.put("/api/v1/product-suppliers/" + id, request, ProductSupplierResponse.class);
|
||||
public ProductSupplierResponse updateProductSupplier(Long productId, Long supplierId, ProductSupplierRequest request) throws Exception {
|
||||
return apiClient.put("/api/v1/product-suppliers/" + productId + "/" + supplierId, request, ProductSupplierResponse.class);
|
||||
}
|
||||
|
||||
public void deleteProductSuppliers(List<Long> ids) throws Exception {
|
||||
apiClient.deleteWithBody("/api/v1/product-suppliers", new BulkDeleteRequest(ids));
|
||||
public void deleteProductSupplier(Long productId, Long supplierId) throws Exception {
|
||||
apiClient.delete("/api/v1/product-suppliers/" + productId + "/" + supplierId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,24 +192,36 @@ public class ProductSupplierController {
|
||||
|
||||
//if confirmed, start deletion
|
||||
if (result.isPresent() && result.get() == ButtonType.OK) {
|
||||
List<Long> ids = selectedProductSuppliers.stream()
|
||||
.map(ps -> (long) ps.getSupId())
|
||||
.collect(Collectors.toList());
|
||||
int deleteCount = 0;
|
||||
Exception lastException = null;
|
||||
|
||||
try {
|
||||
ProductSupplierApi.getInstance().deleteProductSuppliers(ids);
|
||||
for (ProductSupplierDTO ps : selectedProductSuppliers) {
|
||||
try {
|
||||
ProductSupplierApi.getInstance().deleteProductSupplier(
|
||||
(long) ps.getProdId(),
|
||||
(long) ps.getSupId()
|
||||
);
|
||||
deleteCount++;
|
||||
} catch (Exception e) {
|
||||
lastException = e;
|
||||
ActivityLogger.getInstance().logException(
|
||||
"ProductSupplierController.btnDeleteClicked",
|
||||
e,
|
||||
"Deleting product-supplier with productId=" + ps.getProdId() + ", supplierId=" + ps.getSupId());
|
||||
}
|
||||
}
|
||||
|
||||
if (deleteCount > 0) {
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setHeaderText("Database Operation Confirmed");
|
||||
alert.setContentText("Successfully deleted " + ids.size() + " product-supplier(s)");
|
||||
alert.setContentText("Successfully deleted " + deleteCount + " product-supplier(s)");
|
||||
alert.showAndWait();
|
||||
} catch (Exception e) {
|
||||
ActivityLogger.getInstance().logException(
|
||||
"ProductSupplierController.btnDeleteClicked",
|
||||
e,
|
||||
"Deleting product-suppliers");
|
||||
}
|
||||
|
||||
if (lastException != null && deleteCount < selectedProductSuppliers.size()) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setHeaderText("Delete Operation Failed");
|
||||
alert.setContentText(e.getMessage());
|
||||
alert.setHeaderText("Delete Operation Partially Failed");
|
||||
alert.setContentText("Deleted " + deleteCount + " of " + selectedProductSuppliers.size() + " product-supplier(s). Last error: " + lastException.getMessage());
|
||||
alert.showAndWait();
|
||||
}
|
||||
|
||||
@@ -286,7 +298,7 @@ public class ProductSupplierController {
|
||||
response.getProductId().intValue(),
|
||||
response.getSupplierName(),
|
||||
response.getProductName(),
|
||||
response.getSupplierPrice().doubleValue()
|
||||
response.getCost().doubleValue()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ public class ProductSupplierDialogController {
|
||||
private String mode = null;
|
||||
private int selectedSupId = -1;
|
||||
private int selectedProdId = -1;
|
||||
private Long selectedId = null;
|
||||
|
||||
/**
|
||||
* add event listeners to buttons and set up combobox
|
||||
@@ -169,7 +168,7 @@ public class ProductSupplierDialogController {
|
||||
if (mode.equals("Add")) {
|
||||
ProductSupplierApi.getInstance().createProductSupplier(request);
|
||||
} else {
|
||||
ProductSupplierApi.getInstance().updateProductSupplier(selectedId, request);
|
||||
ProductSupplierApi.getInstance().updateProductSupplier((long) selectedProdId, (long) selectedSupId, request);
|
||||
}
|
||||
|
||||
Platform.runLater(() -> {
|
||||
@@ -209,7 +208,7 @@ public class ProductSupplierDialogController {
|
||||
request.setSupplierId(cbSupplier.getSelectionModel().getSelectedItem().getId());
|
||||
request.setProductId(cbProduct.getSelectionModel().getSelectedItem().getId());
|
||||
try {
|
||||
request.setSupplierPrice(new BigDecimal(txtCost.getText()));
|
||||
request.setCost(new BigDecimal(txtCost.getText()));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("Invalid cost format");
|
||||
}
|
||||
@@ -266,7 +265,6 @@ public class ProductSupplierDialogController {
|
||||
public void setSelectedIds(int supId, int prodId){
|
||||
this.selectedSupId = supId;
|
||||
this.selectedProdId = prodId;
|
||||
this.selectedId = (long) supId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user