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"
|
||||
|
||||
Reference in New Issue
Block a user