ohctechv3/.svn/pristine/50/505289ea7475a3a3ad2a55dd54fb418cf1d2c8b6.svn-base

67 lines
2.7 KiB
Plaintext
Raw Normal View History

2024-10-28 15:03:36 +05:30
package com.healthcare.ohctech.service.impl;
import com.healthcare.ohctech.dto.ReferralPointDto;
import com.healthcare.ohctech.entity.ReferralPoint;
import com.healthcare.ohctech.repository.ReferralPointRepo;
import com.healthcare.ohctech.service.ReferralPointService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
public class ReferralPointServiceImpl implements ReferralPointService {
private final ReferralPointRepo referralPointRepo;
public ReferralPointServiceImpl(ReferralPointRepo referralPointRepo) {
this.referralPointRepo = referralPointRepo;
}
@Override
public ReferralPoint getReferralPointById(Long referralPointId) {
return referralPointRepo.findById(referralPointId)
.orElseThrow(() -> new RuntimeException("Referral Point not found for ID: " + referralPointId));
}
@Override
public Page<ReferralPoint> getAllReferralPoints(Pageable pageable) {
return referralPointRepo.findAll(pageable);
}
@Override
public void addReferralPoint(ReferralPointDto referralPointDto, Long userId) {
ReferralPoint referralPoint = convertToEntity(new ReferralPoint(), referralPointDto);
referralPoint.setModifiedBy(userId);
referralPointRepo.save(referralPoint);
}
@Override
public void updateReferralPoint(ReferralPointDto referralPointDto, Long userId) {
Long referralPointId = referralPointDto.id();
ReferralPoint referralPoint = referralPointRepo.findById(referralPointId)
.orElseThrow(() -> new RuntimeException("Referral Point not found for ID: " + referralPointId));
convertToEntity(referralPoint, referralPointDto);
referralPoint.setModifiedBy(userId);
referralPointRepo.save(referralPoint);
}
@Override
public void deleteReferralPoint(Long referralPointId) {
ReferralPoint referralPoint = referralPointRepo.findById(referralPointId)
.orElseThrow(() -> new RuntimeException("Referral Point not found for ID: " + referralPointId));
referralPointRepo.delete(referralPoint);
}
private ReferralPoint convertToEntity(ReferralPoint referralPoint, ReferralPointDto referralPointDto) {
referralPoint.setReferralPointName(referralPointDto.referralPointName());
referralPoint.setCity(referralPointDto.city());
referralPoint.setHospitalName(referralPointDto.hospitalName());
referralPoint.setAddress(referralPointDto.address());
referralPoint.setContactDetail(referralPointDto.contactDetail());
return referralPoint;
}
}