add purchaseOrder store FK

This commit is contained in:
2026-04-06 20:26:42 -06:00
parent b2ddea8794
commit c15313ea5f
3 changed files with 41 additions and 6 deletions

View File

@@ -8,6 +8,8 @@ public class PurchaseOrderResponse {
private Long purchaseOrderId; private Long purchaseOrderId;
private Long supId; private Long supId;
private String supplierName; private String supplierName;
private Long storeId;
private String storeName;
private LocalDate orderDate; private LocalDate orderDate;
private String status; private String status;
private LocalDateTime createdAt; private LocalDateTime createdAt;
@@ -16,10 +18,12 @@ public class PurchaseOrderResponse {
public PurchaseOrderResponse() { public PurchaseOrderResponse() {
} }
public PurchaseOrderResponse(Long purchaseOrderId, Long supId, String supplierName, LocalDate orderDate, String status, LocalDateTime createdAt, LocalDateTime updatedAt) { public PurchaseOrderResponse(Long purchaseOrderId, Long supId, String supplierName, Long storeId, String storeName, LocalDate orderDate, String status, LocalDateTime createdAt, LocalDateTime updatedAt) {
this.purchaseOrderId = purchaseOrderId; this.purchaseOrderId = purchaseOrderId;
this.supId = supId; this.supId = supId;
this.supplierName = supplierName; this.supplierName = supplierName;
this.storeId = storeId;
this.storeName = storeName;
this.orderDate = orderDate; this.orderDate = orderDate;
this.status = status; this.status = status;
this.createdAt = createdAt; this.createdAt = createdAt;
@@ -50,6 +54,22 @@ public class PurchaseOrderResponse {
this.supplierName = supplierName; this.supplierName = supplierName;
} }
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 LocalDate getOrderDate() { public LocalDate getOrderDate() {
return orderDate; return orderDate;
} }
@@ -87,12 +107,12 @@ public class PurchaseOrderResponse {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
PurchaseOrderResponse that = (PurchaseOrderResponse) o; PurchaseOrderResponse that = (PurchaseOrderResponse) o;
return Objects.equals(purchaseOrderId, that.purchaseOrderId) && Objects.equals(supId, that.supId) && Objects.equals(supplierName, that.supplierName) && Objects.equals(orderDate, that.orderDate) && Objects.equals(status, that.status) && Objects.equals(createdAt, that.createdAt) && Objects.equals(updatedAt, that.updatedAt); return Objects.equals(purchaseOrderId, that.purchaseOrderId) && Objects.equals(supId, that.supId) && Objects.equals(supplierName, that.supplierName) && Objects.equals(storeId, that.storeId) && Objects.equals(storeName, that.storeName) && Objects.equals(orderDate, that.orderDate) && Objects.equals(status, that.status) && Objects.equals(createdAt, that.createdAt) && Objects.equals(updatedAt, that.updatedAt);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(purchaseOrderId, supId, supplierName, orderDate, status, createdAt, updatedAt); return Objects.hash(purchaseOrderId, supId, supplierName, storeId, storeName, orderDate, status, createdAt, updatedAt);
} }
@Override @Override
@@ -101,6 +121,8 @@ public class PurchaseOrderResponse {
"purchaseOrderId=" + purchaseOrderId + "purchaseOrderId=" + purchaseOrderId +
", supId=" + supId + ", supId=" + supId +
", supplierName='" + supplierName + '\'' + ", supplierName='" + supplierName + '\'' +
", storeId=" + storeId +
", storeName='" + storeName + '\'' +
", orderDate=" + orderDate + ", orderDate=" + orderDate +
", status='" + status + '\'' + ", status='" + status + '\'' +
", createdAt=" + createdAt + ", createdAt=" + createdAt +

View File

@@ -4,11 +4,8 @@ import jakarta.persistence.*;
import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp; import org.hibernate.annotations.UpdateTimestamp;
import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
@Entity @Entity
@@ -23,6 +20,10 @@ public class PurchaseOrder {
@JoinColumn(name = "supId", nullable = false) @JoinColumn(name = "supId", nullable = false)
private Supplier supplier; private Supplier supplier;
@ManyToOne
@JoinColumn(name = "storeId")
private StoreLocation store;
@Column(nullable = false) @Column(nullable = false)
private LocalDate orderDate; private LocalDate orderDate;
@@ -65,6 +66,14 @@ public class PurchaseOrder {
this.supplier = supplier; this.supplier = supplier;
} }
public StoreLocation getStore() {
return store;
}
public void setStore(StoreLocation store) {
this.store = store;
}
public LocalDate getOrderDate() { public LocalDate getOrderDate() {
return orderDate; return orderDate;
} }

View File

@@ -2,6 +2,7 @@ package com.petshop.backend.service;
import com.petshop.backend.dto.purchaseorder.PurchaseOrderResponse; import com.petshop.backend.dto.purchaseorder.PurchaseOrderResponse;
import com.petshop.backend.entity.PurchaseOrder; import com.petshop.backend.entity.PurchaseOrder;
import com.petshop.backend.entity.StoreLocation;
import com.petshop.backend.exception.ResourceNotFoundException; import com.petshop.backend.exception.ResourceNotFoundException;
import com.petshop.backend.repository.PurchaseOrderRepository; import com.petshop.backend.repository.PurchaseOrderRepository;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@@ -34,10 +35,13 @@ public class PurchaseOrderService {
} }
private PurchaseOrderResponse mapToResponse(PurchaseOrder purchaseOrder) { private PurchaseOrderResponse mapToResponse(PurchaseOrder purchaseOrder) {
StoreLocation store = purchaseOrder.getStore();
return new PurchaseOrderResponse( return new PurchaseOrderResponse(
purchaseOrder.getPurchaseOrderId(), purchaseOrder.getPurchaseOrderId(),
purchaseOrder.getSupplier().getSupId(), purchaseOrder.getSupplier().getSupId(),
purchaseOrder.getSupplier().getSupCompany(), purchaseOrder.getSupplier().getSupCompany(),
store != null ? store.getStoreId() : null,
store != null ? store.getStoreName() : null,
purchaseOrder.getOrderDate(), purchaseOrder.getOrderDate(),
purchaseOrder.getStatus(), purchaseOrder.getStatus(),
purchaseOrder.getCreatedAt(), purchaseOrder.getCreatedAt(),