package com.pollex.pam.web.rest; import com.pollex.pam.business.aop.logging.audit.AuditLoggingInject; import com.pollex.pam.business.aop.logging.audit.AuditLoggingType; import com.pollex.pam.business.appointment.process.AppointmentProcess; import com.pollex.pam.business.domain.Appointment; import com.pollex.pam.business.enums.AppointmentStatusEnum; import com.pollex.pam.business.security.SecurityUtils; import com.pollex.pam.business.service.SendMsgService; import com.pollex.pam.business.service.dto.*; import com.pollex.pam.business.service.mapper.AppointmentMapper; import com.pollex.pam.business.web.errors.CreateFailBecauseOfCancelAppointmentRecentException; import com.pollex.pam.business.web.errors.CreateFailHaveProcessingAppointmentException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import com.pollex.pam.business.service.AppointmentService; import com.pollex.pam.business.service.PersonalNotificationService; import com.pollex.pam.business.service.SatisfactionService; import static com.pollex.pam.business.aop.logging.audit.AuditLoggingType.*; import java.util.List; @RestController @RequestMapping("/api/appointment") public class AppointmentResource { @Autowired AppointmentService appointmentService; @Autowired AppointmentMapper appointmentMapper; @Autowired SatisfactionService satisfactionService; @Autowired SendMsgService sendMsgService; @Autowired AppointmentProcess abstractAppointmentProcess; @Autowired PersonalNotificationService personalNotificationService; @AuditLoggingInject(type = CUSTOMER_EDIT_APPOINTMENT) @PutMapping("") public ResponseEntity updateAppointment(@RequestBody AppointmentUpdateDTO dto) { Appointment appointment = appointmentService.updateAppointment(dto); personalNotificationService.createUpdateAppointmentToConsultant(appointment); return ResponseEntity.noContent().build(); } @AuditLoggingInject(type = AuditLoggingType.CUSTOMER_CANCEL_APPOINTMENT) @DeleteMapping("/{appointmentId}") public ResponseEntity markAppointmentDeleted(@PathVariable Long appointmentId) { appointmentService.markAppointmentDeleted(appointmentId); return ResponseEntity.noContent().build(); } @AuditLoggingInject(type = AuditLoggingType.CUSTOMER_CREATE_APPOINTMENT) @PostMapping("/customer/create") public AppointmentDTO clientCreateAppointment(@RequestBody AppointmentCreateDTO appointmentCreateDTO) { List processing = appointmentService.findProcessingAppointmentByCustomer(SecurityUtils.getCustomerDBId()); List cancelAppointmentment = appointmentService.findCustomer3DayCancelAppointment(); if(!processing.isEmpty()) { throw new CreateFailHaveProcessingAppointmentException(); }else if(!cancelAppointmentment.isEmpty()) { throw new CreateFailBecauseOfCancelAppointmentRecentException(); } Appointment appointment = appointmentService.customerCreateAppointment(appointmentCreateDTO); satisfactionService.createUnfilledSystemSatisfaction(appointment); return appointmentMapper.toAppointmentDTO(appointment); } @PostMapping("/markAsContacted/{appointmentId}") public AppointmentCustomerViewDTO markAsContacted(@PathVariable Long appointmentId) { appointmentService.markAsContacted(appointmentId); return appointmentService.getAppointmentDetail(appointmentId); } @AuditLoggingInject(type = CHECK_APPOINTMENT) @GetMapping("/getDetail/{appointmentId}") public AppointmentCustomerViewDTO getAppointmentDetail(@PathVariable Long appointmentId) { return appointmentService.getAppointmentDetail(appointmentId); } @AuditLoggingInject(type = CONSULTANT_READ_APPOINTMENT) @PostMapping("/recordRead/{appointmentId}") public ResponseEntity recordConsultantReadAppointment(@PathVariable Long appointmentId) { appointmentService.recordConsultantReadTime(appointmentId); return ResponseEntity.noContent().build(); } @AuditLoggingInject(type = APPOINTMENT_CLOSE) @PostMapping("/close") public ResponseEntity closeAppointment(@RequestBody AppointmentCloseDTO closeDTO) { appointmentService.closeAppointment(closeDTO); return ResponseEntity.noContent().build(); } @GetMapping("/customer/expiring/newest") public ResponseEntity getNewestExpiringAppointment() { Long customerId = SecurityUtils.getCustomerDBId(); AppointmentCustomerViewDTO customerNewestExpiringAppointment = appointmentService.getCustomerNewestExpiringAppointment(customerId); return new ResponseEntity<>(customerNewestExpiringAppointment, HttpStatus.OK); } @GetMapping("/consultant/pending/sum") public ResponseEntity getConsultantPendingAppointmentSum() { String agentNo = SecurityUtils.getAgentNo(); return new ResponseEntity<>(appointmentService.getConsultantPendingAppointmentSum(agentNo), HttpStatus.OK); } @GetMapping("/customer/get_all_group_by_consultant") public List getCustomerAllAppointmentGroupByConsultant() { return appointmentService.getCustomerAllAppointmentGroupByConsultant(); } }