ipns-eval-poc-backend / src /controllers /_proposal_ai_analysis_controller.py
Aryan Jain
categorize the strengths
63dfa98
from fastapi import APIRouter, HTTPException, Query, Path
from pydantic import BaseModel
from typing import List, Optional
from uuid import UUID
from datetime import datetime
from src.config import logger
from src.services import ProposalAIAnalysisService
from src.models import QueryType, CreateOrUpdateType, Category
class ProposalAIAnalysis(BaseModel):
id: UUID
proposal_id: UUID
ai_score: float
created_at: datetime
updated_at: datetime
class ProposalStrength(BaseModel):
id: UUID
proposal_id: UUID
strength_point: str
category: Category
created_at: datetime
updated_at: datetime
class ProposalWeakness(BaseModel):
id: UUID
proposal_id: UUID
weakness_point: str
category: Category
created_at: datetime
updated_at: datetime
class ProposalRejectionReason(BaseModel):
id: UUID
proposal_id: UUID
reason: str
category: Category
created_at: datetime
updated_at: datetime
class ProposalImprovement(BaseModel):
id: UUID
proposal_id: UUID
improvement_point: str
category: Category
created_at: datetime
updated_at: datetime
class ProposalAllStrengthsResponse(BaseModel):
status: str
data: Optional[List[str]]
class ProposalAllWeaknessesResponse(BaseModel):
status: str
data: Optional[List[str]]
class ProposalAllRejectionReasonsResponse(BaseModel):
status: str
data: Optional[List[str]]
class ProposalAllImprovementsResponse(BaseModel):
status: str
data: Optional[List[str]]
class ProposalAIAnalysisResponse(BaseModel):
status: str
data: Optional[List[ProposalAIAnalysis]]
class ProposalStrengthResponse(BaseModel):
status: str
data: Optional[List[ProposalStrength]]
class ProposalWeaknessResponse(BaseModel):
status: str
data: Optional[List[ProposalWeakness]]
class ProposalRejectionReasonResponse(BaseModel):
status: str
data: Optional[List[ProposalRejectionReason]]
class ProposalImprovementResponse(BaseModel):
status: str
data: Optional[List[ProposalImprovement]]
class Analysis(BaseModel):
strengths: Optional[List[str]] = None
weaknesses: Optional[List[str]] = None
rejection_reasons: Optional[List[str]] = None
improvements: Optional[List[str]] = None
class ProposalCompleteAnalysis(BaseModel):
ai_score: float
technical: Optional[Analysis] = None
management: Optional[Analysis] = None
past_performance: Optional[Analysis] = None
price: Optional[Analysis] = None
class ProposalCompleteAnalysisResponse(BaseModel):
status: str
data: Optional[List[ProposalCompleteAnalysis]]
class DeleteResponse(BaseModel):
status: str
class ProposalStrengthRequest(BaseModel):
proposal_id: UUID
strength_point: str
category: Category
class UpdateProposalStrengthRequest(BaseModel):
proposal_id: Optional[UUID] = None
strength_point: Optional[str] = None
category: Optional[Category] = None
class ProposalWeaknessRequest(BaseModel):
proposal_id: UUID
weakness_point: str
category: Category
class UpdateProposalWeaknessRequest(BaseModel):
proposal_id: Optional[UUID] = None
weakness_point: Optional[str] = None
category: Optional[Category] = None
class ProposalRejectionReasonRequest(BaseModel):
proposal_id: UUID
reason: str
category: Category
class UpdateProposalRejectionReasonRequest(BaseModel):
proposal_id: Optional[UUID] = None
reason: Optional[str] = None
category: Optional[Category] = None
class ProposalImprovementRequest(BaseModel):
proposal_id: UUID
improvement_point: str
category: Category
class UpdateProposalImprovementRequest(BaseModel):
proposal_id: Optional[UUID] = None
improvement_point: Optional[str] = None
category: Optional[Category] = None
class CreateAiAnalysisRequest(BaseModel):
proposal_id: UUID
ai_score: float
class CreateAIAnalysisRequestByProposalId(BaseModel):
ai_score: float
class UpdateAiAnalysisRequest(BaseModel):
proposal_id: Optional[UUID] = None
ai_score: Optional[float] = None
class UpdateAIAnalysisRequestByProposalId(BaseModel):
ai_score: Optional[float] = None
class CreateAllProposalStrengthsRequest(BaseModel):
strength_point: List[str]
category: Category
class UpdateAllProposalStrengthsRequest(BaseModel):
strength_point: Optional[List[str]] = None
class CreateAllProposalWeaknessRequest(BaseModel):
weakness_point: List[str]
category: Category
class CreateAllProposalRejectionReasonsRequest(BaseModel):
reason: List[str]
category: Category
class CreateAllProposalImprovementsRequest(BaseModel):
improvement_point: List[str]
category: Category
class CreateAllProposalAnalysisRequest(BaseModel):
ai_score: float
technical: Optional[Analysis] = None
management: Optional[Analysis] = None
past_performance: Optional[Analysis] = None
price: Optional[Analysis] = None
class UpdateAllProposalAnalysisRequest(BaseModel):
ai_score: Optional[float] = None
technical: Optional[Analysis] = None
management: Optional[Analysis] = None
past_performance: Optional[Analysis] = None
price: Optional[Analysis] = None
class ProposalAIController:
def __init__(self):
self.__service = ProposalAIAnalysisService
self.router = APIRouter()
# self.router.add_api_route(
# "/proposal-strengths",
# self.get_proposal_strengths,
# methods=["GET"],
# tags=["Proposal Strengths"],
# response_model=ProposalStrengthResponse,
# )
# self.router.add_api_route(
# "/proposal-strengths/{id}",
# self.get_proposal_strengths_by_id,
# methods=["GET"],
# tags=["Proposal Strengths by ID"],
# response_model=ProposalStrengthResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/strengths",
self.get_proposal_strengths_by_proposal_id,
methods=["GET"],
tags=["Proposal Strengths by Proposal ID"],
response_model=ProposalAllStrengthsResponse,
)
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/strengths/{category}",
self.get_proposal_strengths_by_proposal_and_category,
methods=["GET"],
tags=["Proposal Strengths by Proposal and Category"],
response_model=ProposalAllStrengthsResponse,
)
# self.router.add_api_route(
# "/rfps/{rfp_id}/proposals/{proposal_id}/strengths/{id}",
# self.get_proposal_strengths_by_proposal_and_id,
# methods=["GET"],
# tags=["Proposal Strengths by Proposal and ID"],
# response_model=ProposalStrengthResponse,
# )
# self.router.add_api_route(
# "/proposal-strengths",
# self.create_proposal_strengths,
# methods=["POST"],
# tags=["Proposal Strengths"],
# response_model=ProposalStrengthResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/strengths",
self.create_all_proposal_strengths,
methods=["POST"],
tags=["Proposal Strengths by Proposal ID"],
response_model=ProposalAllStrengthsResponse,
)
# self.router.add_api_route(
# "/proposal-strengths/{id}",
# self.update_proposal_strengths,
# methods=["PUT"],
# tags=["Proposal Strengths by ID"],
# response_model=ProposalStrengthResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/strengths/{category}",
self.update_all_proposal_strengths,
methods=["PUT"],
tags=["Proposal Strengths by Proposal and Category"],
response_model=ProposalAllStrengthsResponse,
)
# self.router.add_api_route(
# "/proposal-strengths/{id}",
# self.delete_proposal_strength,
# methods=["DELETE"],
# tags=["Proposal Strengths by ID"],
# response_model=DeleteResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/strengths",
self.delete_all_proposal_strengths,
methods=["DELETE"],
tags=["Proposal Strengths by Proposal ID"],
response_model=DeleteResponse,
)
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/strengths/{category}",
self.delete_proposal_strengths_by_proposal_and_category,
methods=["DELETE"],
tags=["Proposal Strengths by Proposal and Category"],
response_model=DeleteResponse,
)
# self.router.add_api_route(
# "rfps/{rfp_id}/proposals/{proposal_id}/strengths/{id}",
# self.delete_proposal_strengths_by_proposal_and_id,
# methods=["DELETE"],
# tags=["Proposal Strengths by Proposal and ID"],
# response_model=DeleteResponse,
# )
# self.router.add_api_route(
# "/proposal-weakness",
# self.get_proposal_weakness,
# methods=["GET"],
# tags=["Proposal Weakness"],
# response_model=ProposalWeaknessResponse,
# )
# self.router.add_api_route(
# "/proposal-weakness/{id}",
# self.get_proposal_weakness_by_id,
# methods=["GET"],
# tags=["Proposal Weakness by ID"],
# response_model=ProposalWeaknessResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/weakness",
self.get_proposal_weakness_by_proposal_id,
methods=["GET"],
tags=["Proposal Weakness by Proposal ID"],
response_model=ProposalAllWeaknessesResponse,
)
# self.router.add_api_route(
# "/rfps/{rfp_id}/proposals/{proposal_id}/weakness/{id}",
# self.get_proposal_weakness_by_proposal_and_id,
# methods=["GET"],
# tags=["Proposal Weakness by Proposal and ID"],
# response_model=ProposalWeaknessResponse,
# )
# self.router.add_api_route(
# "/proposal-weakness",
# self.create_proposal_weakness,
# methods=["POST"],
# tags=["Proposal Weakness"],
# response_model=ProposalWeaknessResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/weakness",
self.create_all_proposal_weakness,
methods=["POST"],
tags=["Proposal Weakness by Proposal ID"],
response_model=ProposalAllWeaknessesResponse,
)
# self.router.add_api_route(
# "/proposal-weakness/{id}",
# self.update_proposal_weakness,
# methods=["PUT"],
# tags=["Proposal Weakness by ID"],
# response_model=ProposalWeaknessResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/weakness",
self.update_all_proposal_weakness,
methods=["PUT"],
tags=["Proposal Weakness by Proposal ID"],
response_model=ProposalAllWeaknessesResponse,
)
# self.router.add_api_route(
# "/proposal-weakness/{id}",
# self.delete_proposal_weakness,
# methods=["DELETE"],
# tags=["Proposal Weakness by ID"],
# response_model=DeleteResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/weakness",
self.delete_all_proposal_weakness,
methods=["DELETE"],
tags=["Proposal Weakness by Proposal ID"],
response_model=DeleteResponse,
)
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/weakness/{category}",
self.delete_proposal_weakness_by_proposal_and_category,
methods=["DELETE"],
tags=["Proposal Weakness by Proposal and Category"],
response_model=DeleteResponse,
)
# self.router.add_api_route(
# "/rfps/{rfp_id}/proposals/{proposal_id}/weakness/{id}",
# self.delete_proposal_weakness_by_proposal_and_id,
# methods=["DELETE"],
# tags=["Proposal Weakness by Proposal and ID"],
# response_model=DeleteResponse,
# )
# self.router.add_api_route(
# "/proposal-rejections",
# self.get_proposal_rejections,
# methods=["GET"],
# tags=["Proposal Rejections"],
# response_model=ProposalRejectionReasonResponse,
# )
# self.router.add_api_route(
# "/proposal-rejections/{id}",
# self.get_proposal_rejections_by_id,
# methods=["GET"],
# tags=["Proposal Rejections by ID"],
# response_model=ProposalRejectionReasonResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/rejections",
self.get_proposal_rejections_by_proposal_id,
methods=["GET"],
tags=["Proposal Rejections by Proposal ID"],
response_model=ProposalAllRejectionReasonsResponse,
)
# self.router.add_api_route(
# "/rfps/{rfp_id}/proposals/{proposal_id}/rejections/{id}",
# self.get_proposal_rejections_by_proposal_and_id,
# methods=["GET"],
# tags=["Proposal Rejections by Proposal and ID"],
# response_model=ProposalRejectionReasonResponse,
# )
# self.router.add_api_route(
# "/proposal-rejections",
# self.create_proposal_rejections,
# methods=["POST"],
# tags=["Proposal Rejections"],
# response_model=ProposalRejectionReasonResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/rejections",
self.create_all_proposal_rejections,
methods=["POST"],
tags=["Proposal Rejections by Proposal ID"],
response_model=ProposalAllRejectionReasonsResponse,
)
# self.router.add_api_route(
# "/proposal-rejections/{id}",
# self.update_proposal_rejections,
# methods=["PUT"],
# tags=["Proposal Rejections by ID"],
# response_model=ProposalRejectionReasonResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/rejections",
self.update_all_proposal_rejections,
methods=["PUT"],
tags=["Proposal Rejections by Proposal ID"],
response_model=ProposalAllRejectionReasonsResponse,
)
# self.router.add_api_route(
# "/proposal-rejections/{id}",
# self.delete_proposal_rejections,
# methods=["DELETE"],
# tags=["Proposal Rejections by ID"],
# response_model=DeleteResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/rejections",
self.delete_all_proposal_rejections,
methods=["DELETE"],
tags=["Proposal Rejections by Proposal ID"],
response_model=DeleteResponse,
)
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/rejections/{category}",
self.delete_proposal_rejections_by_proposal_and_category,
methods=["DELETE"],
tags=["Proposal Rejections by Proposal and Category"],
response_model=DeleteResponse,
)
# self.router.add_api_route(
# "/rfps/{rfp_id}/proposals/{proposal_id}/proposal-rejections/{id}",
# self.delete_proposal_rejections_by_proposal_and_id,
# methods=["DELETE"],
# tags=["Proposal Rejections by Proposal and ID"],
# response_model=DeleteResponse,
# )
# self.router.add_api_route(
# "/proposal-improvements",
# self.get_proposal_improvements,
# methods=["GET"],
# tags=["Proposal Improvements"],
# response_model=ProposalImprovementResponse,
# )
# self.router.add_api_route(
# "/proposal-improvements/{id}",
# self.get_proposal_improvements_by_id,
# methods=["GET"],
# tags=["Proposal Improvements by ID"],
# response_model=ProposalImprovementResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/improvements",
self.get_proposal_improvements_by_proposal_id,
methods=["GET"],
tags=["Proposal Improvements by Proposal ID"],
response_model=ProposalAllImprovementsResponse,
)
# self.router.add_api_route(
# "/proposals/{proposal_id}/proposal-improvements/{id}",
# self.get_proposal_improvements_by_proposal_and_id,
# methods=["GET"],
# tags=["Proposal Improvements by Proposal and ID"],
# response_model=ProposalImprovementResponse,
# )
# self.router.add_api_route(
# "/proposal-improvements",
# self.create_proposal_improvements,
# methods=["POST"],
# tags=["Proposal Improvements"],
# response_model=ProposalImprovementResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/improvements",
self.create_all_proposal_improvements,
methods=["POST"],
tags=["Proposal Improvements by Proposal ID"],
response_model=ProposalAllImprovementsResponse,
)
# self.router.add_api_route(
# "/proposal-improvements/{id}",
# self.update_proposal_improvements,
# methods=["PUT"],
# tags=["Proposal Improvements by ID"],
# response_model=ProposalImprovementResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/improvements",
self.update_all_proposal_improvements,
methods=["PUT"],
tags=["Proposal Improvements by Proposal ID"],
response_model=ProposalAllImprovementsResponse,
)
# self.router.add_api_route(
# "/proposal-improvements/{id}",
# self.delete_proposal_improvements,
# methods=["DELETE"],
# tags=["Proposal Improvements by ID"],
# response_model=DeleteResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/improvements",
self.delete_all_proposal_improvements,
methods=["DELETE"],
tags=["Proposal Improvements by Proposal ID"],
response_model=DeleteResponse,
)
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/improvements/{category}",
self.delete_proposal_improvements_by_proposal_and_category,
methods=["DELETE"],
tags=["Proposal Improvements by Proposal and Category"],
response_model=DeleteResponse,
)
# self.router.add_api_route(
# "/proposals/{proposal_id}/proposal-improvements/{id}",
# self.delete_proposal_improvements_by_proposal_and_id,
# methods=["DELETE"],
# tags=["Proposal Improvements by Proposal and ID"],
# response_model=DeleteResponse,
# )
# self.router.add_api_route(
# "/proposal-ai-score",
# self.get_proposal_ai_score,
# methods=["GET"],
# tags=["Proposal AI Score"],
# response_model=ProposalAIAnalysisResponse,
# )
# self.router.add_api_route(
# "/proposal-ai-score/{id}",
# self.get_proposal_ai_score_by_id,
# methods=["GET"],
# tags=["Proposal AI Score by ID"],
# response_model=ProposalAIAnalysisResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/ai-score",
self.get_proposal_ai_score_by_proposal_id,
methods=["GET"],
tags=["Proposal AI Score by Proposal ID"],
response_model=ProposalAIAnalysisResponse,
)
# self.router.add_api_route(
# "/proposals/{proposal_id}/proposal-ai-score/{id}",
# self.get_proposal_ai_score_by_proposal_and_id,
# methods=["GET"],
# tags=["Proposal AI Score by Proposal and ID"],
# response_model=ProposalAIAnalysisResponse,
# )
# self.router.add_api_route(
# "/proposal-ai-score",
# self.create_proposal_ai_score,
# methods=["POST"],
# tags=["Proposal AI Score"],
# response_model=ProposalAIAnalysisResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/ai-score",
self.create_proposal_ai_score_by_proposal_id,
methods=["POST"],
tags=["Proposal AI Score by Proposal ID"],
response_model=ProposalAIAnalysisResponse,
)
# self.router.add_api_route(
# "/proposal-ai-score/{id}",
# self.update_proposal_ai_score,
# methods=["PUT"],
# tags=["Proposal AI Score by ID"],
# response_model=ProposalAIAnalysisResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/ai-score",
self.update_proposal_ai_score_by_proposal_id,
methods=["PUT"],
tags=["Proposal AI Score by Proposal ID"],
response_model=ProposalAIAnalysisResponse,
)
# self.router.add_api_route(
# "/proposal-ai-score/{id}",
# self.delete_proposal_ai_score,
# methods=["DELETE"],
# tags=["Proposal AI Score by ID"],
# response_model=DeleteResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/ai-score",
self.delete_proposal_ai_score_by_proposal_id,
methods=["DELETE"],
tags=["Proposal AI Score by Proposal ID"],
response_model=DeleteResponse,
)
# self.router.add_api_route(
# "/proposals/{proposal_id}/proposal-ai-score/{id}",
# self.delete_proposal_ai_score_by_proposal_and_id,
# methods=["DELETE"],
# tags=["Proposal AI Score by Proposal and ID"],
# response_model=DeleteResponse,
# )
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/analysis",
self.get_all_proposal_analysis,
methods=["GET"],
tags=["Proposal Complete Analysis"],
response_model=ProposalCompleteAnalysisResponse,
)
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/analysis",
self.create_proposal_analysis,
methods=["POST"],
tags=["Proposal Complete Analysis"],
response_model=ProposalCompleteAnalysisResponse,
)
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/analysis",
self.update_proposal_analysis,
methods=["PUT"],
tags=["Proposal Complete Analysis"],
response_model=ProposalCompleteAnalysisResponse,
)
self.router.add_api_route(
"/rfps/{rfp_id}/proposals/{proposal_id}/analysis",
self.delete_proposal_analysis,
methods=["DELETE"],
tags=["Proposal Complete Analysis"],
response_model=DeleteResponse,
)
async def get_proposal_strengths(
self
):
async with self.__service() as service:
try:
strengths = await service.get_all_data(
query_type=QueryType.STRENGTHS
)
return ProposalStrengthResponse(
status="success", data=[ProposalStrength(**s) for s in strengths]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve strengths."
)
async def get_proposal_strengths_by_id(self, id: UUID = Path(...)):
async with self.__service() as service:
try:
strength = await service.get_all_data(
query_type=QueryType.STRENGTHS, id=id
)
return ProposalStrengthResponse(
status="success", data=[ProposalStrength(**s) for s in strength]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve strength."
)
async def get_proposal_strengths_by_proposal_id(self, rfp_id: UUID = Path(...), proposal_id: UUID = Path(...)):
async with self.__service() as service:
try:
strength = await service.get_all_data(
query_type=QueryType.STRENGTHS, proposal_id=proposal_id
)
return ProposalAllStrengthsResponse(
status="success", data=[s["strength_point"] for s in strength]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve strength."
)
async def get_proposal_strengths_by_proposal_and_category(self, rfp_id: UUID = Path(...), proposal_id: UUID = Path(...), category: Category = Path(...)):
async with self.__service() as service:
try:
strength = await service.get_all_data(
query_type=QueryType.STRENGTHS, proposal_id=proposal_id, category=category
)
return ProposalAllStrengthsResponse(
status="success", data=[s["strength_point"] for s in strength]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve strength."
)
async def get_proposal_strengths_by_proposal_and_id(self, rfp_id: UUID = Path(...), proposal_id: UUID = Path(...), id: UUID = Path(...)):
async with self.__service() as service:
try:
strength = await service.get_all_data(
query_type=QueryType.STRENGTHS, proposal_id=proposal_id, id=id
)
return ProposalStrengthResponse(
status="success", data=[ProposalStrength(**s) for s in strength]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve strength."
)
async def create_proposal_strengths(self, strength: ProposalStrengthRequest):
async with self.__service() as service:
try:
created = await service.create_data(
query_type=QueryType.STRENGTHS,
create_or_update_type=CreateOrUpdateType.ID,
data=strength.model_dump(mode="json"),
)
return ProposalStrengthResponse(
status="success", data=[ProposalStrength(**s) for s in created]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create strength."
)
async def create_all_proposal_strengths(
self, strengths: CreateAllProposalStrengthsRequest, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
strengths_request = strengths.model_dump(mode="json", exclude_unset=True)
strengths_request["proposal_id"] = proposal_id
created = await service.create_data(
query_type=QueryType.STRENGTHS,
create_or_update_type=CreateOrUpdateType.ALL,
data=strengths_request,
)
return ProposalAllStrengthsResponse(
status="success", data=[s["strength_point"] for s in created]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create strengths."
)
async def update_proposal_strengths(self, strength: UpdateProposalStrengthRequest, id: UUID = Path(...)):
async with self.__service() as service:
try:
strength_request = strength.model_dump(mode="json", exclude_unset=True)
strength_request["id"] = id
updated = await service.update_data(
query_type=QueryType.STRENGTHS,
create_or_update_type=CreateOrUpdateType.ID,
data=strength_request,
)
return ProposalStrengthResponse(
status="success", data=[ProposalStrength(**s) for s in updated]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update strength."
)
async def update_all_proposal_strengths(
self, strengths: UpdateAllProposalStrengthsRequest, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...), category: Category = Path(...)
):
async with self.__service() as service:
try:
strengths_request = strengths.model_dump(mode="json", exclude_unset=True)
strengths_request["proposal_id"] = proposal_id
strengths_request["category"] = category
updated = await service.update_data(
query_type=QueryType.STRENGTHS,
create_or_update_type=CreateOrUpdateType.ALL,
data=strengths_request,
)
return ProposalAllStrengthsResponse(
status="success", data=[s["strength_point"] for s in updated]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update strengths."
)
async def delete_proposal_strength(
self, id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.STRENGTHS, id=id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete strength."
)
async def delete_all_proposal_strengths(self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.STRENGTHS, proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete strengths."
)
async def delete_proposal_strengths_by_proposal_and_category(self, proposal_id: UUID = Path(...), category: Category = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.STRENGTHS, proposal_id=proposal_id, category=category
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete strength."
)
async def delete_proposal_strengths_by_proposal_and_id(self, proposal_id: UUID = Path(...), id: UUID = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.STRENGTHS, proposal_id=proposal_id, id=id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete strength."
)
async def get_proposal_weakness(
self
):
async with self.__service() as service:
try:
weaknesses = await service.get_all_data(
query_type=QueryType.WEAKNESSES
)
return ProposalWeaknessResponse(
status="success", data=[ProposalWeakness(**w) for w in weaknesses]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve weaknesses."
)
async def get_proposal_weakness_by_id(self, id: UUID = Path(...)):
async with self.__service() as service:
try:
weakness = await service.get_all_data(
query_type=QueryType.WEAKNESSES, id=id
)
return ProposalWeaknessResponse(
status="success", data=[ProposalWeakness(**w) for w in weakness]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve weakness."
)
async def get_proposal_weakness_by_proposal_id(self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...), category: Category = Query(None)):
async with self.__service() as service:
try:
weakness = await service.get_all_data(
query_type=QueryType.WEAKNESSES, proposal_id=proposal_id, category=category
)
return ProposalAllWeaknessesResponse(
status="success", data=[w["weakness_point"] for w in weakness]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve weakness."
)
async def get_proposal_weakness_by_proposal_and_id(self, proposal_id: UUID = Path(...), id: UUID = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
weakness = await service.get_all_data(
query_type=QueryType.WEAKNESSES, proposal_id=proposal_id, id=id
)
return ProposalWeaknessResponse(
status="success", data=[ProposalWeakness(**w) for w in weakness]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve weakness."
)
async def create_proposal_weakness(self, weakness: ProposalWeaknessRequest):
async with self.__service() as service:
try:
created = await service.create_data(
query_type=QueryType.WEAKNESSES,
create_or_update_type=CreateOrUpdateType.ID,
data=weakness.model_dump(mode="json"),
)
return ProposalWeaknessResponse(
status="success", data=[ProposalWeakness(**w) for w in created]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create weakness."
)
async def create_all_proposal_weakness(
self, weaknesses: CreateAllProposalWeaknessRequest, proposal_id: UUID
):
async with self.__service() as service:
try:
weakness_request = weaknesses.model_dump(mode="json", exclude_unset=True)
weakness_request["proposal_id"] = proposal_id
created = await service.create_data(
query_type=QueryType.WEAKNESSES,
create_or_update_type=CreateOrUpdateType.ALL,
data=weakness_request,
)
return ProposalAllWeaknessesResponse(
status="success", data=[w["weakness_point"] for w in created]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create weaknesses."
)
async def update_proposal_weakness(self, weakness: UpdateProposalWeaknessRequest, id: UUID = Path(...)):
async with self.__service() as service:
try:
weakness_request = weakness.model_dump(mode="json", exclude_unset=True)
weakness_request["id"] = id
updated = await service.update_data(
query_type=QueryType.WEAKNESSES,
create_or_update_type=CreateOrUpdateType.ID,
data=weakness_request,
)
return ProposalWeaknessResponse(
status="success", data=[ProposalWeakness(**w) for w in updated]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update weakness."
)
async def update_all_proposal_weakness(
self, weaknesses: CreateAllProposalWeaknessRequest, proposal_id: UUID = Path(...)
):
async with self.__service() as service:
try:
weakness_request = weaknesses.model_dump(mode="json", exclude_unset=True)
weakness_request["proposal_id"] = proposal_id
updated = await service.update_data(
query_type=QueryType.WEAKNESSES,
create_or_update_type=CreateOrUpdateType.ALL,
data=weakness_request,
)
return ProposalAllWeaknessesResponse(
status="success", data=[w["weakness_point"] for w in updated]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update weaknesses."
)
async def delete_proposal_weakness(
self, id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.WEAKNESSES, id=id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete weakness."
)
async def delete_all_proposal_weakness(
self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.WEAKNESSES, proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete weaknesses."
)
async def delete_proposal_weakness_by_proposal_and_category(self, proposal_id: UUID = Path(...), category: Category = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.WEAKNESSES, proposal_id=proposal_id, category=category
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete weakness."
)
async def delete_proposal_weakness_by_proposal_and_id(self, proposal_id: UUID = Path(...), id: UUID = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.WEAKNESSES, proposal_id=proposal_id, id=id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete weakness."
)
async def get_proposal_rejections(
self
):
async with self.__service() as service:
try:
rejection_reasons = await service.get_all_data(
query_type=QueryType.REJECTION_REASONS
)
return ProposalRejectionReasonResponse(
status="success",
data=[ProposalRejectionReason(**r) for r in rejection_reasons],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve rejection reasons."
)
async def get_proposal_rejections_by_id(self, id: UUID = Path(...)):
async with self.__service() as service:
try:
rejection_reason = await service.get_all_data(
query_type=QueryType.REJECTION_REASONS, id=id
)
return ProposalRejectionReasonResponse(
status="success", data=[ProposalRejectionReason(**r) for r in rejection_reason]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve rejection reason."
)
async def get_proposal_rejections_by_proposal_id(self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...), category: Category = Query(None)):
async with self.__service() as service:
try:
rejection_reason = await service.get_all_data(
query_type=QueryType.REJECTION_REASONS, proposal_id=proposal_id, category=category
)
return ProposalAllRejectionReasonsResponse(
status="success", data=[r["reason"] for r in rejection_reason]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve rejection reason."
)
async def get_proposal_rejections_by_proposal_and_id(self, proposal_id: UUID = Path(...), id: UUID = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
rejection_reason = await service.get_all_data(
query_type=QueryType.REJECTION_REASONS, proposal_id=proposal_id, id=id
)
return ProposalRejectionReasonResponse(
status="success", data=[ProposalRejectionReason(**r) for r in rejection_reason]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve rejection reason."
)
async def create_proposal_rejections(
self, rejection_reason: ProposalRejectionReasonRequest
):
async with self.__service() as service:
try:
created = await service.create_data(
query_type=QueryType.REJECTION_REASONS,
create_or_update_type=CreateOrUpdateType.ID,
data=rejection_reason.model_dump(mode="json"),
)
return ProposalRejectionReasonResponse(
status="success",
data=[ProposalRejectionReason(**r) for r in created],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create rejection reason."
)
async def create_all_proposal_rejections(
self, rejection_reasons: CreateAllProposalRejectionReasonsRequest, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
rejection_reasons_data = rejection_reasons.model_dump(mode="json", exclude_unset=True)
rejection_reasons_data["proposal_id"] = proposal_id
created = await service.create_data(
query_type=QueryType.REJECTION_REASONS,
create_or_update_type=CreateOrUpdateType.ALL,
data=rejection_reasons_data,
)
return ProposalAllRejectionReasonsResponse(
status="success",
data=[r["reason"] for r in created],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create rejection reasons."
)
async def update_proposal_rejections(
self, rejection_reason: UpdateProposalRejectionReasonRequest, id: UUID = Path(...)
):
async with self.__service() as service:
try:
rejection_reason_data = rejection_reason.model_dump(mode="json", exclude_unset=True)
rejection_reason_data["id"] = id
updated = await service.update_data(
query_type=QueryType.REJECTION_REASONS,
create_or_update_type=CreateOrUpdateType.ID,
data=rejection_reason_data,
)
return ProposalRejectionReasonResponse(
status="success",
data=[ProposalRejectionReason(**r) for r in updated],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update rejection reason."
)
async def update_all_proposal_rejections(
self, rejection_reasons: CreateAllProposalRejectionReasonsRequest, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
rejection_reasons_data = rejection_reasons.model_dump(mode="json", exclude_unset=True)
rejection_reasons_data["proposal_id"] = proposal_id
updated = await service.update_data(
query_type=QueryType.REJECTION_REASONS,
create_or_update_type=CreateOrUpdateType.ALL,
data=rejection_reasons_data,
)
return ProposalAllRejectionReasonsResponse(
status="success",
data=[r["reason"] for r in updated],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update rejection reasons."
)
async def delete_proposal_rejections(
self, id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.REJECTION_REASONS,
id=id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete rejection reason."
)
async def delete_all_proposal_rejections(
self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.REJECTION_REASONS,
proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete rejection reasons."
)
async def delete_proposal_rejections_by_proposal_and_category(
self, proposal_id: UUID = Path(...), category: str = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.REJECTION_REASONS,
category=category,
proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete rejection reason."
)
async def delete_proposal_rejections_by_proposal_and_id(
self, proposal_id: UUID = Path(...), id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.REJECTION_REASONS,
id=id,
proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete rejection reason."
)
async def get_proposal_improvements(
self
):
async with self.__service() as service:
try:
improvements = await service.get_all_data(
query_type=QueryType.IMPROVEMENTS
)
return ProposalImprovementResponse(
status="success",
data=[ProposalImprovement(**r) for r in improvements],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve improvements."
)
async def get_proposal_improvements_by_id(
self, id: UUID = Path(...)
):
async with self.__service() as service:
try:
improvements = await service.get_all_data(
query_type=QueryType.IMPROVEMENTS,
id=id
)
return ProposalImprovementResponse(
status="success",
data=[ProposalImprovement(**r) for r in improvements],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve improvements."
)
async def get_proposal_improvements_by_proposal_id(
self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...), category: Category = Query(None)
):
async with self.__service() as service:
try:
improvements = await service.get_all_data(
query_type=QueryType.IMPROVEMENTS,
proposal_id=proposal_id,
category=category
)
return ProposalAllImprovementsResponse(
status="success",
data=[r["improvement_point"] for r in improvements],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve improvements."
)
async def get_proposal_improvements_by_proposal_and_id(
self, proposal_id: UUID = Path(...), id: UUID = Path(...)
):
async with self.__service() as service:
try:
improvements = await service.get_all_data(
query_type=QueryType.IMPROVEMENTS,
id=id,
proposal_id=proposal_id
)
return ProposalImprovementResponse(
status="success",
data=[ProposalImprovement(**r) for r in improvements],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve improvements."
)
async def create_proposal_improvements(
self, improvement: ProposalImprovementRequest
):
async with self.__service() as service:
try:
created = await service.create_data(
query_type=QueryType.IMPROVEMENTS,
create_or_update_type=CreateOrUpdateType.ID,
data=improvement.model_dump(mode="json"),
)
return ProposalImprovementResponse(
status="success", data=[ProposalImprovement(**r) for r in created]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create improvement."
)
async def create_all_proposal_improvements(
self, improvements: CreateAllProposalImprovementsRequest, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
data = improvements.model_dump(mode="json", exclude_unset=True)
data["proposal_id"] = proposal_id
created = await service.create_data(
query_type=QueryType.IMPROVEMENTS,
create_or_update_type=CreateOrUpdateType.ALL,
data=data,
)
return ProposalAllImprovementsResponse(
status="success", data=[r["improvement_point"] for r in created]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create improvements."
)
async def update_proposal_improvements(
self, improvement: UpdateProposalImprovementRequest, id: UUID = Path(...)
):
async with self.__service() as service:
try:
data = improvement.model_dump(mode="json", exclude_unset=True)
data["id"] = id
updated = await service.update_data(
query_type=QueryType.IMPROVEMENTS,
create_or_update_type=CreateOrUpdateType.ID,
data=data,
)
return ProposalImprovementResponse(
status="success", data=[ProposalImprovement(**r) for r in updated]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update improvement."
)
async def update_all_proposal_improvements(
self, improvements: CreateAllProposalImprovementsRequest, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
data = improvements.model_dump(mode="json", exclude_unset=True)
data["proposal_id"] = proposal_id
updated = await service.update_data(
query_type=QueryType.IMPROVEMENTS,
create_or_update_type=CreateOrUpdateType.ALL,
data=data,
)
return ProposalAllImprovementsResponse(
status="success", data=[r["improvement_point"] for r in updated]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update improvements."
)
async def delete_proposal_improvements(
self, id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.IMPROVEMENTS, id=id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete improvement."
)
async def delete_all_proposal_improvements(
self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.IMPROVEMENTS, proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete improvements."
)
async def delete_proposal_improvements_by_proposal_and_category(
self, category: str = Path(...), proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.IMPROVEMENTS, category=category, proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete improvement."
)
async def delete_proposal_improvements_by_proposal_and_id(
self, id: UUID = Path(...), proposal_id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.IMPROVEMENTS, id=id, proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete improvement."
)
async def get_proposal_ai_score(
self
):
async with self.__service() as service:
try:
scores = await service.get_all_data(
query_type=QueryType.AI_SCORE
)
return ProposalAIAnalysisResponse(
status="success", data=[ProposalAIAnalysis(**r) for r in scores]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve AI scores."
)
async def get_proposal_ai_score_by_id(
self, id: UUID = Path(...)
):
async with self.__service() as service:
try:
scores = await service.get_all_data(
query_type=QueryType.AI_SCORE, id=id
)
return ProposalAIAnalysisResponse(
status="success", data=[ProposalAIAnalysis(**r) for r in scores]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve AI scores."
)
async def get_proposal_ai_score_by_proposal_id(
self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
scores = await service.get_all_data(
query_type=QueryType.AI_SCORE, proposal_id=proposal_id
)
return ProposalAIAnalysisResponse(
status="success", data=[ProposalAIAnalysis(**r) for r in scores]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve AI scores."
)
async def get_proposal_ai_score_by_proposal_and_id(
self, id: UUID = Path(...), proposal_id: UUID = Path(...)
):
async with self.__service() as service:
try:
scores = await service.get_all_data(
query_type=QueryType.AI_SCORE, id=id, proposal_id=proposal_id
)
return ProposalAIAnalysisResponse(
status="success", data=[ProposalAIAnalysis(**r) for r in scores]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve AI scores."
)
async def create_proposal_ai_score(self, score: CreateAiAnalysisRequest):
async with self.__service() as service:
try:
created = await service.create_data(
query_type=QueryType.AI_SCORE,
create_or_update_type=CreateOrUpdateType.ID,
data=score.model_dump(mode="json"),
)
return ProposalAIAnalysisResponse(
status="success", data=[ProposalAIAnalysis(**r) for r in created]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create AI score."
)
async def create_proposal_ai_score_by_proposal_id(self, score: CreateAIAnalysisRequestByProposalId, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
data = score.model_dump(mode="json", exclude_unset=True)
data["proposal_id"] = proposal_id
created = await service.create_data(
query_type=QueryType.AI_SCORE,
create_or_update_type=CreateOrUpdateType.ID,
data=data,
)
return ProposalAIAnalysisResponse(
status="success", data=[ProposalAIAnalysis(**r) for r in created]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create AI score."
)
async def update_proposal_ai_score(self, score: UpdateAiAnalysisRequest, id: UUID = Path(...)):
async with self.__service() as service:
try:
if id:
data = score.model_dump(mode="json", exclude_unset=True)
data["id"] = id
updated = await service.update_data(
query_type=QueryType.AI_SCORE,
create_or_update_type=CreateOrUpdateType.ID,
data=data,
)
return ProposalAIAnalysisResponse(
status="success", data=[ProposalAIAnalysis(**r) for r in updated]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update AI score."
)
async def update_proposal_ai_score_by_proposal_id(self, score: UpdateAIAnalysisRequestByProposalId, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
data = score.model_dump(mode="json", exclude_unset=True)
data["proposal_id"] = proposal_id
updated = await service.update_data(
query_type=QueryType.AI_SCORE,
create_or_update_type=CreateOrUpdateType.ALL,
data=data,
)
return ProposalAIAnalysisResponse(
status="success", data=[ProposalAIAnalysis(**r) for r in updated]
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update AI score."
)
async def delete_proposal_ai_score(
self, id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.AI_SCORE, id=id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete AI score."
)
async def delete_proposal_ai_score_by_proposal_id(
self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.AI_SCORE, proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete AI score."
)
async def delete_proposal_ai_score_by_proposal_and_id(
self, id: UUID = Path(...), proposal_id: UUID = Path(...)
):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.AI_SCORE, id=id, proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete AI score."
)
async def get_all_proposal_analysis(self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
analysis = await service.get_all_data(
query_type=QueryType.ALL, proposal_id=proposal_id
)
return ProposalCompleteAnalysisResponse(
status="success",
data=[ProposalCompleteAnalysis(**analysis)],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to retrieve analysis."
)
async def create_proposal_analysis(
self, analysis: CreateAllProposalAnalysisRequest, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
data = analysis.model_dump(mode="json", exclude_unset=True)
data["proposal_id"] = proposal_id
created = await service.create_data(
query_type=QueryType.ALL,
create_or_update_type=CreateOrUpdateType.ALL,
data=data,
)
return ProposalCompleteAnalysisResponse(
status="success",
data=[ProposalCompleteAnalysis(**created)],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to create analysis."
)
async def update_proposal_analysis(
self, analysis: UpdateAllProposalAnalysisRequest, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)
):
async with self.__service() as service:
try:
data = analysis.model_dump(mode="json", exclude_unset=True)
data["proposal_id"] = proposal_id
updated = await service.update_data(
query_type=QueryType.ALL,
create_or_update_type=CreateOrUpdateType.ALL,
data=data,
)
return ProposalCompleteAnalysisResponse(
status="success",
data=[ProposalCompleteAnalysis(**updated)],
)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to update analysis."
)
async def delete_proposal_analysis(self, proposal_id: UUID = Path(...), rfp_id: UUID = Path(...)):
async with self.__service() as service:
try:
result = await service.delete_data(
query_type=QueryType.ALL, proposal_id=proposal_id
)
return DeleteResponse(status="success")
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=500, detail="Failed to delete analysis."
)