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 {
private Long adoptionId;
private Long petId;
private Long customerId;
private String petName;
private String customerName;
private LocalDate adoptionDate;
private java.math.BigDecimal adoptionFee;
private String adoptionStatus;
public AdoptionResponse() {
@@ -20,6 +23,22 @@ public class AdoptionResponse {
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() {
return petName;
}
@@ -44,6 +63,14 @@ public class AdoptionResponse {
this.adoptionDate = adoptionDate;
}
public java.math.BigDecimal getAdoptionFee() {
return adoptionFee;
}
public void setAdoptionFee(java.math.BigDecimal adoptionFee) {
this.adoptionFee = adoptionFee;
}
public String getAdoptionStatus() {
return adoptionStatus;
}

View File

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

View File

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

View File

@@ -3,7 +3,12 @@ package org.example.petshopdesktop.api.dto.auth;
public class UserInfoResponse {
private Long id;
private String username;
private String email;
private String fullName;
private String avatarUrl;
private String role;
private Long storeId;
private String storeName;
public UserInfoResponse() {
}
@@ -24,6 +29,30 @@ public class UserInfoResponse {
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() {
return role;
}
@@ -31,4 +60,20 @@ public class UserInfoResponse {
public void setRole(String 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) {
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) {
return new Adoption(
response.getAdoptionId().intValue(),
0,
0,
response.getPetId() != null ? response.getPetId().intValue() : 0,
response.getCustomerId() != null ? response.getCustomerId().intValue() : 0,
response.getPetName(),
response.getCustomerName(),
response.getAdoptionDate() != null ? response.getAdoptionDate().toString() : "",
0.0,
response.getAdoptionFee() != null ? response.getAdoptionFee().doubleValue() : 0.0,
response.getAdoptionStatus()
);
}

View File

@@ -230,13 +230,14 @@ public class AppointmentController {
}
private AppointmentDTO mapToAppointmentDTO(AppointmentResponse response) {
Long petId = response.getPetIds() != null && !response.getPetIds().isEmpty() ? response.getPetIds().get(0) : null;
return new AppointmentDTO(
response.getAppointmentId().intValue(),
0,
response.getCustomerId() != null ? response.getCustomerId().intValue() : 0,
response.getCustomerName(),
0,
petId != null ? petId.intValue() : 0,
String.join(", ", response.getPetNames()),
0,
response.getServiceId() != null ? response.getServiceId().intValue() : 0,
response.getServiceName(),
response.getAppointmentDate().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.LoginResponse;
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.UserSession;
import org.example.petshopdesktop.util.ActivityLogger;
import java.util.List;
public class LoginController {
@FXML
@@ -79,11 +75,7 @@ public class LoginController {
throw new IllegalStateException("User info is null");
}
UserSession.getInstance().login(userInfo.getId(), username, role, token);
List<DropdownOption> stores = DropdownApi.getInstance().getStores();
if (stores != null && !stores.isEmpty()) {
UserSession.getInstance().setStoreId(stores.get(0).getId());
}
UserSession.getInstance().setStoreId(userInfo.getStoreId());
openMainLayout();

View File

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

View File

@@ -142,6 +142,8 @@ public class SaleController {
}
private void setupTables() {
tvCart.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tvCart.setFixedCellSize(34);
colCartProduct.setCellValueFactory(new PropertyValueFactory<>("prodName"));
colCartQty.setCellValueFactory(new PropertyValueFactory<>("quantity"));
colCartUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice"));
@@ -149,6 +151,8 @@ public class SaleController {
tvCart.setItems(cartItems);
tvCart.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
tvSales.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tvSales.setFixedCellSize(34);
colSaleId.setCellValueFactory(new PropertyValueFactory<>("saleId"));
colSaleDate.setCellValueFactory(new PropertyValueFactory<>("saleDate"));
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.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.endpoints.AppointmentApi;
import org.example.petshopdesktop.api.endpoints.DropdownApi;
import org.example.petshopdesktop.auth.UserSession;
import org.example.petshopdesktop.util.ActivityLogger;
import java.time.LocalTime;
@@ -89,6 +89,7 @@ public class AppointmentDialogController {
if (pets != null) {
cbPet.setItems(FXCollections.observableArrayList(pets));
}
syncSelectedAppointment();
});
} catch (Exception e) {
Platform.runLater(() -> {
@@ -194,15 +195,15 @@ public class AppointmentDialogController {
}
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 -> {
if (c.getId() == appt.getCustomerId()) cbCustomer.setValue(c);
if (c.getId() != null && c.getId().longValue() == appt.getCustomerId()) cbCustomer.setValue(c);
});
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());
Long storeId = UserSession.getInstance().getStoreId();
if (storeId == null || storeId <= 0) {
showError("Store is not set for this account");
return;
}
AppointmentRequest request = new AppointmentRequest();
request.setPetIds(Collections.singletonList(cbPet.getValue().getId()));
request.setCustomerId(cbCustomer.getValue().getId());
request.setStoreId(storeId);
request.setServiceId(cbService.getValue().getId());
request.setAppointmentDate(dpAppointmentDate.getValue());
request.setAppointmentTime(appointmentTime);
@@ -275,4 +282,10 @@ public class AppointmentDialogController {
alert.setContentText(msg);
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 java.math.BigDecimal;
import java.time.LocalDate;
public class PetDialogController {
@FXML
@@ -158,7 +156,7 @@ public class PetDialogController {
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid age format");
}
LocalDate dateOfBirth = LocalDate.now().minusYears(age);
request.setPetAge(age);
return request;
}

View File

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

View File

@@ -151,16 +151,16 @@
</TextField>
</children>
</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>
<TableColumn fx:id="colSaleId" prefWidth="40.0" text="ID" />
<TableColumn fx:id="colSaleDate" prefWidth="130.0" text="Date" />
<TableColumn fx:id="colEmployeeName" prefWidth="140.0" text="Employee" />
<TableColumn fx:id="colServiceProduct" prefWidth="150.0" text="Product" />
<TableColumn fx:id="colSaleQuantity" prefWidth="50.0" text="Qty" />
<TableColumn fx:id="colSaleUnitPrice" prefWidth="90.0" text="Unit Price" />
<TableColumn fx:id="colSaleTotal" prefWidth="90.0" text="Total" />
<TableColumn fx:id="colSalePaymentType" prefWidth="90.0" text="Payment" />
<TableColumn fx:id="colSaleId" minWidth="56.0" prefWidth="72.0" text="ID" />
<TableColumn fx:id="colSaleDate" minWidth="150.0" prefWidth="180.0" text="Date" />
<TableColumn fx:id="colEmployeeName" minWidth="150.0" prefWidth="180.0" text="Employee" />
<TableColumn fx:id="colServiceProduct" minWidth="190.0" prefWidth="240.0" text="Product" />
<TableColumn fx:id="colSaleQuantity" minWidth="70.0" prefWidth="80.0" text="Qty" />
<TableColumn fx:id="colSaleUnitPrice" minWidth="110.0" prefWidth="130.0" text="Unit Price" />
<TableColumn fx:id="colSaleTotal" minWidth="100.0" prefWidth="120.0" text="Total" />
<TableColumn fx:id="colSalePaymentType" minWidth="100.0" prefWidth="120.0" text="Payment" />
</columns>
</TableView>
</children>