fix desktop user inventory crud
This commit is contained in:
@@ -5,9 +5,12 @@ public class EmployeeRequest {
|
||||
private String password;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String fullName;
|
||||
private String email;
|
||||
private String phone;
|
||||
private String role;
|
||||
private String staffRole;
|
||||
private Long primaryStoreId;
|
||||
private Boolean active;
|
||||
|
||||
public String getUsername() { return username; }
|
||||
@@ -18,12 +21,18 @@ public class EmployeeRequest {
|
||||
public void setFirstName(String firstName) { this.firstName = firstName; }
|
||||
public String getLastName() { return lastName; }
|
||||
public void setLastName(String lastName) { this.lastName = lastName; }
|
||||
public String getFullName() { return fullName; }
|
||||
public void setFullName(String fullName) { this.fullName = fullName; }
|
||||
public String getEmail() { return email; }
|
||||
public void setEmail(String email) { this.email = email; }
|
||||
public String getPhone() { return phone; }
|
||||
public void setPhone(String phone) { this.phone = phone; }
|
||||
public String getRole() { return role; }
|
||||
public void setRole(String role) { this.role = role; }
|
||||
public String getStaffRole() { return staffRole; }
|
||||
public void setStaffRole(String staffRole) { this.staffRole = staffRole; }
|
||||
public Long getPrimaryStoreId() { return primaryStoreId; }
|
||||
public void setPrimaryStoreId(Long primaryStoreId) { this.primaryStoreId = primaryStoreId; }
|
||||
public Boolean getActive() { return active; }
|
||||
public void setActive(Boolean active) { this.active = active; }
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.example.petshopdesktop.api.dto.employee;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class EmployeeResponse {
|
||||
private Long id;
|
||||
private Long employeeId;
|
||||
private Long userId;
|
||||
private String username;
|
||||
@@ -12,13 +13,17 @@ public class EmployeeResponse {
|
||||
private String email;
|
||||
private String phone;
|
||||
private String role;
|
||||
private String staffRole;
|
||||
private Long primaryStoreId;
|
||||
private Boolean active;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
public Long getEmployeeId() { return employeeId; }
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
public Long getEmployeeId() { return employeeId != null ? employeeId : id; }
|
||||
public void setEmployeeId(Long employeeId) { this.employeeId = employeeId; }
|
||||
public Long getUserId() { return userId; }
|
||||
public Long getUserId() { return userId != null ? userId : id; }
|
||||
public void setUserId(Long userId) { this.userId = userId; }
|
||||
public String getUsername() { return username; }
|
||||
public void setUsername(String username) { this.username = username; }
|
||||
@@ -34,6 +39,10 @@ public class EmployeeResponse {
|
||||
public void setPhone(String phone) { this.phone = phone; }
|
||||
public String getRole() { return role; }
|
||||
public void setRole(String role) { this.role = role; }
|
||||
public String getStaffRole() { return staffRole; }
|
||||
public void setStaffRole(String staffRole) { this.staffRole = staffRole; }
|
||||
public Long getPrimaryStoreId() { return primaryStoreId; }
|
||||
public void setPrimaryStoreId(Long primaryStoreId) { this.primaryStoreId = primaryStoreId; }
|
||||
public Boolean getActive() { return active; }
|
||||
public void setActive(Boolean active) { this.active = active; }
|
||||
public LocalDateTime getCreatedAt() { return createdAt; }
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.example.petshopdesktop.api.dto.inventory;
|
||||
public class InventoryRequest {
|
||||
private Long prodId;
|
||||
private Integer quantity;
|
||||
private Long storeId;
|
||||
|
||||
public InventoryRequest() {
|
||||
}
|
||||
@@ -22,4 +23,12 @@ public class InventoryRequest {
|
||||
public void setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public Long getStoreId() {
|
||||
return storeId;
|
||||
}
|
||||
|
||||
public void setStoreId(Long storeId) {
|
||||
this.storeId = storeId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ public class InventoryResponse {
|
||||
private Long prodId;
|
||||
private String productName;
|
||||
private String categoryName;
|
||||
private Long storeId;
|
||||
private String storeName;
|
||||
private Integer quantity;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
@@ -46,6 +48,22 @@ public class InventoryResponse {
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
|
||||
public Long getStoreId() {
|
||||
return storeId;
|
||||
}
|
||||
|
||||
public void setStoreId(Long storeId) {
|
||||
this.storeId = storeId;
|
||||
}
|
||||
|
||||
public String getStoreName() {
|
||||
return storeName;
|
||||
}
|
||||
|
||||
public void setStoreName(String storeName) {
|
||||
this.storeName = storeName;
|
||||
}
|
||||
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
@@ -235,8 +235,8 @@ public class InventoryController {
|
||||
response.getProdId() != null ? response.getProdId().intValue() : 0,
|
||||
response.getProductName(),
|
||||
response.getCategoryName() != null ? response.getCategoryName() : "",
|
||||
0,
|
||||
"N/A",
|
||||
response.getStoreId() != null ? response.getStoreId().intValue() : 0,
|
||||
response.getStoreName() != null ? response.getStoreName() : "",
|
||||
response.getQuantity() != null ? response.getQuantity() : 0,
|
||||
0
|
||||
);
|
||||
|
||||
@@ -186,10 +186,14 @@ public class StaffAccountsController {
|
||||
long userId = employee.getUserId() != null ? employee.getUserId() : 0L;
|
||||
long employeeId = employee.getEmployeeId() != null ? employee.getEmployeeId() : 0L;
|
||||
String username = employee.getUsername();
|
||||
String fullName = employee.getFullName() != null ? employee.getFullName() : "";
|
||||
String[] names = splitFullName(fullName);
|
||||
String firstName = names[0];
|
||||
String lastName = names[1];
|
||||
String firstName = employee.getFirstName() != null ? employee.getFirstName() : "";
|
||||
String lastName = employee.getLastName() != null ? employee.getLastName() : "";
|
||||
if (firstName.isBlank() && lastName.isBlank()) {
|
||||
String fullName = employee.getFullName() != null ? employee.getFullName() : "";
|
||||
String[] names = splitFullName(fullName);
|
||||
firstName = names[0];
|
||||
lastName = names[1];
|
||||
}
|
||||
String email = employee.getEmail() != null ? employee.getEmail() : "";
|
||||
String phone = employee.getPhone() != null ? employee.getPhone() : "";
|
||||
String role = employee.getRole() != null ? employee.getRole() : "STAFF";
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.example.petshopdesktop.api.dto.inventory.InventoryResponse;
|
||||
import org.example.petshopdesktop.api.dto.product.ProductResponse;
|
||||
import org.example.petshopdesktop.api.endpoints.InventoryApi;
|
||||
import org.example.petshopdesktop.api.endpoints.ProductApi;
|
||||
import org.example.petshopdesktop.auth.UserSession;
|
||||
import org.example.petshopdesktop.models.Product;
|
||||
import org.example.petshopdesktop.util.ActivityLogger;
|
||||
|
||||
@@ -127,6 +128,10 @@ public class InventoryDialogController {
|
||||
try {
|
||||
InventoryRequest request = new InventoryRequest();
|
||||
Product selectedProduct = cbProduct.getSelectionModel().getSelectedItem();
|
||||
Long storeId = UserSession.getInstance().getStoreId();
|
||||
if (storeId == null || storeId <= 0) {
|
||||
throw new IllegalStateException("Store is not set for this account");
|
||||
}
|
||||
request.setProdId((long) selectedProduct.getProdId());
|
||||
int quantity;
|
||||
try {
|
||||
@@ -135,6 +140,7 @@ public class InventoryDialogController {
|
||||
throw new IllegalArgumentException("Invalid quantity format");
|
||||
}
|
||||
request.setQuantity(quantity);
|
||||
request.setStoreId(storeId);
|
||||
|
||||
if (mode.equals("Add")) {
|
||||
InventoryApi.getInstance().createInventory(request);
|
||||
@@ -206,4 +212,4 @@ public class InventoryDialogController {
|
||||
lblMode.setText(mode + " Inventory");
|
||||
lblInventoryId.setVisible(mode.equals("Edit"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import javafx.stage.Stage;
|
||||
import org.example.petshopdesktop.Validator;
|
||||
import org.example.petshopdesktop.api.dto.employee.EmployeeRequest;
|
||||
import org.example.petshopdesktop.api.endpoints.EmployeeApi;
|
||||
import org.example.petshopdesktop.auth.UserSession;
|
||||
import org.example.petshopdesktop.models.StaffAccount;
|
||||
import org.example.petshopdesktop.util.ActivityLogger;
|
||||
|
||||
@@ -104,14 +105,18 @@ public class StaffEditDialogController {
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Long storeId = UserSession.getInstance().getStoreId();
|
||||
EmployeeRequest request = new EmployeeRequest();
|
||||
request.setUsername(username);
|
||||
request.setPassword(password.isEmpty() ? null : password);
|
||||
request.setFirstName(firstName);
|
||||
request.setLastName(lastName);
|
||||
request.setFullName(firstName + " " + lastName);
|
||||
request.setEmail(email);
|
||||
request.setPhone(phone);
|
||||
request.setRole(staffAccount.getRole());
|
||||
request.setStaffRole("Staff");
|
||||
request.setPrimaryStoreId(storeId);
|
||||
request.setActive(staffAccount.isActive());
|
||||
|
||||
EmployeeApi.getInstance().updateEmployee(staffAccount.getEmployeeId(), request);
|
||||
|
||||
@@ -11,6 +11,7 @@ import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import org.example.petshopdesktop.api.dto.employee.EmployeeRequest;
|
||||
import org.example.petshopdesktop.api.endpoints.EmployeeApi;
|
||||
import org.example.petshopdesktop.auth.UserSession;
|
||||
import org.example.petshopdesktop.Validator;
|
||||
import org.example.petshopdesktop.util.ActivityLogger;
|
||||
|
||||
@@ -89,14 +90,18 @@ public class StaffRegisterDialogController {
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Long storeId = UserSession.getInstance().getStoreId();
|
||||
EmployeeRequest request = new EmployeeRequest();
|
||||
request.setUsername(username);
|
||||
request.setPassword(password);
|
||||
request.setFirstName(firstName);
|
||||
request.setLastName(lastName);
|
||||
request.setFullName(firstName + " " + lastName);
|
||||
request.setEmail(email);
|
||||
request.setPhone(phone);
|
||||
request.setRole("STAFF");
|
||||
request.setStaffRole("Staff");
|
||||
request.setPrimaryStoreId(storeId);
|
||||
request.setActive(true);
|
||||
|
||||
EmployeeApi.getInstance().createEmployee(request);
|
||||
|
||||
Reference in New Issue
Block a user