66 lines
2.3 KiB
Plaintext
66 lines
2.3 KiB
Plaintext
package com.healthcare.ohctech.service.impl;
|
|
|
|
import com.healthcare.ohctech.dto.InjuryTypeDto;
|
|
import com.healthcare.ohctech.entity.InjuryType;
|
|
import com.healthcare.ohctech.repository.InjuryTypeRepo;
|
|
import com.healthcare.ohctech.service.InjuryTypeService;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@Service
|
|
public class InjuryTypeServiceImpl implements InjuryTypeService {
|
|
|
|
private final InjuryTypeRepo injuryTypeRepo;
|
|
|
|
public InjuryTypeServiceImpl(InjuryTypeRepo injuryTypeRepo) {
|
|
this.injuryTypeRepo = injuryTypeRepo;
|
|
}
|
|
|
|
@Override
|
|
public InjuryType getInjuryTypeById(Long injuryTypeId) {
|
|
return injuryTypeRepo.findById(injuryTypeId)
|
|
.orElseThrow(() -> new RuntimeException("Injury Type not found for ID: " + injuryTypeId));
|
|
}
|
|
|
|
@Override
|
|
public Page<InjuryType> getAllInjuryTypes(Pageable pageable) {
|
|
return injuryTypeRepo.findAll(pageable);
|
|
}
|
|
|
|
@Override
|
|
public void addInjuryType(InjuryTypeDto injuryTypeDto, Long userId) {
|
|
InjuryType injuryType = convertToEntity(new InjuryType(), injuryTypeDto);
|
|
injuryType.setModifiedBy(userId);
|
|
injuryTypeRepo.save(injuryType);
|
|
}
|
|
|
|
@Override
|
|
public void updateInjuryType(InjuryTypeDto injuryTypeDto, Long userId) {
|
|
Long injuryTypeId = injuryTypeDto.id();
|
|
InjuryType injuryType = injuryTypeRepo.findById(injuryTypeId)
|
|
.orElseThrow(() -> new RuntimeException("Injury Type not found for ID: " + injuryTypeId));
|
|
|
|
convertToEntity(injuryType, injuryTypeDto);
|
|
injuryType.setModifiedBy(userId);
|
|
injuryTypeRepo.save(injuryType);
|
|
}
|
|
|
|
@Override
|
|
public void deleteInjuryType(Long injuryTypeId) {
|
|
InjuryType injuryType = injuryTypeRepo.findById(injuryTypeId)
|
|
.orElseThrow(() -> new RuntimeException("Injury Type not found for ID: " + injuryTypeId));
|
|
injuryTypeRepo.delete(injuryType);
|
|
}
|
|
|
|
private InjuryType convertToEntity(InjuryType injuryType, InjuryTypeDto injuryTypeDto) {
|
|
injuryType.setInjuryTypeName(injuryTypeDto.injuryTypeName());
|
|
injuryType.setInjuryTypeCode(injuryTypeDto.injuryTypeCode());
|
|
injuryType.setInjuryTypeDesc(injuryTypeDto.injuryTypeDesc());
|
|
return injuryType;
|
|
}
|
|
|
|
|
|
}
|