loading employee in appointments and adoptions
changes in backend and android
This commit is contained in:
@@ -12,6 +12,8 @@ public class AdoptionRequest {
|
||||
@NotNull(message = "Customer ID is required")
|
||||
private Long customerId;
|
||||
|
||||
private Long employeeId;
|
||||
|
||||
@NotNull(message = "Adoption date is required")
|
||||
private LocalDate adoptionDate;
|
||||
|
||||
@@ -34,6 +36,10 @@ public class AdoptionRequest {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
public Long getEmployeeId() { return employeeId; }
|
||||
|
||||
public void setEmployeeId(Long employeeId) { this.employeeId = employeeId; }
|
||||
|
||||
public LocalDate getAdoptionDate() {
|
||||
return adoptionDate;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ public class AdoptionResponse {
|
||||
private LocalDate adoptionDate;
|
||||
private String adoptionStatus;
|
||||
private BigDecimal adoptionFee;
|
||||
private Long employeeId;
|
||||
private String employeeName;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@@ -73,6 +75,22 @@ public class AdoptionResponse {
|
||||
this.customerName = customerName;
|
||||
}
|
||||
|
||||
public Long getEmployeeId() {
|
||||
return employeeId;
|
||||
}
|
||||
|
||||
public void setEmployeeId(Long employeeId) {
|
||||
this.employeeId = employeeId;
|
||||
}
|
||||
|
||||
public String getEmployeeName() {
|
||||
return employeeName;
|
||||
}
|
||||
|
||||
public void setEmployeeName(String employeeName) {
|
||||
this.employeeName = employeeName;
|
||||
}
|
||||
|
||||
public LocalDate getAdoptionDate() {
|
||||
return adoptionDate;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ public class AppointmentRequest {
|
||||
@NotEmpty(message = "At least one pet must be specified")
|
||||
private List<Long> petIds;
|
||||
|
||||
// @NotNull(message = "Employee ID is required")
|
||||
private Long employeeId;
|
||||
|
||||
public Long getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
@@ -85,6 +88,14 @@ public class AppointmentRequest {
|
||||
this.petIds = petIds;
|
||||
}
|
||||
|
||||
public Long getEmployeeId() {
|
||||
return employeeId;
|
||||
}
|
||||
|
||||
public void setEmployeeId(Long employeeId) {
|
||||
this.employeeId = employeeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -14,6 +14,8 @@ public class AppointmentResponse {
|
||||
private String storeName;
|
||||
private Long serviceId;
|
||||
private String serviceName;
|
||||
private Long employeeId;
|
||||
private String employeeName;
|
||||
private LocalDate appointmentDate;
|
||||
private LocalTime appointmentTime;
|
||||
private String appointmentStatus;
|
||||
@@ -25,7 +27,11 @@ public class AppointmentResponse {
|
||||
public AppointmentResponse() {
|
||||
}
|
||||
|
||||
public AppointmentResponse(Long appointmentId, Long customerId, String customerName, Long storeId, String storeName, Long serviceId, String serviceName, LocalDate appointmentDate, LocalTime appointmentTime, String appointmentStatus, List<String> petNames, List<Long> petIds, LocalDateTime createdAt, LocalDateTime updatedAt) {
|
||||
public AppointmentResponse(Long appointmentId, Long customerId, String customerName,
|
||||
Long storeId, String storeName, Long serviceId, String serviceName,
|
||||
LocalDate appointmentDate, LocalTime appointmentTime, String appointmentStatus,
|
||||
List<String> petNames, List<Long> petIds, LocalDateTime createdAt,
|
||||
LocalDateTime updatedAt, Long employeeId, String employeeName) {
|
||||
this.appointmentId = appointmentId;
|
||||
this.customerId = customerId;
|
||||
this.customerName = customerName;
|
||||
@@ -40,8 +46,9 @@ public class AppointmentResponse {
|
||||
this.petIds = petIds;
|
||||
this.createdAt = createdAt;
|
||||
this.updatedAt = updatedAt;
|
||||
this.employeeId = employeeId;
|
||||
this.employeeName = employeeName;
|
||||
}
|
||||
|
||||
public Long getAppointmentId() {
|
||||
return appointmentId;
|
||||
}
|
||||
@@ -98,14 +105,29 @@ public class AppointmentResponse {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
|
||||
public String getEmployeeName() {
|
||||
return employeeName;
|
||||
}
|
||||
public void setEmployeeName(String employeeName) {
|
||||
this.employeeName = employeeName;
|
||||
}
|
||||
|
||||
public LocalDate getAppointmentDate() {
|
||||
return appointmentDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void setAppointmentDate(LocalDate appointmentDate) {
|
||||
this.appointmentDate = appointmentDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public LocalTime getAppointmentTime() {
|
||||
return appointmentTime;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ public class Adoption {
|
||||
@JoinColumn(name = "customerId", nullable = false)
|
||||
private Customer customer;
|
||||
|
||||
@ManyToOne
|
||||
private Employee employee;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDate adoptionDate;
|
||||
|
||||
@@ -76,6 +79,14 @@ public class Adoption {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public Employee getEmployee() {
|
||||
return employee;
|
||||
}
|
||||
|
||||
public void setEmployee(Employee employee) {
|
||||
this.employee = employee;
|
||||
}
|
||||
|
||||
public LocalDate getAdoptionDate() {
|
||||
return adoptionDate;
|
||||
}
|
||||
@@ -133,4 +144,7 @@ public class Adoption {
|
||||
", updatedAt=" + updatedAt +
|
||||
'}';
|
||||
}
|
||||
|
||||
public void setEmployeeName(String s) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ public class Appointment {
|
||||
@JoinColumn(name = "serviceId", nullable = false)
|
||||
private Service service;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "employeeId")
|
||||
private Employee employee;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDate appointmentDate;
|
||||
|
||||
@@ -104,6 +108,14 @@ public class Appointment {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public Employee getEmployee() {
|
||||
return employee;
|
||||
}
|
||||
|
||||
public void setEmployee(Employee employee) {
|
||||
this.employee = employee;
|
||||
}
|
||||
|
||||
public LocalDate getAppointmentDate() {
|
||||
return appointmentDate;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ 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.Customer;
|
||||
import com.petshop.backend.entity.Employee;
|
||||
import com.petshop.backend.entity.Pet;
|
||||
import com.petshop.backend.exception.ResourceNotFoundException;
|
||||
import com.petshop.backend.repository.AdoptionRepository;
|
||||
@@ -14,6 +15,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.petshop.backend.repository.EmployeeRepository;
|
||||
|
||||
@Service
|
||||
public class AdoptionService {
|
||||
@@ -21,11 +23,15 @@ public class AdoptionService {
|
||||
private final AdoptionRepository adoptionRepository;
|
||||
private final PetRepository petRepository;
|
||||
private final CustomerRepository customerRepository;
|
||||
private final EmployeeRepository employeeRepository;
|
||||
private Adoption response;
|
||||
|
||||
public AdoptionService(AdoptionRepository adoptionRepository, PetRepository petRepository, CustomerRepository customerRepository) {
|
||||
public AdoptionService(AdoptionRepository adoptionRepository, PetRepository petRepository, CustomerRepository customerRepository, EmployeeRepository employeeRepository) {
|
||||
this.adoptionRepository = adoptionRepository;
|
||||
this.petRepository = petRepository;
|
||||
this.customerRepository = customerRepository;
|
||||
this.employeeRepository = employeeRepository;
|
||||
|
||||
}
|
||||
|
||||
public Page<AdoptionResponse> getAllAdoptions(String query, Pageable pageable, Long customerId) {
|
||||
@@ -73,6 +79,7 @@ public class AdoptionService {
|
||||
adoption.setAdoptionDate(request.getAdoptionDate());
|
||||
adoption.setAdoptionStatus(request.getAdoptionStatus());
|
||||
|
||||
|
||||
adoption = adoptionRepository.save(adoption);
|
||||
return mapToResponse(adoption);
|
||||
}
|
||||
@@ -92,7 +99,12 @@ public class AdoptionService {
|
||||
adoption.setCustomer(customer);
|
||||
adoption.setAdoptionDate(request.getAdoptionDate());
|
||||
adoption.setAdoptionStatus(request.getAdoptionStatus());
|
||||
|
||||
if (request.getEmployeeId() != null) {
|
||||
Employee employee = employeeRepository.findById(request.getEmployeeId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(
|
||||
"Employee not found with id: " + request.getEmployeeId()));
|
||||
adoption.setEmployee(employee);
|
||||
}
|
||||
adoption = adoptionRepository.save(adoption);
|
||||
return mapToResponse(adoption);
|
||||
}
|
||||
@@ -111,17 +123,27 @@ public class AdoptionService {
|
||||
}
|
||||
|
||||
private AdoptionResponse mapToResponse(Adoption adoption) {
|
||||
return new AdoptionResponse(
|
||||
adoption.getAdoptionId(),
|
||||
adoption.getPet().getPetId(),
|
||||
adoption.getPet().getPetName(),
|
||||
adoption.getCustomer().getCustomerId(),
|
||||
adoption.getCustomer().getFirstName() + " " + adoption.getCustomer().getLastName(),
|
||||
adoption.getAdoptionDate(),
|
||||
adoption.getAdoptionStatus(),
|
||||
adoption.getPet().getPetPrice(),
|
||||
adoption.getCreatedAt(),
|
||||
adoption.getUpdatedAt()
|
||||
AdoptionResponse response = new AdoptionResponse(
|
||||
adoption.getAdoptionId(),
|
||||
adoption.getPet().getPetId(),
|
||||
adoption.getPet().getPetName(),
|
||||
adoption.getCustomer().getCustomerId(),
|
||||
adoption.getCustomer().getFirstName() + " " + adoption.getCustomer().getLastName(),
|
||||
adoption.getAdoptionDate(),
|
||||
adoption.getAdoptionStatus(),
|
||||
adoption.getPet().getPetPrice(),
|
||||
adoption.getCreatedAt(),
|
||||
adoption.getUpdatedAt()
|
||||
);
|
||||
// Add employee name
|
||||
if (adoption.getEmployee() != null) {
|
||||
response.setEmployeeId(adoption.getEmployee().getEmployeeId());
|
||||
response.setEmployeeName(
|
||||
adoption.getEmployee().getFirstName() + " " +
|
||||
adoption.getEmployee().getLastName());
|
||||
} else {
|
||||
response.setEmployeeName("Unassigned");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +98,16 @@ public class AppointmentService {
|
||||
Customer customer = customerRepository.findById(request.getCustomerId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException("Customer not found with id: " + request.getCustomerId()));
|
||||
|
||||
Employee employee;
|
||||
if (request.getEmployeeId() != null) {
|
||||
employee = employeeRepository.findById(request.getEmployeeId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException(
|
||||
"Employee not found with id: " + request.getEmployeeId()));
|
||||
} else {
|
||||
employee = AuthenticationHelper.getAuthenticatedEmployee(
|
||||
userRepository, employeeRepository);
|
||||
}
|
||||
|
||||
StoreLocation store = storeRepository.findById(request.getStoreId())
|
||||
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getStoreId()));
|
||||
|
||||
@@ -113,6 +123,7 @@ public class AppointmentService {
|
||||
appointment.setCustomer(customer);
|
||||
appointment.setStore(store);
|
||||
appointment.setService(service);
|
||||
appointment.setEmployee(employee);
|
||||
appointment.setAppointmentDate(request.getAppointmentDate());
|
||||
appointment.setAppointmentTime(request.getAppointmentTime());
|
||||
appointment.setAppointmentStatus(request.getAppointmentStatus());
|
||||
@@ -246,7 +257,13 @@ public class AppointmentService {
|
||||
petNames,
|
||||
petIds,
|
||||
appointment.getCreatedAt(),
|
||||
appointment.getUpdatedAt()
|
||||
appointment.getUpdatedAt(),
|
||||
appointment.getEmployee() != null ? appointment.getEmployee().getEmployeeId() : null,
|
||||
appointment.getEmployee() != null ?
|
||||
appointment.getEmployee().getFirstName() + " " + appointment.getEmployee().getLastName()
|
||||
: "Unassigned"
|
||||
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user