ipns-eval-poc-backend / src /services /_rfp_service.py
gopalswami's picture
Implement evaluation status API and enhance RFP service with deficiency check logic
2a79756
from src.models import RFP, RFPStatus, AnalysisType
from src.repositories import RFPRepository, ProposalRepository, ProposalEvaluationRepository, AnalysisRepository
class RFPService:
def __init__(self):
self.rfp_repository = RFPRepository
self.proposal_repository = ProposalRepository
self.evaluation_repository = ProposalEvaluationRepository
self.analysis_repository = AnalysisRepository
async def __aenter__(self):
return self
async def __aexit__(self, exc_type, exc_value, traceback):
pass
async def get_rfps(self, rfp_id: str = None, status: RFPStatus = None):
async with self.rfp_repository() as repository:
return await repository.get_rfps(rfp_id=rfp_id, status=status)
async def create_rfp(self, rfp: dict):
async with self.rfp_repository() as repository:
return await repository.create_rfp(rfp)
async def update_rfp(self, rfp_id: str, rfp: dict):
async with self.rfp_repository() as repository:
return await repository.update_rfp(rfp_id=rfp_id, rfp=rfp)
async def delete_rfp(self, rfp_id: str):
async with self.rfp_repository() as repository:
return await repository.delete_rfp(rfp_id)
async def check_deficiencies(self, rfp_id: str) -> bool:
async with self.proposal_repository() as proposal_repo:
proposals = await proposal_repo.get_proposals(rfp_id=rfp_id)
if not proposals:
return False
for proposal in proposals:
proposal_id = proposal["id"]
async with self.evaluation_repository() as eval_repo:
evaluations = await eval_repo.get_evaluations(proposal_id=proposal_id)
if not evaluations:
continue
for evaluation in evaluations:
evaluation_id = evaluation["id"]
async with self.analysis_repository() as analysis_repo:
deficiencies = await analysis_repo.get_analysis(
evaluation_id=evaluation_id,
analysis_type=AnalysisType.DEFICIENCIES
)
if deficiencies:
return True
return False