loading employee in appointments and adoptions

changes in backend and android
This commit is contained in:
Nikitha
2026-04-07 08:43:49 -06:00
parent ff53e4a1ec
commit d3b9d28513
17 changed files with 284 additions and 24 deletions

View File

@@ -24,13 +24,14 @@ public class AdoptionAdapter extends RecyclerView.Adapter<AdoptionAdapter.Adopti
} }
public static class AdoptionViewHolder extends RecyclerView.ViewHolder { 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) { public AdoptionViewHolder(@NonNull View v) {
super(v); super(v);
tvCustomerName = v.findViewById(R.id.tvAdoptionCustomerName); tvCustomerName = v.findViewById(R.id.tvAdoptionCustomerName);
tvPetName = v.findViewById(R.id.tvAdoptionPetName); tvPetName = v.findViewById(R.id.tvAdoptionPetName);
tvDate = v.findViewById(R.id.tvAdoptionDate); tvDate = v.findViewById(R.id.tvAdoptionDate);
tvEmployee = v.findViewById(R.id.tvAdoptionEmployee);
tvFee = v.findViewById(R.id.tvAdoptionFee); tvFee = v.findViewById(R.id.tvAdoptionFee);
tvStatus = v.findViewById(R.id.tvAdoptionStatus); 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.tvPetName.setText("Pet: " + (a.getPetName() != null ? a.getPetName() : ""));
holder.tvDate.setText("Date: " + (a.getAdoptionDate() != null ? a.getAdoptionDate() : "")); holder.tvDate.setText("Date: " + (a.getAdoptionDate() != null ? a.getAdoptionDate() : ""));
holder.tvFee.setText(a.getAdoptionFee() != null ? "$" + a.getAdoptionFee() : ""); 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() : ""; String status = a.getAdoptionStatus() != null ? a.getAdoptionStatus() : "";
holder.tvStatus.setText(status); holder.tvStatus.setText(status);

View File

@@ -27,7 +27,7 @@ public class AppointmentAdapter extends RecyclerView.Adapter<AppointmentAdapter.
} }
public static class AppointmentViewHolder extends RecyclerView.ViewHolder { 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) { public AppointmentViewHolder(@NonNull View v) {
super(v); super(v);
@@ -35,6 +35,7 @@ public class AppointmentAdapter extends RecyclerView.Adapter<AppointmentAdapter.
tvPetName = v.findViewById(R.id.tvApptPetName); tvPetName = v.findViewById(R.id.tvApptPetName);
tvServiceType = v.findViewById(R.id.tvServiceType); tvServiceType = v.findViewById(R.id.tvServiceType);
tvDateTime = v.findViewById(R.id.tvDateTime); tvDateTime = v.findViewById(R.id.tvDateTime);
tvAppointmentStatus = v.findViewById(R.id.tvAppointmentStatus); 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.tvServiceType.setText(a.getServiceType() != null ? a.getServiceType() : "");
holder.tvDateTime.setText((a.getAppointmentDate() != null ? a.getAppointmentDate() : "") + holder.tvDateTime.setText((a.getAppointmentDate() != null ? a.getAppointmentDate() : "") +
" at " + (a.getAppointmentTime() != null ? a.getAppointmentTime() : "")); " at " + (a.getAppointmentTime() != null ? a.getAppointmentTime() : ""));
holder.tvEmployee.setText("Staff: " + (a.getEmployeeName() != null ? a.getEmployeeName() : ""));
String status = a.getStatus() != null ? a.getStatus() : ""; String status = a.getStatus() != null ? a.getStatus() : "";
holder.tvAppointmentStatus.setText(status); holder.tvAppointmentStatus.setText(status);

View File

@@ -3,6 +3,7 @@ package com.example.petstoremobile.dtos;
import java.math.BigDecimal; import java.math.BigDecimal;
public class AdoptionDTO { public class AdoptionDTO {
private Long adoptionId; private Long adoptionId;
private Long petId; private Long petId;
private String petName; private String petName;
@@ -11,58 +12,85 @@ public class AdoptionDTO {
private String adoptionDate; private String adoptionDate;
private String adoptionStatus; private String adoptionStatus;
private BigDecimal adoptionFee; private BigDecimal adoptionFee;
private Long employeeId;
private String employeeName;
private String createdAt; private String createdAt;
private String updatedAt; private String updatedAt;
// Constructor for create/update requests // 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.petId = petId;
this.customerId = customerId; this.customerId = customerId;
this.adoptionDate = adoptionDate; this.adoptionDate = adoptionDate;
this.adoptionStatus = adoptionStatus; this.adoptionStatus = adoptionStatus;
this.employeeId = employeeId;
} }
public Long getAdoptionId() { public Long getAdoptionId() {
return adoptionId; return adoptionId;
} }
public Long getPetId() { public Long getPetId() {
return petId; return petId;
} }
public String getPetName() { public String getPetName() {
return petName; return petName;
} }
public Long getCustomerId() { public Long getCustomerId() {
return customerId; return customerId;
} }
public String getCustomerName() { public String getCustomerName() {
return customerName; return customerName;
} }
public String getAdoptionDate() { public String getAdoptionDate() {
return adoptionDate; return adoptionDate;
} }
public String getEmployeeName() {
return employeeName;
}
public Long getEmployeeId() {
return employeeId;
}
public String getAdoptionStatus() { public String getAdoptionStatus() {
return adoptionStatus; return adoptionStatus;
} }
public String getStatus() { public String getStatus() {
return adoptionStatus; return adoptionStatus;
} }
public BigDecimal getAdoptionFee() { public BigDecimal getAdoptionFee() {
return adoptionFee; return adoptionFee;
} }
public String getCreatedAt() { public String getCreatedAt() {
return createdAt; return createdAt;
} }
public String getUpdatedAt() { public String getUpdatedAt() {
return updatedAt; return updatedAt;
} }
} }

View File

@@ -12,14 +12,20 @@ public class AppointmentDTO {
private String storeName; private String storeName;
private Long serviceId; private Long serviceId;
private String serviceName; private String serviceName;
private Long employeeId;
private String employeeName;
private String appointmentDate; private String appointmentDate;
private String appointmentTime; private String appointmentTime;
private String appointmentStatus; private String appointmentStatus;
private List<String> petNames; private List<String> petNames;
private List<Long> petIds; private List<Long> petIds;
private String createdAt; private String createdAt;
private String updatedAt; private String updatedAt;
// Constructor for CREATE/UPDATE request body // Constructor for CREATE/UPDATE request body
// Matches AppointmentRequest exactly // Matches AppointmentRequest exactly
public AppointmentDTO(Long customerId, Long storeId, Long serviceId, public AppointmentDTO(Long customerId, Long storeId, Long serviceId,
@@ -32,62 +38,79 @@ public class AppointmentDTO {
this.appointmentTime = appointmentTime; this.appointmentTime = appointmentTime;
this.appointmentStatus = appointmentStatus; this.appointmentStatus = appointmentStatus;
this.petIds = petIds; this.petIds = petIds;
this.employeeId = employeeId;
} }
// Getters // Getters
public Long getAppointmentId() { public Long getAppointmentId() {
return appointmentId; return appointmentId;
} }
public Long getCustomerId() { public Long getCustomerId() {
return customerId; return customerId;
} }
public String getCustomerName() { public String getCustomerName() {
return customerName; return customerName;
} }
public Long getStoreId() { public Long getStoreId() {
return storeId; return storeId;
} }
public String getStoreName() { public String getStoreName() {
return storeName; return storeName;
} }
public Long getServiceId() { public Long getServiceId() {
return serviceId; return serviceId;
} }
public String getServiceName() { public String getServiceName() {
return serviceName; return serviceName;
} }
public String getAppointmentDate() { public String getAppointmentDate() {
return appointmentDate; return appointmentDate;
} }
public String getAppointmentTime() { public String getAppointmentTime() {
return appointmentTime; return appointmentTime;
} }
public String getAppointmentStatus() { public String getAppointmentStatus() {
return appointmentStatus; return appointmentStatus;
} }
public List<String> getPetNames() { public List<String> getPetNames() {
return petNames; return petNames;
} }
public List<Long> getPetIds() { public List<Long> getPetIds() {
return petIds; return petIds;
} }
public String getCreatedAt() { public String getCreatedAt() {
return createdAt; return createdAt;
} }
public String getUpdatedAt() { public String getUpdatedAt() {
return updatedAt; return updatedAt;
} }
@@ -97,10 +120,12 @@ public class AppointmentDTO {
} }
public Long getPetID() { public Long getPetID() {
return (petIds != null && !petIds.isEmpty()) ? petIds.get(0) : null; return (petIds != null && !petIds.isEmpty()) ? petIds.get(0) : null;
} }
public Long getPetId() { public Long getPetId() {
return getPetID(); return getPetID();
} }
@@ -110,11 +135,20 @@ public class AppointmentDTO {
} }
public Long getServiceID() { public Long getServiceID() {
return serviceId; return serviceId;
} }
public String getEmployeeName() {
return employeeName;
}
// Status alias // Status alias
public String getStatus() { public String getStatus() {
return appointmentStatus; return appointmentStatus;
} }
} }

View File

@@ -129,7 +129,8 @@ public class AdoptionFragment extends Fragment implements AdoptionAdapter.OnAdop
args.putLong("customerId", a.getCustomerId() != null ? a.getCustomerId() : -1); args.putLong("customerId", a.getCustomerId() != null ? a.getCustomerId() : -1);
args.putString("adoptionDate", a.getAdoptionDate()); args.putString("adoptionDate", a.getAdoptionDate());
args.putString("adoptionStatus", a.getAdoptionStatus()); args.putString("adoptionStatus", a.getAdoptionStatus());
} if (a.getEmployeeId() != null)
args.putLong("employeeId", a.getEmployeeId());}
detail.setArguments(args); detail.setArguments(args);
ListFragment lf = (ListFragment) getParentFragment(); ListFragment lf = (ListFragment) getParentFragment();

View File

@@ -19,7 +19,7 @@ public class AdoptionDetailFragment extends Fragment {
private TextView tvMode, tvAdoptionId; private TextView tvMode, tvAdoptionId;
private EditText etAdoptionDate; private EditText etAdoptionDate;
private Spinner spinnerPet, spinnerCustomer, spinnerStatus; private Spinner spinnerPet, spinnerCustomer, spinnerEmployee, spinnerStatus;
private Button btnSave, btnDelete, btnBack; private Button btnSave, btnDelete, btnBack;
private long adoptionId = -1; private long adoptionId = -1;
@@ -27,6 +27,9 @@ public class AdoptionDetailFragment extends Fragment {
private long preselectedPetId = -1; private long preselectedPetId = -1;
private long preselectedCustomerId = -1; private long preselectedCustomerId = -1;
private List<EmployeeDTO> employeeList = new ArrayList<>();
private long preselectedEmployeeId = -1;
private List<PetDTO> petList = new ArrayList<>(); private List<PetDTO> petList = new ArrayList<>();
private List<CustomerDTO> customerList = new ArrayList<>(); private List<CustomerDTO> customerList = new ArrayList<>();
@@ -54,6 +57,7 @@ public class AdoptionDetailFragment extends Fragment {
etAdoptionDate = v.findViewById(R.id.etAdoptionDate); etAdoptionDate = v.findViewById(R.id.etAdoptionDate);
spinnerPet = v.findViewById(R.id.spinnerAdoptionPet); spinnerPet = v.findViewById(R.id.spinnerAdoptionPet);
spinnerCustomer= v.findViewById(R.id.spinnerAdoptionCustomer); spinnerCustomer= v.findViewById(R.id.spinnerAdoptionCustomer);
spinnerEmployee = v.findViewById(R.id.spinnerAdoptionEmployee);
spinnerStatus = v.findViewById(R.id.spinnerAdoptionStatus); spinnerStatus = v.findViewById(R.id.spinnerAdoptionStatus);
btnSave = v.findViewById(R.id.btnSaveAdoption); btnSave = v.findViewById(R.id.btnSaveAdoption);
btnDelete = v.findViewById(R.id.btnDeleteAdoption); btnDelete = v.findViewById(R.id.btnDeleteAdoption);
@@ -80,6 +84,7 @@ public class AdoptionDetailFragment extends Fragment {
private void loadData() { private void loadData() {
loadPets(); loadPets();
loadCustomers(); loadCustomers();
loadEmployees();
} }
private void loadPets() { 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() { private void handleArguments() {
Bundle a = getArguments(); Bundle a = getArguments();
if (a != null && a.containsKey("adoptionId")) { if (a != null && a.containsKey("adoptionId")) {
@@ -152,7 +185,7 @@ public class AdoptionDetailFragment extends Fragment {
adoptionId = a.getLong("adoptionId"); adoptionId = a.getLong("adoptionId");
preselectedPetId = a.getLong("petId", -1); preselectedPetId = a.getLong("petId", -1);
preselectedCustomerId = a.getLong("customerId", -1); preselectedCustomerId = a.getLong("customerId", -1);
preselectedEmployeeId = a.getLong("employeeId", -1);
tvMode.setText("Edit Adoption"); tvMode.setText("Edit Adoption");
tvAdoptionId.setText("ID: " + adoptionId); tvAdoptionId.setText("ID: " + adoptionId);
tvAdoptionId.setVisibility(View.VISIBLE); tvAdoptionId.setVisibility(View.VISIBLE);
@@ -180,6 +213,12 @@ public class AdoptionDetailFragment extends Fragment {
if (spinnerPet.getSelectedItemPosition() == 0) { if (spinnerPet.getSelectedItemPosition() == 0) {
Toast.makeText(getContext(), "Select a pet", Toast.LENGTH_SHORT).show(); return; 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(); String date = etAdoptionDate.getText().toString().trim();
if (date.isEmpty()) { if (date.isEmpty()) {
Toast.makeText(getContext(), "Select a date", Toast.LENGTH_SHORT).show(); return; Toast.makeText(getContext(), "Select a date", Toast.LENGTH_SHORT).show(); return;
@@ -193,7 +232,8 @@ public class AdoptionDetailFragment extends Fragment {
pet.getPetId(), pet.getPetId(),
customer.getCustomerId(), customer.getCustomerId(),
date, date,
status status,
employeeId
); );
Log.d("ADOPTION_SAVE", "petId=" + pet.getPetId() Log.d("ADOPTION_SAVE", "petId=" + pet.getPetId()

View File

@@ -80,6 +80,21 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp"/> 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 --> <!-- Pet -->
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -49,6 +49,14 @@
android:textColor="@color/text_light" android:textColor="@color/text_light"
android:layout_marginTop="2dp"/> 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 <TextView
android:id="@+id/tvAdoptionFee" android:id="@+id/tvAdoptionFee"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -65,6 +65,14 @@
android:textSize="14sp" android:textSize="14sp"
android:textStyle="bold" /> 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 <View
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"

View File

@@ -12,6 +12,8 @@ public class AdoptionRequest {
@NotNull(message = "Customer ID is required") @NotNull(message = "Customer ID is required")
private Long customerId; private Long customerId;
private Long employeeId;
@NotNull(message = "Adoption date is required") @NotNull(message = "Adoption date is required")
private LocalDate adoptionDate; private LocalDate adoptionDate;
@@ -34,6 +36,10 @@ public class AdoptionRequest {
this.customerId = customerId; this.customerId = customerId;
} }
public Long getEmployeeId() { return employeeId; }
public void setEmployeeId(Long employeeId) { this.employeeId = employeeId; }
public LocalDate getAdoptionDate() { public LocalDate getAdoptionDate() {
return adoptionDate; return adoptionDate;
} }

View File

@@ -14,6 +14,8 @@ public class AdoptionResponse {
private LocalDate adoptionDate; private LocalDate adoptionDate;
private String adoptionStatus; private String adoptionStatus;
private BigDecimal adoptionFee; private BigDecimal adoptionFee;
private Long employeeId;
private String employeeName;
private LocalDateTime createdAt; private LocalDateTime createdAt;
private LocalDateTime updatedAt; private LocalDateTime updatedAt;
@@ -73,6 +75,22 @@ public class AdoptionResponse {
this.customerName = customerName; 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() { public LocalDate getAdoptionDate() {
return adoptionDate; return adoptionDate;
} }

View File

@@ -29,6 +29,9 @@ public class AppointmentRequest {
@NotEmpty(message = "At least one pet must be specified") @NotEmpty(message = "At least one pet must be specified")
private List<Long> petIds; private List<Long> petIds;
// @NotNull(message = "Employee ID is required")
private Long employeeId;
public Long getCustomerId() { public Long getCustomerId() {
return customerId; return customerId;
} }
@@ -85,6 +88,14 @@ public class AppointmentRequest {
this.petIds = petIds; this.petIds = petIds;
} }
public Long getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Long employeeId) {
this.employeeId = employeeId;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@@ -14,6 +14,8 @@ public class AppointmentResponse {
private String storeName; private String storeName;
private Long serviceId; private Long serviceId;
private String serviceName; private String serviceName;
private Long employeeId;
private String employeeName;
private LocalDate appointmentDate; private LocalDate appointmentDate;
private LocalTime appointmentTime; private LocalTime appointmentTime;
private String appointmentStatus; private String appointmentStatus;
@@ -25,7 +27,11 @@ public class AppointmentResponse {
public 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.appointmentId = appointmentId;
this.customerId = customerId; this.customerId = customerId;
this.customerName = customerName; this.customerName = customerName;
@@ -40,8 +46,9 @@ public class AppointmentResponse {
this.petIds = petIds; this.petIds = petIds;
this.createdAt = createdAt; this.createdAt = createdAt;
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
this.employeeId = employeeId;
this.employeeName = employeeName;
} }
public Long getAppointmentId() { public Long getAppointmentId() {
return appointmentId; return appointmentId;
} }
@@ -98,14 +105,29 @@ public class AppointmentResponse {
this.serviceName = serviceName; this.serviceName = serviceName;
} }
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public LocalDate getAppointmentDate() { public LocalDate getAppointmentDate() {
return appointmentDate; return appointmentDate;
} }
public void setAppointmentDate(LocalDate appointmentDate) { public void setAppointmentDate(LocalDate appointmentDate) {
this.appointmentDate = appointmentDate; this.appointmentDate = appointmentDate;
} }
public LocalTime getAppointmentTime() { public LocalTime getAppointmentTime() {
return appointmentTime; return appointmentTime;
} }

View File

@@ -25,6 +25,9 @@ public class Adoption {
@JoinColumn(name = "customerId", nullable = false) @JoinColumn(name = "customerId", nullable = false)
private Customer customer; private Customer customer;
@ManyToOne
private Employee employee;
@Column(nullable = false) @Column(nullable = false)
private LocalDate adoptionDate; private LocalDate adoptionDate;
@@ -76,6 +79,14 @@ public class Adoption {
this.customer = customer; this.customer = customer;
} }
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public LocalDate getAdoptionDate() { public LocalDate getAdoptionDate() {
return adoptionDate; return adoptionDate;
} }
@@ -133,4 +144,7 @@ public class Adoption {
", updatedAt=" + updatedAt + ", updatedAt=" + updatedAt +
'}'; '}';
} }
public void setEmployeeName(String s) {
}
} }

View File

@@ -31,6 +31,10 @@ public class Appointment {
@JoinColumn(name = "serviceId", nullable = false) @JoinColumn(name = "serviceId", nullable = false)
private Service service; private Service service;
@ManyToOne
@JoinColumn(name = "employeeId")
private Employee employee;
@Column(nullable = false) @Column(nullable = false)
private LocalDate appointmentDate; private LocalDate appointmentDate;
@@ -104,6 +108,14 @@ public class Appointment {
this.service = service; this.service = service;
} }
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public LocalDate getAppointmentDate() { public LocalDate getAppointmentDate() {
return appointmentDate; return appointmentDate;
} }

View File

@@ -5,6 +5,7 @@ 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.Customer; import com.petshop.backend.entity.Customer;
import com.petshop.backend.entity.Employee;
import com.petshop.backend.entity.Pet; import com.petshop.backend.entity.Pet;
import com.petshop.backend.exception.ResourceNotFoundException; import com.petshop.backend.exception.ResourceNotFoundException;
import com.petshop.backend.repository.AdoptionRepository; 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.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.petshop.backend.repository.EmployeeRepository;
@Service @Service
public class AdoptionService { public class AdoptionService {
@@ -21,11 +23,15 @@ public class AdoptionService {
private final AdoptionRepository adoptionRepository; private final AdoptionRepository adoptionRepository;
private final PetRepository petRepository; private final PetRepository petRepository;
private final CustomerRepository customerRepository; 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.adoptionRepository = adoptionRepository;
this.petRepository = petRepository; this.petRepository = petRepository;
this.customerRepository = customerRepository; this.customerRepository = customerRepository;
this.employeeRepository = employeeRepository;
} }
public Page<AdoptionResponse> getAllAdoptions(String query, Pageable pageable, Long customerId) { public Page<AdoptionResponse> getAllAdoptions(String query, Pageable pageable, Long customerId) {
@@ -73,6 +79,7 @@ public class AdoptionService {
adoption.setAdoptionDate(request.getAdoptionDate()); adoption.setAdoptionDate(request.getAdoptionDate());
adoption.setAdoptionStatus(request.getAdoptionStatus()); adoption.setAdoptionStatus(request.getAdoptionStatus());
adoption = adoptionRepository.save(adoption); adoption = adoptionRepository.save(adoption);
return mapToResponse(adoption); return mapToResponse(adoption);
} }
@@ -92,7 +99,12 @@ public class AdoptionService {
adoption.setCustomer(customer); adoption.setCustomer(customer);
adoption.setAdoptionDate(request.getAdoptionDate()); adoption.setAdoptionDate(request.getAdoptionDate());
adoption.setAdoptionStatus(request.getAdoptionStatus()); 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); adoption = adoptionRepository.save(adoption);
return mapToResponse(adoption); return mapToResponse(adoption);
} }
@@ -111,17 +123,27 @@ public class AdoptionService {
} }
private AdoptionResponse mapToResponse(Adoption adoption) { private AdoptionResponse mapToResponse(Adoption adoption) {
return new AdoptionResponse( AdoptionResponse response = new AdoptionResponse(
adoption.getAdoptionId(), adoption.getAdoptionId(),
adoption.getPet().getPetId(), adoption.getPet().getPetId(),
adoption.getPet().getPetName(), adoption.getPet().getPetName(),
adoption.getCustomer().getCustomerId(), adoption.getCustomer().getCustomerId(),
adoption.getCustomer().getFirstName() + " " + adoption.getCustomer().getLastName(), adoption.getCustomer().getFirstName() + " " + adoption.getCustomer().getLastName(),
adoption.getAdoptionDate(), adoption.getAdoptionDate(),
adoption.getAdoptionStatus(), adoption.getAdoptionStatus(),
adoption.getPet().getPetPrice(), adoption.getPet().getPetPrice(),
adoption.getCreatedAt(), adoption.getCreatedAt(),
adoption.getUpdatedAt() 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;
} }
} }

View File

@@ -98,6 +98,16 @@ public class AppointmentService {
Customer customer = customerRepository.findById(request.getCustomerId()) Customer customer = customerRepository.findById(request.getCustomerId())
.orElseThrow(() -> new ResourceNotFoundException("Customer not found with id: " + 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()) StoreLocation store = storeRepository.findById(request.getStoreId())
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getStoreId())); .orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getStoreId()));
@@ -113,6 +123,7 @@ public class AppointmentService {
appointment.setCustomer(customer); appointment.setCustomer(customer);
appointment.setStore(store); appointment.setStore(store);
appointment.setService(service); appointment.setService(service);
appointment.setEmployee(employee);
appointment.setAppointmentDate(request.getAppointmentDate()); appointment.setAppointmentDate(request.getAppointmentDate());
appointment.setAppointmentTime(request.getAppointmentTime()); appointment.setAppointmentTime(request.getAppointmentTime());
appointment.setAppointmentStatus(request.getAppointmentStatus()); appointment.setAppointmentStatus(request.getAppointmentStatus());
@@ -246,7 +257,13 @@ public class AppointmentService {
petNames, petNames,
petIds, petIds,
appointment.getCreatedAt(), appointment.getCreatedAt(),
appointment.getUpdatedAt() appointment.getUpdatedAt(),
appointment.getEmployee() != null ? appointment.getEmployee().getEmployeeId() : null,
appointment.getEmployee() != null ?
appointment.getEmployee().getFirstName() + " " + appointment.getEmployee().getLastName()
: "Unassigned"
); );
} }