From 1173ac574d7da4b071aaa97e79b9c1aaf3dc485d Mon Sep 17 00:00:00 2001 From: Nox Date: Thu, 7 Dec 2023 14:45:08 -0300 Subject: [PATCH] Refactor get_all_certified_requests function to include user information --- .../web/api/certified_request/views.py | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/identity_socializer/web/api/certified_request/views.py b/identity_socializer/web/api/certified_request/views.py index 8b410c1..418a3f9 100644 --- a/identity_socializer/web/api/certified_request/views.py +++ b/identity_socializer/web/api/certified_request/views.py @@ -1,4 +1,4 @@ -from typing import List +from typing import Any from fastapi import APIRouter, Depends @@ -7,7 +7,6 @@ StatusRequest, ) from identity_socializer.db.dao.user_dao import UserDAO -from identity_socializer.db.models.certified_request_model import CertifiedRequestModel from identity_socializer.web.api.certified_request.schema import CertifiedRequestDTO router = APIRouter() @@ -36,10 +35,35 @@ async def create_certified_request( async def get_all_certified_requests( limit: int = 10, offset: int = 0, - dao: CertifiedRequestDAO = Depends(), -) -> List[CertifiedRequestModel]: + cq_dao: CertifiedRequestDAO = Depends(), + user_dao: UserDAO = Depends(), +) -> Any: """Get all certified requests.""" - return await dao.get_all_certified_requests(limit=limit, offset=offset) + completed_cqs = [] + + certifieds = await cq_dao.get_all_certified_requests(limit=limit, offset=offset) + + for certified in certifieds: + + user = await user_dao.get_user_by_id(certified.user_id) + + username = user.username if user else "unknown" + email = user.email if user else "unknown" + + completed_cq = { + "id": certified.id, + "user_id": certified.user_id, + "dni": certified.dni, + "img1_url": certified.img1_url, + "img2_url": certified.img2_url, + "status": certified.status, + "created_at": certified.created_at, + "username": username, + "email": email, + } + completed_cqs.append(completed_cq) + + return completed_cqs @router.delete("/delete/{certified_request_id}", response_model=None)