Done ticket GEPAFINBE-3

This commit is contained in:
harish
2024-08-14 15:31:00 +05:30
parent 2773dfa034
commit e09f61f918
51 changed files with 2107 additions and 70 deletions

View File

@@ -0,0 +1,109 @@
package net.gepafin.tendermanagement.dao;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.RegionEntity;
import net.gepafin.tendermanagement.entities.RoleEntity;
import net.gepafin.tendermanagement.model.request.RegionReq;
import net.gepafin.tendermanagement.model.request.RoleReq;
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
import net.gepafin.tendermanagement.model.request.UpdateRegionReq;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
import net.gepafin.tendermanagement.repositories.RegionRepository;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
import static net.gepafin.tendermanagement.util.ObjectUtils.setIfUpdated;
@Repository
public class RegionDao {
@Autowired
private RegionRepository regionRepository;
public RegionResponseBean createRegion(RegionReq regionReq) {
RegionEntity regionEntity = convertRegionRequestToRegionEntity(regionReq);
regionRepository.save(regionEntity);
return convertRegionEntityToRegionResponse(regionEntity);
}
private RegionEntity convertRegionRequestToRegionEntity(RegionReq regionReq) {
RegionEntity regionEntity = new RegionEntity();
regionEntity.setCountry(regionReq.getCountry());
regionEntity.setDescription(regionReq.getDescription());
regionEntity.setGdp(regionReq.getGdp());
regionEntity.setRegionName(regionReq.getRegionName());
regionEntity.setAreaSize(regionReq.getAreaSize());
regionEntity.setPopulation(regionReq.getPopulation());
regionEntity.setEnvironmentalScore(regionReq.getEnvironmentalScore());
regionEntity.setStatus(regionReq.getStatus());
regionEntity.setHealthcareAccess(regionReq.getHealthcareAccess());
regionEntity.setInfrastructureScore(regionReq.getInfrastructureScore());
regionEntity.setPriorityArea(regionReq.getPriorityArea());
regionEntity.setUnemploymentRate(regionReq.getUnemploymentRate());
regionEntity.setEducationLevel(regionReq.getEducationLevel());
return regionEntity;
}
private RegionResponseBean convertRegionEntityToRegionResponse(RegionEntity regionEntity) {
RegionResponseBean regionResponseBean = new RegionResponseBean();
regionResponseBean.setId(regionEntity.getId());
regionResponseBean.setCreatedDate(regionEntity.getCreatedDate());
regionResponseBean.setUpdatedDate(regionEntity.getUpdatedDate());
regionResponseBean.setCountry(regionEntity.getCountry());
regionResponseBean.setDescription(regionEntity.getDescription());
regionResponseBean.setGdp(regionEntity.getGdp());
regionResponseBean.setRegionName(regionEntity.getRegionName());
regionResponseBean.setAreaSize(regionEntity.getAreaSize());
regionResponseBean.setPopulation(regionEntity.getPopulation());
regionResponseBean.setEnvironmentalScore(regionEntity.getEnvironmentalScore());
regionResponseBean.setStatus(regionEntity.getStatus());
regionResponseBean.setHealthcareAccess(regionEntity.getHealthcareAccess());
regionResponseBean.setInfrastructureScore(regionEntity.getInfrastructureScore());
regionResponseBean.setPriorityArea(regionEntity.getPriorityArea());
regionResponseBean.setUnemploymentRate(regionEntity.getUnemploymentRate());
regionResponseBean.setEducationLevel(regionEntity.getEducationLevel());
return regionResponseBean;
}
public RegionResponseBean updateRegion(Long id, RegionReq regionReq) {
RegionEntity existingRegion = getRegionById(id);
setIfUpdated(existingRegion::getRegionName, existingRegion::setRegionName, regionReq.getRegionName());
setIfUpdated(existingRegion::getDescription, existingRegion::setDescription, regionReq.getDescription());
setIfUpdated(existingRegion::getCountry, existingRegion::setCountry, regionReq.getCountry());
setIfUpdated(existingRegion::getStatus, existingRegion::setStatus, regionReq.getStatus());
setIfUpdated(existingRegion::getPriorityArea, existingRegion::setPriorityArea, regionReq.getPriorityArea());
setIfUpdated(existingRegion::getPopulation, existingRegion::setPopulation, regionReq.getPopulation());
setIfUpdated(existingRegion::getAreaSize, existingRegion::setAreaSize, regionReq.getAreaSize());
setIfUpdated(existingRegion::getGdp, existingRegion::setGdp, regionReq.getGdp());
setIfUpdated(existingRegion::getUnemploymentRate, existingRegion::setUnemploymentRate, regionReq.getUnemploymentRate());
setIfUpdated(existingRegion::getInfrastructureScore, existingRegion::setInfrastructureScore, regionReq.getInfrastructureScore() );
setIfUpdated(existingRegion::getEducationLevel, existingRegion::setEducationLevel, regionReq.getEducationLevel());
setIfUpdated(existingRegion::getHealthcareAccess, existingRegion::setHealthcareAccess, regionReq.getHealthcareAccess());
setIfUpdated(existingRegion::getEnvironmentalScore, existingRegion::setEnvironmentalScore, regionReq.getEnvironmentalScore());
regionRepository.save(existingRegion);
return Utils.convertObject(existingRegion, RegionResponseBean.class);
}
public RegionEntity getRegionById(Long id) {
return regionRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
}
public void deleteById(Long id) {
regionRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
regionRepository.deleteById(id);
}
public List<RegionResponseBean> getAllRegions()
{
return regionRepository.findAll()
.stream()
.map(regionEntity -> Utils.convertObject(regionEntity, RegionResponseBean.class))
.collect(Collectors.toList());
}
}