add adoption sourceStore FK

This commit is contained in:
2026-04-06 20:28:31 -06:00
parent 3f6dc132f4
commit 969fbdfe8b
4 changed files with 69 additions and 6 deletions

View File

@@ -20,6 +20,8 @@ public class AdoptionRequest {
private Long employeeId; private Long employeeId;
private Long sourceStoreId;
public Long getPetId() { public Long getPetId() {
return petId; return petId;
} }
@@ -60,6 +62,14 @@ public class AdoptionRequest {
this.employeeId = employeeId; this.employeeId = employeeId;
} }
public Long getSourceStoreId() {
return sourceStoreId;
}
public void setSourceStoreId(Long sourceStoreId) {
this.sourceStoreId = sourceStoreId;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@@ -69,12 +79,13 @@ public class AdoptionRequest {
Objects.equals(customerId, that.customerId) && Objects.equals(customerId, that.customerId) &&
Objects.equals(adoptionDate, that.adoptionDate) && Objects.equals(adoptionDate, that.adoptionDate) &&
Objects.equals(adoptionStatus, that.adoptionStatus) && Objects.equals(adoptionStatus, that.adoptionStatus) &&
Objects.equals(employeeId, that.employeeId); Objects.equals(employeeId, that.employeeId) &&
Objects.equals(sourceStoreId, that.sourceStoreId);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(petId, customerId, adoptionDate, adoptionStatus, employeeId); return Objects.hash(petId, customerId, adoptionDate, adoptionStatus, employeeId, sourceStoreId);
} }
@Override @Override
@@ -85,6 +96,7 @@ public class AdoptionRequest {
", adoptionDate=" + adoptionDate + ", adoptionDate=" + adoptionDate +
", adoptionStatus='" + adoptionStatus + '\'' + ", adoptionStatus='" + adoptionStatus + '\'' +
", employeeId=" + employeeId + ", employeeId=" + employeeId +
", sourceStoreId=" + sourceStoreId +
'}'; '}';
} }
} }

View File

@@ -13,6 +13,8 @@ public class AdoptionResponse {
private String customerName; private String customerName;
private Long employeeId; private Long employeeId;
private String employeeName; private String employeeName;
private Long sourceStoreId;
private String sourceStoreName;
private LocalDate adoptionDate; private LocalDate adoptionDate;
private String adoptionStatus; private String adoptionStatus;
private BigDecimal adoptionFee; private BigDecimal adoptionFee;
@@ -22,7 +24,7 @@ public class AdoptionResponse {
public 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.adoptionId = adoptionId;
this.petId = petId; this.petId = petId;
this.petName = petName; this.petName = petName;
@@ -30,6 +32,8 @@ public class AdoptionResponse {
this.customerName = customerName; this.customerName = customerName;
this.employeeId = employeeId; this.employeeId = employeeId;
this.employeeName = employeeName; this.employeeName = employeeName;
this.sourceStoreId = sourceStoreId;
this.sourceStoreName = sourceStoreName;
this.adoptionDate = adoptionDate; this.adoptionDate = adoptionDate;
this.adoptionStatus = adoptionStatus; this.adoptionStatus = adoptionStatus;
this.adoptionFee = adoptionFee; this.adoptionFee = adoptionFee;
@@ -93,6 +97,22 @@ public class AdoptionResponse {
this.employeeName = employeeName; 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() { public LocalDate getAdoptionDate() {
return adoptionDate; return adoptionDate;
} }
@@ -138,12 +158,12 @@ public class AdoptionResponse {
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;
AdoptionResponse that = (AdoptionResponse) o; 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 @Override
public int hashCode() { 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 @Override
@@ -154,6 +174,8 @@ public class AdoptionResponse {
", petName='" + petName + '\'' + ", petName='" + petName + '\'' +
", customerId=" + customerId + ", customerId=" + customerId +
", customerName='" + customerName + '\'' + ", customerName='" + customerName + '\'' +
", sourceStoreId=" + sourceStoreId +
", sourceStoreName='" + sourceStoreName + '\'' +
", adoptionDate=" + adoptionDate + ", adoptionDate=" + adoptionDate +
", adoptionStatus='" + adoptionStatus + '\'' + ", adoptionStatus='" + adoptionStatus + '\'' +
", adoptionFee=" + adoptionFee + ", adoptionFee=" + adoptionFee +

View File

@@ -28,6 +28,10 @@ public class Adoption {
@JoinColumn(name = "employeeId", nullable = false) @JoinColumn(name = "employeeId", nullable = false)
private User employee; private User employee;
@ManyToOne
@JoinColumn(name = "sourceStoreId")
private StoreLocation sourceStore;
@Column(nullable = false) @Column(nullable = false)
private LocalDate adoptionDate; private LocalDate adoptionDate;
@@ -77,6 +81,14 @@ public class Adoption {
this.employee = employee; this.employee = employee;
} }
public StoreLocation getSourceStore() {
return sourceStore;
}
public void setSourceStore(StoreLocation sourceStore) {
this.sourceStore = sourceStore;
}
public LocalDate getAdoptionDate() { public LocalDate getAdoptionDate() {
return adoptionDate; return adoptionDate;
} }

View File

@@ -5,10 +5,12 @@ import com.petshop.backend.dto.adoption.AdoptionResponse;
import com.petshop.backend.dto.common.BulkDeleteRequest; import com.petshop.backend.dto.common.BulkDeleteRequest;
import com.petshop.backend.entity.Adoption; import com.petshop.backend.entity.Adoption;
import com.petshop.backend.entity.Pet; import com.petshop.backend.entity.Pet;
import com.petshop.backend.entity.StoreLocation;
import com.petshop.backend.entity.User; import com.petshop.backend.entity.User;
import com.petshop.backend.exception.ResourceNotFoundException; import com.petshop.backend.exception.ResourceNotFoundException;
import com.petshop.backend.repository.AdoptionRepository; import com.petshop.backend.repository.AdoptionRepository;
import com.petshop.backend.repository.PetRepository; import com.petshop.backend.repository.PetRepository;
import com.petshop.backend.repository.StoreRepository;
import com.petshop.backend.repository.UserRepository; import com.petshop.backend.repository.UserRepository;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@@ -27,11 +29,13 @@ public class AdoptionService {
private final AdoptionRepository adoptionRepository; private final AdoptionRepository adoptionRepository;
private final PetRepository petRepository; private final PetRepository petRepository;
private final UserRepository userRepository; 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.adoptionRepository = adoptionRepository;
this.petRepository = petRepository; this.petRepository = petRepository;
this.userRepository = userRepository; this.userRepository = userRepository;
this.storeRepository = storeRepository;
} }
public Page<AdoptionResponse> getAllAdoptions(String query, Pageable pageable, Long customerId) { public Page<AdoptionResponse> getAllAdoptions(String query, Pageable pageable, Long customerId) {
@@ -73,6 +77,10 @@ public class AdoptionService {
User customer = userRepository.findById(request.getCustomerId()) User customer = userRepository.findById(request.getCustomerId())
.orElseThrow(() -> new ResourceNotFoundException("Customer not found with id: " + request.getCustomerId())); .orElseThrow(() -> new ResourceNotFoundException("Customer not found with id: " + request.getCustomerId()));
User employee = resolveAdoptionEmployee(request.getEmployeeId()); 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()); String adoptionStatus = normalizeAdoptionStatus(request.getAdoptionStatus());
validatePetAvailability(pet, null); validatePetAvailability(pet, null);
@@ -80,6 +88,7 @@ public class AdoptionService {
adoption.setPet(pet); adoption.setPet(pet);
adoption.setCustomer(customer); adoption.setCustomer(customer);
adoption.setEmployee(employee); adoption.setEmployee(employee);
adoption.setSourceStore(sourceStore);
adoption.setAdoptionDate(request.getAdoptionDate()); adoption.setAdoptionDate(request.getAdoptionDate());
adoption.setAdoptionStatus(adoptionStatus); adoption.setAdoptionStatus(adoptionStatus);
@@ -99,12 +108,17 @@ public class AdoptionService {
User customer = userRepository.findById(request.getCustomerId()) User customer = userRepository.findById(request.getCustomerId())
.orElseThrow(() -> new ResourceNotFoundException("Customer not found with id: " + request.getCustomerId())); .orElseThrow(() -> new ResourceNotFoundException("Customer not found with id: " + request.getCustomerId()));
User employee = resolveAdoptionEmployee(request.getEmployeeId()); 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()); String adoptionStatus = normalizeAdoptionStatus(request.getAdoptionStatus());
validatePetAvailability(pet, adoption.getAdoptionId()); validatePetAvailability(pet, adoption.getAdoptionId());
adoption.setPet(pet); adoption.setPet(pet);
adoption.setCustomer(customer); adoption.setCustomer(customer);
adoption.setEmployee(employee); adoption.setEmployee(employee);
adoption.setSourceStore(sourceStore);
adoption.setAdoptionDate(request.getAdoptionDate()); adoption.setAdoptionDate(request.getAdoptionDate());
adoption.setAdoptionStatus(adoptionStatus); adoption.setAdoptionStatus(adoptionStatus);
@@ -127,6 +141,7 @@ public class AdoptionService {
} }
private AdoptionResponse mapToResponse(Adoption adoption) { private AdoptionResponse mapToResponse(Adoption adoption) {
StoreLocation sourceStore = adoption.getSourceStore();
return new AdoptionResponse( return new AdoptionResponse(
adoption.getAdoptionId(), adoption.getAdoptionId(),
adoption.getPet().getPetId(), adoption.getPet().getPetId(),
@@ -135,6 +150,8 @@ public class AdoptionService {
adoption.getCustomer().getFirstName() + " " + adoption.getCustomer().getLastName(), adoption.getCustomer().getFirstName() + " " + adoption.getCustomer().getLastName(),
adoption.getEmployee().getId(), adoption.getEmployee().getId(),
adoption.getEmployee().getFirstName() + " " + adoption.getEmployee().getLastName(), adoption.getEmployee().getFirstName() + " " + adoption.getEmployee().getLastName(),
sourceStore != null ? sourceStore.getStoreId() : null,
sourceStore != null ? sourceStore.getStoreName() : null,
adoption.getAdoptionDate(), adoption.getAdoptionDate(),
adoption.getAdoptionStatus(), adoption.getAdoptionStatus(),
adoption.getPet().getPetPrice(), adoption.getPet().getPetPrice(),