package com.pollex.pam.appointment.process;
|
|
import java.util.Optional;
|
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.pollex.pam.domain.AppointmentClosedInfo;
|
import com.pollex.pam.enums.ContactStatusEnum;
|
import com.pollex.pam.repository.AppointmentClosedInfoRepository;
|
import com.pollex.pam.service.dto.AbstractAppointmentProcessDTO;
|
import com.pollex.pam.service.dto.DoneProcessDTO;
|
|
@Service
|
public class DoneProcess implements AppointmentProcessInterface{
|
|
@Autowired
|
AppointmentClosedInfoRepository appointmentClosedInfoRepository;
|
|
@Override
|
public void doProcess(AbstractAppointmentProcessDTO processDTO) {
|
checkClosedInfo(processDTO.getAppointmentId());
|
DoneProcessDTO doneProcess = (DoneProcessDTO)processDTO;
|
BeanUtils.copyProperties(processDTO, doneProcess);
|
AppointmentClosedInfo closedInfo = new AppointmentClosedInfo();
|
BeanUtils.copyProperties(doneProcess, closedInfo);
|
appointmentClosedInfoRepository.save(closedInfo);
|
}
|
|
@Override
|
public ContactStatusEnum getProcessType() {
|
return ContactStatusEnum.DONE;
|
}
|
|
private void checkClosedInfo(Long appointmentId) {
|
Optional<AppointmentClosedInfo> closedInfo = appointmentClosedInfoRepository.findByAppointmentId(appointmentId);
|
if(closedInfo.isPresent()) {
|
throw new IllegalArgumentException("appointment closed info exist");
|
}
|
}
|
|
}
|