Fix desktop mappings

This commit is contained in:
2026-03-10 18:49:59 -06:00
parent 93b587cd9c
commit bdde1d39dc
14 changed files with 175 additions and 42 deletions

View File

@@ -4,9 +4,12 @@ import java.time.LocalDate;
public class AdoptionResponse { public class AdoptionResponse {
private Long adoptionId; private Long adoptionId;
private Long petId;
private Long customerId;
private String petName; private String petName;
private String customerName; private String customerName;
private LocalDate adoptionDate; private LocalDate adoptionDate;
private java.math.BigDecimal adoptionFee;
private String adoptionStatus; private String adoptionStatus;
public AdoptionResponse() { public AdoptionResponse() {
@@ -20,6 +23,22 @@ public class AdoptionResponse {
this.adoptionId = adoptionId; this.adoptionId = adoptionId;
} }
public Long getPetId() {
return petId;
}
public void setPetId(Long petId) {
this.petId = petId;
}
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public String getPetName() { public String getPetName() {
return petName; return petName;
} }
@@ -44,6 +63,14 @@ public class AdoptionResponse {
this.adoptionDate = adoptionDate; this.adoptionDate = adoptionDate;
} }
public java.math.BigDecimal getAdoptionFee() {
return adoptionFee;
}
public void setAdoptionFee(java.math.BigDecimal adoptionFee) {
this.adoptionFee = adoptionFee;
}
public String getAdoptionStatus() { public String getAdoptionStatus() {
return adoptionStatus; return adoptionStatus;
} }

View File

@@ -7,6 +7,7 @@ import java.util.List;
public class AppointmentRequest { public class AppointmentRequest {
private List<Long> petIds; private List<Long> petIds;
private Long customerId; private Long customerId;
private Long storeId;
private Long serviceId; private Long serviceId;
private LocalDate appointmentDate; private LocalDate appointmentDate;
private LocalTime appointmentTime; private LocalTime appointmentTime;
@@ -31,6 +32,14 @@ public class AppointmentRequest {
this.customerId = customerId; this.customerId = customerId;
} }
public Long getStoreId() {
return storeId;
}
public void setStoreId(Long storeId) {
this.storeId = storeId;
}
public Long getServiceId() { public Long getServiceId() {
return serviceId; return serviceId;
} }

View File

@@ -5,8 +5,13 @@ import java.time.LocalTime;
public class AppointmentResponse { public class AppointmentResponse {
private Long appointmentId; private Long appointmentId;
private Long customerId;
private String customerName; private String customerName;
private Long storeId;
private String storeName;
private Long serviceId;
private java.util.List<String> petNames; private java.util.List<String> petNames;
private java.util.List<Long> petIds;
private String serviceName; private String serviceName;
private LocalDate appointmentDate; private LocalDate appointmentDate;
private LocalTime appointmentTime; private LocalTime appointmentTime;
@@ -23,6 +28,14 @@ public class AppointmentResponse {
this.appointmentId = appointmentId; this.appointmentId = appointmentId;
} }
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public String getCustomerName() { public String getCustomerName() {
return customerName; return customerName;
} }
@@ -31,6 +44,30 @@ public class AppointmentResponse {
this.customerName = customerName; this.customerName = customerName;
} }
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 Long getServiceId() {
return serviceId;
}
public void setServiceId(Long serviceId) {
this.serviceId = serviceId;
}
public java.util.List<String> getPetNames() { public java.util.List<String> getPetNames() {
return petNames; return petNames;
} }
@@ -39,6 +76,14 @@ public class AppointmentResponse {
this.petNames = petNames; this.petNames = petNames;
} }
public java.util.List<Long> getPetIds() {
return petIds;
}
public void setPetIds(java.util.List<Long> petIds) {
this.petIds = petIds;
}
public String getServiceName() { public String getServiceName() {
return serviceName; return serviceName;
} }

View File

@@ -3,7 +3,12 @@ package org.example.petshopdesktop.api.dto.auth;
public class UserInfoResponse { public class UserInfoResponse {
private Long id; private Long id;
private String username; private String username;
private String email;
private String fullName;
private String avatarUrl;
private String role; private String role;
private Long storeId;
private String storeName;
public UserInfoResponse() { public UserInfoResponse() {
} }
@@ -24,6 +29,30 @@ public class UserInfoResponse {
this.username = username; this.username = username;
} }
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public String getRole() { public String getRole() {
return role; return role;
} }
@@ -31,4 +60,20 @@ public class UserInfoResponse {
public void setRole(String role) { public void setRole(String role) {
this.role = role; this.role = role;
} }
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;
}
} }

View File

@@ -22,4 +22,9 @@ public class DropdownOption {
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
@Override
public String toString() {
return label == null ? "" : label;
}
} }

View File

@@ -247,12 +247,12 @@ public class AdoptionController {
private Adoption mapToAdoption(AdoptionResponse response) { private Adoption mapToAdoption(AdoptionResponse response) {
return new Adoption( return new Adoption(
response.getAdoptionId().intValue(), response.getAdoptionId().intValue(),
0, response.getPetId() != null ? response.getPetId().intValue() : 0,
0, response.getCustomerId() != null ? response.getCustomerId().intValue() : 0,
response.getPetName(), response.getPetName(),
response.getCustomerName(), response.getCustomerName(),
response.getAdoptionDate() != null ? response.getAdoptionDate().toString() : "", response.getAdoptionDate() != null ? response.getAdoptionDate().toString() : "",
0.0, response.getAdoptionFee() != null ? response.getAdoptionFee().doubleValue() : 0.0,
response.getAdoptionStatus() response.getAdoptionStatus()
); );
} }

View File

@@ -230,13 +230,14 @@ public class AppointmentController {
} }
private AppointmentDTO mapToAppointmentDTO(AppointmentResponse response) { private AppointmentDTO mapToAppointmentDTO(AppointmentResponse response) {
Long petId = response.getPetIds() != null && !response.getPetIds().isEmpty() ? response.getPetIds().get(0) : null;
return new AppointmentDTO( return new AppointmentDTO(
response.getAppointmentId().intValue(), response.getAppointmentId().intValue(),
0, response.getCustomerId() != null ? response.getCustomerId().intValue() : 0,
response.getCustomerName(), response.getCustomerName(),
0, petId != null ? petId.intValue() : 0,
String.join(", ", response.getPetNames()), String.join(", ", response.getPetNames()),
0, response.getServiceId() != null ? response.getServiceId().intValue() : 0,
response.getServiceName(), response.getServiceName(),
response.getAppointmentDate().toString(), response.getAppointmentDate().toString(),
response.getAppointmentTime().toString(), response.getAppointmentTime().toString(),

View File

@@ -14,14 +14,10 @@ import org.example.petshopdesktop.api.ApiClient;
import org.example.petshopdesktop.api.dto.auth.LoginRequest; import org.example.petshopdesktop.api.dto.auth.LoginRequest;
import org.example.petshopdesktop.api.dto.auth.LoginResponse; import org.example.petshopdesktop.api.dto.auth.LoginResponse;
import org.example.petshopdesktop.api.dto.auth.UserInfoResponse; import org.example.petshopdesktop.api.dto.auth.UserInfoResponse;
import org.example.petshopdesktop.api.dto.common.DropdownOption;
import org.example.petshopdesktop.api.endpoints.DropdownApi;
import org.example.petshopdesktop.auth.Role; import org.example.petshopdesktop.auth.Role;
import org.example.petshopdesktop.auth.UserSession; import org.example.petshopdesktop.auth.UserSession;
import org.example.petshopdesktop.util.ActivityLogger; import org.example.petshopdesktop.util.ActivityLogger;
import java.util.List;
public class LoginController { public class LoginController {
@FXML @FXML
@@ -79,11 +75,7 @@ public class LoginController {
throw new IllegalStateException("User info is null"); throw new IllegalStateException("User info is null");
} }
UserSession.getInstance().login(userInfo.getId(), username, role, token); UserSession.getInstance().login(userInfo.getId(), username, role, token);
UserSession.getInstance().setStoreId(userInfo.getStoreId());
List<DropdownOption> stores = DropdownApi.getInstance().getStores();
if (stores != null && !stores.isEmpty()) {
UserSession.getInstance().setStoreId(stores.get(0).getId());
}
openMainLayout(); openMainLayout();

View File

@@ -18,8 +18,6 @@ import org.example.petshopdesktop.models.Pet;
import org.example.petshopdesktop.util.ActivityLogger; import org.example.petshopdesktop.util.ActivityLogger;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDate;
import java.time.Period;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -257,16 +255,12 @@ public class PetController {
} }
private Pet mapToPet(PetResponse response) { private Pet mapToPet(PetResponse response) {
int age = 0;
if (null != null) {
age = Period.between(null, LocalDate.now()).getYears();
}
return new Pet( return new Pet(
response.getPetId().intValue(), response.getPetId().intValue(),
response.getPetName(), response.getPetName(),
response.getPetSpecies(), response.getPetSpecies(),
response.getPetBreed(), response.getPetBreed(),
age, response.getPetAge() != null ? response.getPetAge() : 0,
response.getPetStatus(), response.getPetStatus(),
response.getPetPrice().doubleValue() response.getPetPrice().doubleValue()
); );

View File

@@ -142,6 +142,8 @@ public class SaleController {
} }
private void setupTables() { private void setupTables() {
tvCart.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tvCart.setFixedCellSize(34);
colCartProduct.setCellValueFactory(new PropertyValueFactory<>("prodName")); colCartProduct.setCellValueFactory(new PropertyValueFactory<>("prodName"));
colCartQty.setCellValueFactory(new PropertyValueFactory<>("quantity")); colCartQty.setCellValueFactory(new PropertyValueFactory<>("quantity"));
colCartUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice")); colCartUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice"));
@@ -149,6 +151,8 @@ public class SaleController {
tvCart.setItems(cartItems); tvCart.setItems(cartItems);
tvCart.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); tvCart.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
tvSales.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tvSales.setFixedCellSize(34);
colSaleId.setCellValueFactory(new PropertyValueFactory<>("saleId")); colSaleId.setCellValueFactory(new PropertyValueFactory<>("saleId"));
colSaleDate.setCellValueFactory(new PropertyValueFactory<>("saleDate")); colSaleDate.setCellValueFactory(new PropertyValueFactory<>("saleDate"));
colEmployeeName.setCellValueFactory(new PropertyValueFactory<>("employeeName")); colEmployeeName.setCellValueFactory(new PropertyValueFactory<>("employeeName"));

View File

@@ -12,10 +12,10 @@ import javafx.scene.control.ListCell;
import org.example.petshopdesktop.DTOs.AppointmentDTO; import org.example.petshopdesktop.DTOs.AppointmentDTO;
import org.example.petshopdesktop.api.dto.appointment.AppointmentRequest; import org.example.petshopdesktop.api.dto.appointment.AppointmentRequest;
import org.example.petshopdesktop.api.dto.appointment.AppointmentResponse;
import org.example.petshopdesktop.api.dto.common.DropdownOption; import org.example.petshopdesktop.api.dto.common.DropdownOption;
import org.example.petshopdesktop.api.endpoints.AppointmentApi; import org.example.petshopdesktop.api.endpoints.AppointmentApi;
import org.example.petshopdesktop.api.endpoints.DropdownApi; import org.example.petshopdesktop.api.endpoints.DropdownApi;
import org.example.petshopdesktop.auth.UserSession;
import org.example.petshopdesktop.util.ActivityLogger; import org.example.petshopdesktop.util.ActivityLogger;
import java.time.LocalTime; import java.time.LocalTime;
@@ -89,6 +89,7 @@ public class AppointmentDialogController {
if (pets != null) { if (pets != null) {
cbPet.setItems(FXCollections.observableArrayList(pets)); cbPet.setItems(FXCollections.observableArrayList(pets));
} }
syncSelectedAppointment();
}); });
} catch (Exception e) { } catch (Exception e) {
Platform.runLater(() -> { Platform.runLater(() -> {
@@ -194,15 +195,15 @@ public class AppointmentDialogController {
} }
cbService.getItems().forEach(s -> { cbService.getItems().forEach(s -> {
if (s.getId() == appt.getServiceId()) cbService.setValue(s); if (s.getId() != null && s.getId().longValue() == appt.getServiceId()) cbService.setValue(s);
}); });
cbCustomer.getItems().forEach(c -> { cbCustomer.getItems().forEach(c -> {
if (c.getId() == appt.getCustomerId()) cbCustomer.setValue(c); if (c.getId() != null && c.getId().longValue() == appt.getCustomerId()) cbCustomer.setValue(c);
}); });
cbPet.getItems().forEach(p -> { cbPet.getItems().forEach(p -> {
if (p.getId() == appt.getPetId()) cbPet.setValue(p); if (p.getId() != null && p.getId().longValue() == appt.getPetId()) cbPet.setValue(p);
}); });
} }
@@ -225,10 +226,16 @@ public class AppointmentDialogController {
} }
LocalTime appointmentTime = LocalTime.of(cbHour.getValue(), cbMinute.getValue()); LocalTime appointmentTime = LocalTime.of(cbHour.getValue(), cbMinute.getValue());
Long storeId = UserSession.getInstance().getStoreId();
if (storeId == null || storeId <= 0) {
showError("Store is not set for this account");
return;
}
AppointmentRequest request = new AppointmentRequest(); AppointmentRequest request = new AppointmentRequest();
request.setPetIds(Collections.singletonList(cbPet.getValue().getId())); request.setPetIds(Collections.singletonList(cbPet.getValue().getId()));
request.setCustomerId(cbCustomer.getValue().getId()); request.setCustomerId(cbCustomer.getValue().getId());
request.setStoreId(storeId);
request.setServiceId(cbService.getValue().getId()); request.setServiceId(cbService.getValue().getId());
request.setAppointmentDate(dpAppointmentDate.getValue()); request.setAppointmentDate(dpAppointmentDate.getValue());
request.setAppointmentTime(appointmentTime); request.setAppointmentTime(appointmentTime);
@@ -275,4 +282,10 @@ public class AppointmentDialogController {
alert.setContentText(msg); alert.setContentText(msg);
alert.showAndWait(); alert.showAndWait();
} }
private void syncSelectedAppointment() {
if (selectedAppointment != null) {
displayAppointmentDetails(selectedAppointment);
}
}
} }

View File

@@ -16,8 +16,6 @@ import org.example.petshopdesktop.models.Pet;
import org.example.petshopdesktop.util.ActivityLogger; import org.example.petshopdesktop.util.ActivityLogger;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate;
public class PetDialogController { public class PetDialogController {
@FXML @FXML
@@ -158,7 +156,7 @@ public class PetDialogController {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid age format"); throw new IllegalArgumentException("Invalid age format");
} }
LocalDate dateOfBirth = LocalDate.now().minusYears(age); request.setPetAge(age);
return request; return request;
} }

View File

@@ -171,7 +171,7 @@ public class RefundDialogController {
} }
int alreadyRefunded = refundItems.stream() int alreadyRefunded = refundItems.stream()
.filter(r -> r.getProdId() == selected.getSaleItemId().intValue()) .filter(r -> r.getProdId() == selected.getProdId().intValue())
.mapToInt(RefundItem::getQuantity) .mapToInt(RefundItem::getQuantity)
.sum(); .sum();
@@ -200,7 +200,7 @@ public class RefundDialogController {
} }
refundItems.add(new RefundItem( refundItems.add(new RefundItem(
selected.getSaleItemId().intValue(), selected.getProdId().intValue(),
selected.getProductName(), selected.getProductName(),
quantity, quantity,
selected.getUnitPrice().doubleValue() selected.getUnitPrice().doubleValue()

View File

@@ -151,16 +151,16 @@
</TextField> </TextField>
</children> </children>
</HBox> </HBox>
<TableView fx:id="tvSales" prefHeight="362.0" prefWidth="752.0" style="-fx-background-color: white; -fx-background-radius: 12;" VBox.vgrow="ALWAYS"> <TableView fx:id="tvSales" prefHeight="362.0" prefWidth="752.0" style="-fx-background-color: white; -fx-background-radius: 12; -fx-padding: 6;" VBox.vgrow="ALWAYS">
<columns> <columns>
<TableColumn fx:id="colSaleId" prefWidth="40.0" text="ID" /> <TableColumn fx:id="colSaleId" minWidth="56.0" prefWidth="72.0" text="ID" />
<TableColumn fx:id="colSaleDate" prefWidth="130.0" text="Date" /> <TableColumn fx:id="colSaleDate" minWidth="150.0" prefWidth="180.0" text="Date" />
<TableColumn fx:id="colEmployeeName" prefWidth="140.0" text="Employee" /> <TableColumn fx:id="colEmployeeName" minWidth="150.0" prefWidth="180.0" text="Employee" />
<TableColumn fx:id="colServiceProduct" prefWidth="150.0" text="Product" /> <TableColumn fx:id="colServiceProduct" minWidth="190.0" prefWidth="240.0" text="Product" />
<TableColumn fx:id="colSaleQuantity" prefWidth="50.0" text="Qty" /> <TableColumn fx:id="colSaleQuantity" minWidth="70.0" prefWidth="80.0" text="Qty" />
<TableColumn fx:id="colSaleUnitPrice" prefWidth="90.0" text="Unit Price" /> <TableColumn fx:id="colSaleUnitPrice" minWidth="110.0" prefWidth="130.0" text="Unit Price" />
<TableColumn fx:id="colSaleTotal" prefWidth="90.0" text="Total" /> <TableColumn fx:id="colSaleTotal" minWidth="100.0" prefWidth="120.0" text="Total" />
<TableColumn fx:id="colSalePaymentType" prefWidth="90.0" text="Payment" /> <TableColumn fx:id="colSalePaymentType" minWidth="100.0" prefWidth="120.0" text="Payment" />
</columns> </columns>
</TableView> </TableView>
</children> </children>