add purchaseOrder store FK
This commit is contained in:
@@ -8,6 +8,8 @@ public class PurchaseOrderResponse {
|
||||
private Long purchaseOrderId;
|
||||
private Long supId;
|
||||
private String supplierName;
|
||||
private Long storeId;
|
||||
private String storeName;
|
||||
private LocalDate orderDate;
|
||||
private String status;
|
||||
private LocalDateTime createdAt;
|
||||
@@ -16,10 +18,12 @@ public class 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.supId = supId;
|
||||
this.supplierName = supplierName;
|
||||
this.storeId = storeId;
|
||||
this.storeName = storeName;
|
||||
this.orderDate = orderDate;
|
||||
this.status = status;
|
||||
this.createdAt = createdAt;
|
||||
@@ -50,6 +54,22 @@ public class PurchaseOrderResponse {
|
||||
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() {
|
||||
return orderDate;
|
||||
}
|
||||
@@ -87,12 +107,12 @@ public class PurchaseOrderResponse {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
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
|
||||
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
|
||||
@@ -101,6 +121,8 @@ public class PurchaseOrderResponse {
|
||||
"purchaseOrderId=" + purchaseOrderId +
|
||||
", supId=" + supId +
|
||||
", supplierName='" + supplierName + '\'' +
|
||||
", storeId=" + storeId +
|
||||
", storeName='" + storeName + '\'' +
|
||||
", orderDate=" + orderDate +
|
||||
", status='" + status + '\'' +
|
||||
", createdAt=" + createdAt +
|
||||
|
||||
@@ -4,11 +4,8 @@ import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@@ -23,6 +20,10 @@ public class PurchaseOrder {
|
||||
@JoinColumn(name = "supId", nullable = false)
|
||||
private Supplier supplier;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "storeId")
|
||||
private StoreLocation store;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDate orderDate;
|
||||
|
||||
@@ -65,6 +66,14 @@ public class PurchaseOrder {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
public StoreLocation getStore() {
|
||||
return store;
|
||||
}
|
||||
|
||||
public void setStore(StoreLocation store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
public LocalDate getOrderDate() {
|
||||
return orderDate;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.petshop.backend.service;
|
||||
|
||||
import com.petshop.backend.dto.purchaseorder.PurchaseOrderResponse;
|
||||
import com.petshop.backend.entity.PurchaseOrder;
|
||||
import com.petshop.backend.entity.StoreLocation;
|
||||
import com.petshop.backend.exception.ResourceNotFoundException;
|
||||
import com.petshop.backend.repository.PurchaseOrderRepository;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -34,10 +35,13 @@ public class PurchaseOrderService {
|
||||
}
|
||||
|
||||
private PurchaseOrderResponse mapToResponse(PurchaseOrder purchaseOrder) {
|
||||
StoreLocation store = purchaseOrder.getStore();
|
||||
return new PurchaseOrderResponse(
|
||||
purchaseOrder.getPurchaseOrderId(),
|
||||
purchaseOrder.getSupplier().getSupId(),
|
||||
purchaseOrder.getSupplier().getSupCompany(),
|
||||
store != null ? store.getStoreId() : null,
|
||||
store != null ? store.getStoreName() : null,
|
||||
purchaseOrder.getOrderDate(),
|
||||
purchaseOrder.getStatus(),
|
||||
purchaseOrder.getCreatedAt(),
|
||||
|
||||
Reference in New Issue
Block a user