ohctechv3/.svn/pristine/4e/4e573a5458bbeb83313bc04b62867fa621472b16.svn-base

74 lines
2.5 KiB
Plaintext
Raw Permalink Normal View History

2024-10-28 15:03:36 +05:30
package com.healthcare.ohctech.service.impl;
import com.healthcare.ohctech.dto.OhcDto;
import com.healthcare.ohctech.entity.OhcType;
import com.healthcare.ohctech.repository.OhcTypeRepo;
import com.healthcare.ohctech.service.OhcService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@Service
public class OhcServiceImpl implements OhcService {
private final OhcTypeRepo ohcTypeRepo;
public OhcServiceImpl(OhcTypeRepo ohcTypeRepo) {
this.ohcTypeRepo = ohcTypeRepo;
}
@Override
public OhcType getOhcById(Long ohcId) {
return ohcTypeRepo.findById(ohcId)
.orElseThrow(() -> new RuntimeException("OHC not found for ID: " + ohcId));
}
@Override
public Page<OhcType> getAllOhc(Pageable pageable) {
return ohcTypeRepo.findAll(pageable);
}
@Override
public void addOhc(OhcDto ohcDto, Long userId) {
OhcType ohcType = convertToEntity(new OhcType(), ohcDto);
ohcType.setModifiedBy(userId);
ohcTypeRepo.save(ohcType);
}
@Override
public void updateOhc(OhcDto ohcDto, Long userId) {
Long ohcId = ohcDto.id();
OhcType ohcType = ohcTypeRepo.findById(ohcId)
.orElseThrow(() -> new RuntimeException("OHC not found for ID: " + ohcId));
convertToEntity(ohcType, ohcDto);
ohcType.setModifiedBy(userId);
ohcTypeRepo.save(ohcType);
}
@Override
public void deleteOhc(Long ohcId) {
OhcType ohcType = ohcTypeRepo.findById(ohcId)
.orElseThrow(() -> new RuntimeException("OHC not found for ID: " + ohcId));
ohcTypeRepo.delete(ohcType);
}
private OhcType convertToEntity(OhcType ohcType, OhcDto ohcDto) {
ohcType.setOhcName(ohcDto.ohcName());
ohcType.setOhcCode(ohcDto.ohcCode());
ohcType.setOhcCategory(ohcDto.ohcCategory());
ohcType.setOhcDescription(ohcDto.ohcDescription());
ohcType.setOhcLogo(ohcDto.ohcLogo());
ohcType.setOhcType(ohcDto.ohcType());
ohcType.setAddress(ohcDto.address());
ohcType.setFax(ohcDto.fax());
ohcType.setIconColor(ohcDto.iconColor());
ohcType.setIconText(ohcDto.iconText());
ohcType.setPinCode(ohcDto.pinCode());
ohcType.setPrimaryEmail(ohcDto.primaryEmail());
ohcType.setPrimaryPhone(ohcDto.primaryPhone());
ohcType.setState(ohcDto.state());
ohcType.setOhcLogoType(ohcDto.ohcLogoType());
return ohcType;
}
}