loading employee in appointments and adoptions
changes in backend and android
This commit is contained in:
@@ -24,13 +24,14 @@ public class AdoptionAdapter extends RecyclerView.Adapter<AdoptionAdapter.Adopti
|
||||
}
|
||||
|
||||
public static class AdoptionViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView tvCustomerName, tvPetName, tvDate, tvFee, tvStatus;
|
||||
TextView tvCustomerName, tvPetName, tvDate, tvEmployee, tvFee, tvStatus;
|
||||
|
||||
public AdoptionViewHolder(@NonNull View v) {
|
||||
super(v);
|
||||
tvCustomerName = v.findViewById(R.id.tvAdoptionCustomerName);
|
||||
tvPetName = v.findViewById(R.id.tvAdoptionPetName);
|
||||
tvDate = v.findViewById(R.id.tvAdoptionDate);
|
||||
tvEmployee = v.findViewById(R.id.tvAdoptionEmployee);
|
||||
tvFee = v.findViewById(R.id.tvAdoptionFee);
|
||||
tvStatus = v.findViewById(R.id.tvAdoptionStatus);
|
||||
}
|
||||
@@ -52,7 +53,8 @@ public class AdoptionAdapter extends RecyclerView.Adapter<AdoptionAdapter.Adopti
|
||||
holder.tvPetName.setText("Pet: " + (a.getPetName() != null ? a.getPetName() : ""));
|
||||
holder.tvDate.setText("Date: " + (a.getAdoptionDate() != null ? a.getAdoptionDate() : ""));
|
||||
holder.tvFee.setText(a.getAdoptionFee() != null ? "$" + a.getAdoptionFee() : "");
|
||||
|
||||
holder.tvEmployee.setText("Staff: " +
|
||||
(a.getEmployeeName() != null ? a.getEmployeeName() : "Unassigned"));
|
||||
String status = a.getAdoptionStatus() != null ? a.getAdoptionStatus() : "";
|
||||
holder.tvStatus.setText(status);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class AppointmentAdapter extends RecyclerView.Adapter<AppointmentAdapter.
|
||||
}
|
||||
|
||||
public static class AppointmentViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView tvCustomerName, tvPetName, tvServiceType, tvDateTime, tvAppointmentStatus;
|
||||
TextView tvCustomerName, tvPetName, tvServiceType, tvDateTime,tvEmployee, tvAppointmentStatus;
|
||||
|
||||
public AppointmentViewHolder(@NonNull View v) {
|
||||
super(v);
|
||||
@@ -35,6 +35,7 @@ public class AppointmentAdapter extends RecyclerView.Adapter<AppointmentAdapter.
|
||||
tvPetName = v.findViewById(R.id.tvApptPetName);
|
||||
tvServiceType = v.findViewById(R.id.tvServiceType);
|
||||
tvDateTime = v.findViewById(R.id.tvDateTime);
|
||||
|
||||
tvAppointmentStatus = v.findViewById(R.id.tvAppointmentStatus);
|
||||
}
|
||||
}
|
||||
@@ -55,6 +56,7 @@ public class AppointmentAdapter extends RecyclerView.Adapter<AppointmentAdapter.
|
||||
holder.tvServiceType.setText(a.getServiceType() != null ? a.getServiceType() : "");
|
||||
holder.tvDateTime.setText((a.getAppointmentDate() != null ? a.getAppointmentDate() : "") +
|
||||
" at " + (a.getAppointmentTime() != null ? a.getAppointmentTime() : ""));
|
||||
holder.tvEmployee.setText("Staff: " + (a.getEmployeeName() != null ? a.getEmployeeName() : ""));
|
||||
|
||||
String status = a.getStatus() != null ? a.getStatus() : "";
|
||||
holder.tvAppointmentStatus.setText(status);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.example.petstoremobile.dtos;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class AdoptionDTO {
|
||||
|
||||
private Long adoptionId;
|
||||
private Long petId;
|
||||
private String petName;
|
||||
@@ -11,58 +12,85 @@ public class AdoptionDTO {
|
||||
private String adoptionDate;
|
||||
private String adoptionStatus;
|
||||
private BigDecimal adoptionFee;
|
||||
private Long employeeId;
|
||||
private String employeeName;
|
||||
private String createdAt;
|
||||
private String updatedAt;
|
||||
|
||||
// Constructor for create/update requests
|
||||
public AdoptionDTO(Long petId, Long customerId, String adoptionDate, String adoptionStatus) {
|
||||
public AdoptionDTO(Long petId, Long customerId, String adoptionDate, String adoptionStatus, Long employeeId) {
|
||||
this.petId = petId;
|
||||
this.customerId = customerId;
|
||||
this.adoptionDate = adoptionDate;
|
||||
this.adoptionStatus = adoptionStatus;
|
||||
this.employeeId = employeeId;
|
||||
}
|
||||
|
||||
public Long getAdoptionId() {
|
||||
|
||||
return adoptionId;
|
||||
}
|
||||
|
||||
public Long getPetId() {
|
||||
|
||||
return petId;
|
||||
}
|
||||
|
||||
public String getPetName() {
|
||||
|
||||
return petName;
|
||||
}
|
||||
|
||||
public Long getCustomerId() {
|
||||
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public String getCustomerName() {
|
||||
|
||||
return customerName;
|
||||
}
|
||||
|
||||
public String getAdoptionDate() {
|
||||
|
||||
return adoptionDate;
|
||||
}
|
||||
|
||||
public String getEmployeeName() {
|
||||
|
||||
return employeeName;
|
||||
}
|
||||
|
||||
public Long getEmployeeId() {
|
||||
return employeeId;
|
||||
}
|
||||
|
||||
public String getAdoptionStatus() {
|
||||
|
||||
return adoptionStatus;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
|
||||
return adoptionStatus;
|
||||
}
|
||||
|
||||
public BigDecimal getAdoptionFee() {
|
||||
|
||||
return adoptionFee;
|
||||
}
|
||||
|
||||
public String getCreatedAt() {
|
||||
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public String getUpdatedAt() {
|
||||
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -12,14 +12,20 @@ public class AppointmentDTO {
|
||||
private String storeName;
|
||||
private Long serviceId;
|
||||
private String serviceName;
|
||||
|
||||
private Long employeeId;
|
||||
private String employeeName;
|
||||
private String appointmentDate;
|
||||
private String appointmentTime;
|
||||
private String appointmentStatus;
|
||||
private List<String> petNames;
|
||||
private List<Long> petIds;
|
||||
|
||||
private String createdAt;
|
||||
private String updatedAt;
|
||||
|
||||
|
||||
|
||||
// Constructor for CREATE/UPDATE request body
|
||||
// Matches AppointmentRequest exactly
|
||||
public AppointmentDTO(Long customerId, Long storeId, Long serviceId,
|
||||
@@ -32,62 +38,79 @@ public class AppointmentDTO {
|
||||
this.appointmentTime = appointmentTime;
|
||||
this.appointmentStatus = appointmentStatus;
|
||||
this.petIds = petIds;
|
||||
this.employeeId = employeeId;
|
||||
}
|
||||
|
||||
// Getters
|
||||
public Long getAppointmentId() {
|
||||
|
||||
return appointmentId;
|
||||
}
|
||||
|
||||
public Long getCustomerId() {
|
||||
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public String getCustomerName() {
|
||||
|
||||
return customerName;
|
||||
}
|
||||
|
||||
public Long getStoreId() {
|
||||
|
||||
return storeId;
|
||||
}
|
||||
|
||||
public String getStoreName() {
|
||||
|
||||
return storeName;
|
||||
}
|
||||
|
||||
public Long getServiceId() {
|
||||
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
public String getServiceName() {
|
||||
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
public String getAppointmentDate() {
|
||||
|
||||
return appointmentDate;
|
||||
}
|
||||
|
||||
public String getAppointmentTime() {
|
||||
|
||||
return appointmentTime;
|
||||
}
|
||||
|
||||
public String getAppointmentStatus() {
|
||||
|
||||
return appointmentStatus;
|
||||
}
|
||||
|
||||
public List<String> getPetNames() {
|
||||
|
||||
return petNames;
|
||||
}
|
||||
|
||||
public List<Long> getPetIds() {
|
||||
|
||||
return petIds;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getCreatedAt() {
|
||||
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public String getUpdatedAt() {
|
||||
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
@@ -97,10 +120,12 @@ public class AppointmentDTO {
|
||||
}
|
||||
|
||||
public Long getPetID() {
|
||||
|
||||
return (petIds != null && !petIds.isEmpty()) ? petIds.get(0) : null;
|
||||
}
|
||||
|
||||
public Long getPetId() {
|
||||
|
||||
return getPetID();
|
||||
}
|
||||
|
||||
@@ -110,11 +135,20 @@ public class AppointmentDTO {
|
||||
}
|
||||
|
||||
public Long getServiceID() {
|
||||
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
public String getEmployeeName() {
|
||||
|
||||
return employeeName;
|
||||
}
|
||||
|
||||
// Status alias
|
||||
public String getStatus() {
|
||||
|
||||
return appointmentStatus;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -129,7 +129,8 @@ public class AdoptionFragment extends Fragment implements AdoptionAdapter.OnAdop
|
||||
args.putLong("customerId", a.getCustomerId() != null ? a.getCustomerId() : -1);
|
||||
args.putString("adoptionDate", a.getAdoptionDate());
|
||||
args.putString("adoptionStatus", a.getAdoptionStatus());
|
||||
}
|
||||
if (a.getEmployeeId() != null)
|
||||
args.putLong("employeeId", a.getEmployeeId());}
|
||||
|
||||
detail.setArguments(args);
|
||||
ListFragment lf = (ListFragment) getParentFragment();
|
||||
|
||||
@@ -19,7 +19,7 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
|
||||
private TextView tvMode, tvAdoptionId;
|
||||
private EditText etAdoptionDate;
|
||||
private Spinner spinnerPet, spinnerCustomer, spinnerStatus;
|
||||
private Spinner spinnerPet, spinnerCustomer, spinnerEmployee, spinnerStatus;
|
||||
private Button btnSave, btnDelete, btnBack;
|
||||
|
||||
private long adoptionId = -1;
|
||||
@@ -27,6 +27,9 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
private long preselectedPetId = -1;
|
||||
private long preselectedCustomerId = -1;
|
||||
|
||||
private List<EmployeeDTO> employeeList = new ArrayList<>();
|
||||
private long preselectedEmployeeId = -1;
|
||||
|
||||
private List<PetDTO> petList = new ArrayList<>();
|
||||
private List<CustomerDTO> customerList = new ArrayList<>();
|
||||
|
||||
@@ -54,6 +57,7 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
etAdoptionDate = v.findViewById(R.id.etAdoptionDate);
|
||||
spinnerPet = v.findViewById(R.id.spinnerAdoptionPet);
|
||||
spinnerCustomer= v.findViewById(R.id.spinnerAdoptionCustomer);
|
||||
spinnerEmployee = v.findViewById(R.id.spinnerAdoptionEmployee);
|
||||
spinnerStatus = v.findViewById(R.id.spinnerAdoptionStatus);
|
||||
btnSave = v.findViewById(R.id.btnSaveAdoption);
|
||||
btnDelete = v.findViewById(R.id.btnDeleteAdoption);
|
||||
@@ -80,6 +84,7 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
private void loadData() {
|
||||
loadPets();
|
||||
loadCustomers();
|
||||
loadEmployees();
|
||||
}
|
||||
|
||||
private void loadPets() {
|
||||
@@ -145,6 +150,34 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadEmployees() {
|
||||
RetrofitClient.getEmployeeApi(requireContext()).getAllEmployees(0, 100)
|
||||
.enqueue(new Callback<PageResponse<EmployeeDTO>>() {
|
||||
public void onResponse(Call<PageResponse<EmployeeDTO>> c,
|
||||
Response<PageResponse<EmployeeDTO>> r) {
|
||||
if (r.isSuccessful() && r.body() != null) {
|
||||
employeeList = r.body().getContent();
|
||||
List<String> names = new ArrayList<>();
|
||||
names.add("-- Select Employee --");
|
||||
for (EmployeeDTO e : employeeList)
|
||||
names.add(e.getFullName() + " (" + e.getRole() + ")");
|
||||
spinnerEmployee.setAdapter(new ArrayAdapter<>(requireContext(),
|
||||
android.R.layout.simple_spinner_item, names));
|
||||
if (preselectedEmployeeId != -1) {
|
||||
for (int i = 0; i < employeeList.size(); i++) {
|
||||
if (employeeList.get(i).getEmployeeId() == preselectedEmployeeId) {
|
||||
spinnerEmployee.setSelection(i + 1); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onFailure(Call<PageResponse<EmployeeDTO>> c, Throwable t) {
|
||||
Log.e("ADOPTION", "Employee load failed: " + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleArguments() {
|
||||
Bundle a = getArguments();
|
||||
if (a != null && a.containsKey("adoptionId")) {
|
||||
@@ -152,7 +185,7 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
adoptionId = a.getLong("adoptionId");
|
||||
preselectedPetId = a.getLong("petId", -1);
|
||||
preselectedCustomerId = a.getLong("customerId", -1);
|
||||
|
||||
preselectedEmployeeId = a.getLong("employeeId", -1);
|
||||
tvMode.setText("Edit Adoption");
|
||||
tvAdoptionId.setText("ID: " + adoptionId);
|
||||
tvAdoptionId.setVisibility(View.VISIBLE);
|
||||
@@ -180,6 +213,12 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
if (spinnerPet.getSelectedItemPosition() == 0) {
|
||||
Toast.makeText(getContext(), "Select a pet", Toast.LENGTH_SHORT).show(); return;
|
||||
}
|
||||
Long employeeId = null;
|
||||
if (spinnerEmployee.getSelectedItemPosition() > 0) {
|
||||
employeeId = employeeList
|
||||
.get(spinnerEmployee.getSelectedItemPosition() - 1)
|
||||
.getEmployeeId();
|
||||
}
|
||||
String date = etAdoptionDate.getText().toString().trim();
|
||||
if (date.isEmpty()) {
|
||||
Toast.makeText(getContext(), "Select a date", Toast.LENGTH_SHORT).show(); return;
|
||||
@@ -193,7 +232,8 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
pet.getPetId(),
|
||||
customer.getCustomerId(),
|
||||
date,
|
||||
status
|
||||
status,
|
||||
employeeId
|
||||
);
|
||||
|
||||
Log.d("ADOPTION_SAVE", "petId=" + pet.getPetId()
|
||||
|
||||
@@ -80,6 +80,21 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- Employee -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Assign Employee"
|
||||
android:textColor="@color/text_dark"
|
||||
android:textSize="12sp"
|
||||
android:layout_marginBottom="4dp"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinnerAdoptionEmployee"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- Pet -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -49,6 +49,14 @@
|
||||
android:textColor="@color/text_light"
|
||||
android:layout_marginTop="2dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAdoptionEmployee"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/text_light"
|
||||
android:layout_marginTop="2dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAdoptionFee"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -65,6 +65,14 @@
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAppointmentEmployee"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/text_light"
|
||||
android:layout_marginTop="2dp"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
|
||||
@@ -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