package com.healthcare.ohctech.service.impl; import com.healthcare.ohctech.dto.AppoinmentSlotDto; import com.healthcare.ohctech.entity.AppoinmentSlot; import com.healthcare.ohctech.repository.AppoinmentSlotRepo; import com.healthcare.ohctech.service.AppoinmentSlotService; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @Service public class AppoinmentSlotServiceImpl implements AppoinmentSlotService { private final AppoinmentSlotRepo appoinmentSlotRepo; public AppoinmentSlotServiceImpl(AppoinmentSlotRepo appoinmentSlotRepo) { this.appoinmentSlotRepo = appoinmentSlotRepo; } @Override public AppoinmentSlot getAppoinmentSlotById(Long id) { return appoinmentSlotRepo.findById(id) .orElseThrow(() -> new RuntimeException("Appoinment slot not found with ID: " + id)); } @Override public Page getAllAppoinmentSlots(Pageable pageable) { return appoinmentSlotRepo.findAll(pageable); } @Override public void addAppoinmentSlot(AppoinmentSlotDto appoinmentSlotDto,Long userId) { AppoinmentSlot appoinmentSlot = convertToEntity(new AppoinmentSlot(), appoinmentSlotDto); appoinmentSlot.setModifiedBy(userId); appoinmentSlotRepo.save(appoinmentSlot); } @Override public AppoinmentSlot updateAppoinmentSlot(AppoinmentSlotDto appoinmentSlotDto,Long userId) { AppoinmentSlot appoinmentSlot = appoinmentSlotRepo.findById(appoinmentSlotDto.id()) .orElseThrow(() -> new RuntimeException("Appoinment slot not found with ID: " + appoinmentSlotDto.id())); appoinmentSlot.setModifiedBy(userId); return appoinmentSlotRepo.save(convertToEntity(appoinmentSlot, appoinmentSlotDto)); } @Override public void deleteAppoinmentSlot(Long id) { AppoinmentSlot appoinmentSlot = appoinmentSlotRepo.findById(id) .orElseThrow(() -> new RuntimeException("Appoinment slot not found with ID: " + id)); appoinmentSlotRepo.delete(appoinmentSlot); } private AppoinmentSlot convertToEntity(AppoinmentSlot appoinmentSlot, AppoinmentSlotDto appoinmentSlotDto) { appoinmentSlot.setSlot(appoinmentSlotDto.slot()); appoinmentSlot.setSlotEnd(appoinmentSlotDto.slotEnd()); appoinmentSlot.setSlotCount(appoinmentSlotDto.slotCount()); appoinmentSlot.setAppType(appoinmentSlotDto.appType()); return appoinmentSlot; } }