From 969fbdfe8b89423314837845798421279ad828b0 Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Mon, 6 Apr 2026 20:28:31 -0600 Subject: [PATCH] add adoption sourceStore FK --- .../backend/dto/adoption/AdoptionRequest.java | 16 +++++++++-- .../dto/adoption/AdoptionResponse.java | 28 +++++++++++++++++-- .../com/petshop/backend/entity/Adoption.java | 12 ++++++++ .../backend/service/AdoptionService.java | 19 ++++++++++++- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/com/petshop/backend/dto/adoption/AdoptionRequest.java b/backend/src/main/java/com/petshop/backend/dto/adoption/AdoptionRequest.java index 9a34dff8..d3700bfc 100644 --- a/backend/src/main/java/com/petshop/backend/dto/adoption/AdoptionRequest.java +++ b/backend/src/main/java/com/petshop/backend/dto/adoption/AdoptionRequest.java @@ -20,6 +20,8 @@ public class AdoptionRequest { private Long employeeId; + private Long sourceStoreId; + public Long getPetId() { return petId; } @@ -60,6 +62,14 @@ public class AdoptionRequest { this.employeeId = employeeId; } + public Long getSourceStoreId() { + return sourceStoreId; + } + + public void setSourceStoreId(Long sourceStoreId) { + this.sourceStoreId = sourceStoreId; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -69,12 +79,13 @@ public class AdoptionRequest { Objects.equals(customerId, that.customerId) && Objects.equals(adoptionDate, that.adoptionDate) && Objects.equals(adoptionStatus, that.adoptionStatus) && - Objects.equals(employeeId, that.employeeId); + Objects.equals(employeeId, that.employeeId) && + Objects.equals(sourceStoreId, that.sourceStoreId); } @Override public int hashCode() { - return Objects.hash(petId, customerId, adoptionDate, adoptionStatus, employeeId); + return Objects.hash(petId, customerId, adoptionDate, adoptionStatus, employeeId, sourceStoreId); } @Override @@ -85,6 +96,7 @@ public class AdoptionRequest { ", adoptionDate=" + adoptionDate + ", adoptionStatus='" + adoptionStatus + '\'' + ", employeeId=" + employeeId + + ", sourceStoreId=" + sourceStoreId + '}'; } } diff --git a/backend/src/main/java/com/petshop/backend/dto/adoption/AdoptionResponse.java b/backend/src/main/java/com/petshop/backend/dto/adoption/AdoptionResponse.java index 43128d23..7e831213 100644 --- a/backend/src/main/java/com/petshop/backend/dto/adoption/AdoptionResponse.java +++ b/backend/src/main/java/com/petshop/backend/dto/adoption/AdoptionResponse.java @@ -13,6 +13,8 @@ public class AdoptionResponse { private String customerName; private Long employeeId; private String employeeName; + private Long sourceStoreId; + private String sourceStoreName; private LocalDate adoptionDate; private String adoptionStatus; private BigDecimal adoptionFee; @@ -22,7 +24,7 @@ public class AdoptionResponse { public AdoptionResponse() { } - public AdoptionResponse(Long adoptionId, Long petId, String petName, Long customerId, String customerName, Long employeeId, String employeeName, LocalDate adoptionDate, String adoptionStatus, BigDecimal adoptionFee, LocalDateTime createdAt, LocalDateTime updatedAt) { + public AdoptionResponse(Long adoptionId, Long petId, String petName, Long customerId, String customerName, Long employeeId, String employeeName, Long sourceStoreId, String sourceStoreName, LocalDate adoptionDate, String adoptionStatus, BigDecimal adoptionFee, LocalDateTime createdAt, LocalDateTime updatedAt) { this.adoptionId = adoptionId; this.petId = petId; this.petName = petName; @@ -30,6 +32,8 @@ public class AdoptionResponse { this.customerName = customerName; this.employeeId = employeeId; this.employeeName = employeeName; + this.sourceStoreId = sourceStoreId; + this.sourceStoreName = sourceStoreName; this.adoptionDate = adoptionDate; this.adoptionStatus = adoptionStatus; this.adoptionFee = adoptionFee; @@ -93,6 +97,22 @@ public class AdoptionResponse { this.employeeName = employeeName; } + public Long getSourceStoreId() { + return sourceStoreId; + } + + public void setSourceStoreId(Long sourceStoreId) { + this.sourceStoreId = sourceStoreId; + } + + public String getSourceStoreName() { + return sourceStoreName; + } + + public void setSourceStoreName(String sourceStoreName) { + this.sourceStoreName = sourceStoreName; + } + public LocalDate getAdoptionDate() { return adoptionDate; } @@ -138,12 +158,12 @@ public class AdoptionResponse { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AdoptionResponse that = (AdoptionResponse) o; - return Objects.equals(adoptionId, that.adoptionId) && Objects.equals(petId, that.petId) && Objects.equals(petName, that.petName) && Objects.equals(customerId, that.customerId) && Objects.equals(customerName, that.customerName) && Objects.equals(adoptionDate, that.adoptionDate) && Objects.equals(adoptionStatus, that.adoptionStatus) && Objects.equals(adoptionFee, that.adoptionFee) && Objects.equals(createdAt, that.createdAt) && Objects.equals(updatedAt, that.updatedAt); + return Objects.equals(adoptionId, that.adoptionId) && Objects.equals(petId, that.petId) && Objects.equals(petName, that.petName) && Objects.equals(customerId, that.customerId) && Objects.equals(customerName, that.customerName) && Objects.equals(sourceStoreId, that.sourceStoreId) && Objects.equals(sourceStoreName, that.sourceStoreName) && Objects.equals(adoptionDate, that.adoptionDate) && Objects.equals(adoptionStatus, that.adoptionStatus) && Objects.equals(adoptionFee, that.adoptionFee) && Objects.equals(createdAt, that.createdAt) && Objects.equals(updatedAt, that.updatedAt); } @Override public int hashCode() { - return Objects.hash(adoptionId, petId, petName, customerId, customerName, adoptionDate, adoptionStatus, adoptionFee, createdAt, updatedAt); + return Objects.hash(adoptionId, petId, petName, customerId, customerName, sourceStoreId, sourceStoreName, adoptionDate, adoptionStatus, adoptionFee, createdAt, updatedAt); } @Override @@ -154,6 +174,8 @@ public class AdoptionResponse { ", petName='" + petName + '\'' + ", customerId=" + customerId + ", customerName='" + customerName + '\'' + + ", sourceStoreId=" + sourceStoreId + + ", sourceStoreName='" + sourceStoreName + '\'' + ", adoptionDate=" + adoptionDate + ", adoptionStatus='" + adoptionStatus + '\'' + ", adoptionFee=" + adoptionFee + diff --git a/backend/src/main/java/com/petshop/backend/entity/Adoption.java b/backend/src/main/java/com/petshop/backend/entity/Adoption.java index 35d4edac..e5dae5aa 100644 --- a/backend/src/main/java/com/petshop/backend/entity/Adoption.java +++ b/backend/src/main/java/com/petshop/backend/entity/Adoption.java @@ -28,6 +28,10 @@ public class Adoption { @JoinColumn(name = "employeeId", nullable = false) private User employee; + @ManyToOne + @JoinColumn(name = "sourceStoreId") + private StoreLocation sourceStore; + @Column(nullable = false) private LocalDate adoptionDate; @@ -77,6 +81,14 @@ public class Adoption { this.employee = employee; } + public StoreLocation getSourceStore() { + return sourceStore; + } + + public void setSourceStore(StoreLocation sourceStore) { + this.sourceStore = sourceStore; + } + public LocalDate getAdoptionDate() { return adoptionDate; } diff --git a/backend/src/main/java/com/petshop/backend/service/AdoptionService.java b/backend/src/main/java/com/petshop/backend/service/AdoptionService.java index caadfbb9..10b3fd02 100644 --- a/backend/src/main/java/com/petshop/backend/service/AdoptionService.java +++ b/backend/src/main/java/com/petshop/backend/service/AdoptionService.java @@ -5,10 +5,12 @@ import com.petshop.backend.dto.adoption.AdoptionResponse; import com.petshop.backend.dto.common.BulkDeleteRequest; import com.petshop.backend.entity.Adoption; import com.petshop.backend.entity.Pet; +import com.petshop.backend.entity.StoreLocation; import com.petshop.backend.entity.User; import com.petshop.backend.exception.ResourceNotFoundException; import com.petshop.backend.repository.AdoptionRepository; import com.petshop.backend.repository.PetRepository; +import com.petshop.backend.repository.StoreRepository; import com.petshop.backend.repository.UserRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -27,11 +29,13 @@ public class AdoptionService { private final AdoptionRepository adoptionRepository; private final PetRepository petRepository; private final UserRepository userRepository; + private final StoreRepository storeRepository; - public AdoptionService(AdoptionRepository adoptionRepository, PetRepository petRepository, UserRepository userRepository) { + public AdoptionService(AdoptionRepository adoptionRepository, PetRepository petRepository, UserRepository userRepository, StoreRepository storeRepository) { this.adoptionRepository = adoptionRepository; this.petRepository = petRepository; this.userRepository = userRepository; + this.storeRepository = storeRepository; } public Page getAllAdoptions(String query, Pageable pageable, Long customerId) { @@ -73,6 +77,10 @@ public class AdoptionService { User customer = userRepository.findById(request.getCustomerId()) .orElseThrow(() -> new ResourceNotFoundException("Customer not found with id: " + request.getCustomerId())); User employee = resolveAdoptionEmployee(request.getEmployeeId()); + StoreLocation sourceStore = request.getSourceStoreId() != null + ? storeRepository.findById(request.getSourceStoreId()) + .orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getSourceStoreId())) + : null; String adoptionStatus = normalizeAdoptionStatus(request.getAdoptionStatus()); validatePetAvailability(pet, null); @@ -80,6 +88,7 @@ public class AdoptionService { adoption.setPet(pet); adoption.setCustomer(customer); adoption.setEmployee(employee); + adoption.setSourceStore(sourceStore); adoption.setAdoptionDate(request.getAdoptionDate()); adoption.setAdoptionStatus(adoptionStatus); @@ -99,12 +108,17 @@ public class AdoptionService { User customer = userRepository.findById(request.getCustomerId()) .orElseThrow(() -> new ResourceNotFoundException("Customer not found with id: " + request.getCustomerId())); User employee = resolveAdoptionEmployee(request.getEmployeeId()); + StoreLocation sourceStore = request.getSourceStoreId() != null + ? storeRepository.findById(request.getSourceStoreId()) + .orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getSourceStoreId())) + : null; String adoptionStatus = normalizeAdoptionStatus(request.getAdoptionStatus()); validatePetAvailability(pet, adoption.getAdoptionId()); adoption.setPet(pet); adoption.setCustomer(customer); adoption.setEmployee(employee); + adoption.setSourceStore(sourceStore); adoption.setAdoptionDate(request.getAdoptionDate()); adoption.setAdoptionStatus(adoptionStatus); @@ -127,6 +141,7 @@ public class AdoptionService { } private AdoptionResponse mapToResponse(Adoption adoption) { + StoreLocation sourceStore = adoption.getSourceStore(); return new AdoptionResponse( adoption.getAdoptionId(), adoption.getPet().getPetId(), @@ -135,6 +150,8 @@ public class AdoptionService { adoption.getCustomer().getFirstName() + " " + adoption.getCustomer().getLastName(), adoption.getEmployee().getId(), adoption.getEmployee().getFirstName() + " " + adoption.getEmployee().getLastName(), + sourceStore != null ? sourceStore.getStoreId() : null, + sourceStore != null ? sourceStore.getStoreName() : null, adoption.getAdoptionDate(), adoption.getAdoptionStatus(), adoption.getPet().getPetPrice(),