61 lines
2.1 KiB
Plaintext
61 lines
2.1 KiB
Plaintext
|
package com.healthcare.ohctech.service.impl;
|
||
|
|
||
|
import com.healthcare.ohctech.dto.SaltMasterDto;
|
||
|
import com.healthcare.ohctech.entity.SaltMaster;
|
||
|
import com.healthcare.ohctech.repository.SaltMasterRepo;
|
||
|
import com.healthcare.ohctech.service.SaltMasterService;
|
||
|
import org.springframework.data.domain.Page;
|
||
|
import org.springframework.data.domain.Pageable;
|
||
|
import org.springframework.stereotype.Service;
|
||
|
|
||
|
import java.util.Optional;
|
||
|
|
||
|
@Service
|
||
|
public class SaltMasterServiceImpl implements SaltMasterService {
|
||
|
private final SaltMasterRepo saltMasterRepo;
|
||
|
|
||
|
public SaltMasterServiceImpl(SaltMasterRepo saltMasterRepo) {
|
||
|
this.saltMasterRepo = saltMasterRepo;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public SaltMaster getSaltMasterById(Long id) {
|
||
|
Optional<SaltMaster> saltMaster = saltMasterRepo.findById(id);
|
||
|
return saltMaster.orElse(null);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Page<SaltMaster> getAllSaltMasters(Pageable pageable) {
|
||
|
return saltMasterRepo.findAll(pageable);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void addSaltMaster(SaltMasterDto saltMasterDto) {
|
||
|
SaltMaster saltMaster = new SaltMaster();
|
||
|
saltMaster.setSaltName(saltMasterDto.saltName());
|
||
|
saltMasterRepo.save(saltMaster);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public SaltMaster updateSaltMaster(SaltMasterDto saltMasterDto) {
|
||
|
Optional<SaltMaster> optionalSaltMaster = saltMasterRepo.findById(saltMasterDto.id());
|
||
|
if (optionalSaltMaster.isPresent()) {
|
||
|
SaltMaster saltMaster = optionalSaltMaster.get();
|
||
|
saltMaster.setSaltName(saltMasterDto.saltName());
|
||
|
return saltMasterRepo.save(saltMaster);
|
||
|
} else {
|
||
|
throw new RuntimeException("SaltMaster not found with ID: " + saltMasterDto.id());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void deleteSaltMaster(Long id) {
|
||
|
Optional<SaltMaster> optionalSaltMaster = saltMasterRepo.findById(id);
|
||
|
if (optionalSaltMaster.isPresent()) {
|
||
|
saltMasterRepo.delete(optionalSaltMaster.get());
|
||
|
} else {
|
||
|
throw new RuntimeException("SaltMaster not found with ID: " + id);
|
||
|
}
|
||
|
}
|
||
|
}
|