From 40ba87b958d3b53f2eef4f95eb3add6548f35006 Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期五, 03 十二月 2021 11:18:48 +0800
Subject: [PATCH] [update] 我的顧問清單新增預約單歷史明細、預約單的更新API、預約單的邏輯刪除API

---
 pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java b/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
index 7e23420..42ef0ae 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
@@ -25,6 +25,7 @@
 import com.pollex.pam.service.mapper.AppointmentDTOMapper;
 import com.pollex.pam.web.rest.errors.AppointmentNotFoundException;
 
+import static com.pollex.pam.enums.AppointmentStatusEnum.AVAILABLE;
 import static com.pollex.pam.enums.AppointmentStatusEnum.DELETED;
 
 @Service
@@ -70,16 +71,17 @@
 		return appointmentRepository.save(appointment);
 	}
 
-
 	public AppointmentCustomerViewDTO getAppointmentDetail(Long appointmentId) {
 		AppointmentCustomerView appointment = appointmentCustomerViewRepository.findById(appointmentId)
 				.orElseThrow(AppointmentNotFoundException::new);
 		return appointmentCustomerViewMapper.toAppointmentCustomerViewDTO(appointment);
 	}
 
-
-    public List<Appointment> findByAgentNoAndCustomerId(String agentNo, Long customerId) {
-        return appointmentRepository.findByAgentNoAndCustomerId(agentNo, customerId);
+    public List<AppointmentCustomerView> findAvailableByAgentNoAndCustomerId(String agentNo, Long customerId) {
+        return appointmentCustomerViewRepository.findByAgentNoAndCustomerId(agentNo, customerId)
+            .stream()
+            .filter(appointmentCustomerView -> appointmentCustomerView.getStatus() == AVAILABLE)
+            .collect(Collectors.toList());
     }
 
     public void recordConsultantReadTime(Long appointmentId) {
@@ -102,7 +104,6 @@
     public void markAppointmentDeleted(Long appointmentId) {
         Appointment appointment = appointmentRepository.findById(appointmentId).get();
         appointment.setStatus(DELETED);
-
         appointmentRepository.save(appointment);
     }
 
@@ -117,7 +118,9 @@
     }
 
     public List<AppointmentCustomerViewDTO> getConsultantAppointments(String agentNo) {
-        List<AppointmentCustomerView> appointmentList = appointmentCustomerViewRepository.findByAgentNo(agentNo);
-        return appointmentCustomerViewMapper.toAppointmentCustomerViewDTO(appointmentList);
+        return appointmentCustomerViewRepository.findByAgentNo(agentNo).stream()
+            .filter(appointment -> appointment.getStatus() != DELETED)
+            .map(appointmentCustomerViewMapper::toAppointmentCustomerViewDTO)
+            .collect(Collectors.toList());
     }
 }

--
Gitblit v1.8.0