63 lines
2.4 KiB
Plaintext
63 lines
2.4 KiB
Plaintext
|
package com.healthcare.ohctech.service.impl;
|
||
|
|
||
|
import com.healthcare.ohctech.dto.InjuryClassDto;
|
||
|
import com.healthcare.ohctech.entity.InjuryClass;
|
||
|
import com.healthcare.ohctech.repository.InjuryClassRepo;
|
||
|
import com.healthcare.ohctech.service.InjuryClassService;
|
||
|
import org.springframework.data.domain.Page;
|
||
|
import org.springframework.data.domain.Pageable;
|
||
|
import org.springframework.stereotype.Service;
|
||
|
|
||
|
@Service
|
||
|
public class InjuryClassServiceImpl implements InjuryClassService {
|
||
|
|
||
|
private final InjuryClassRepo injuryClassRepo;
|
||
|
|
||
|
public InjuryClassServiceImpl(InjuryClassRepo injuryClassRepo) {
|
||
|
this.injuryClassRepo = injuryClassRepo;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public InjuryClass getInjuryClassById(Long injuryClassId) {
|
||
|
return injuryClassRepo.findById(injuryClassId)
|
||
|
.orElseThrow(() -> new RuntimeException("Injury Class not found for ID: " + injuryClassId));
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Page<InjuryClass> getAllInjuryClasses(Pageable pageable) {
|
||
|
return injuryClassRepo.findAll(pageable);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void addInjuryClass(InjuryClassDto injuryClassDto, Long userId) {
|
||
|
InjuryClass injuryClass = convertToEntity(new InjuryClass(), injuryClassDto);
|
||
|
injuryClass.setModifiedBy(userId);
|
||
|
injuryClassRepo.save(injuryClass);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void updateInjuryClass(InjuryClassDto injuryClassDto, Long userId) {
|
||
|
Long injuryClassId = injuryClassDto.id();
|
||
|
InjuryClass injuryClass = injuryClassRepo.findById(injuryClassId)
|
||
|
.orElseThrow(() -> new RuntimeException("Injury Class not found for ID: " + injuryClassId));
|
||
|
|
||
|
convertToEntity(injuryClass, injuryClassDto);
|
||
|
injuryClass.setModifiedBy(userId);
|
||
|
injuryClassRepo.save(injuryClass);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void deleteInjuryClass(Long injuryClassId) {
|
||
|
InjuryClass injuryClass = injuryClassRepo.findById(injuryClassId)
|
||
|
.orElseThrow(() -> new RuntimeException("Injury Class not found for ID: " + injuryClassId));
|
||
|
injuryClassRepo.delete(injuryClass);
|
||
|
}
|
||
|
|
||
|
private InjuryClass convertToEntity(InjuryClass injuryClass, InjuryClassDto injuryClassDto) {
|
||
|
injuryClass.setInjClassName(injuryClassDto.injClassName());
|
||
|
injuryClass.setInjClassCode(injuryClassDto.injClassCode());
|
||
|
injuryClass.setInjClassDesc(injuryClassDto.injClassDesc());
|
||
|
return injuryClass;
|
||
|
}
|
||
|
}
|