修复前后端显示异常问题(受试者、中心、负责人、日期等)
This commit is contained in:
@@ -15,6 +15,7 @@ from app.crud import user as user_crud
|
||||
from app.crud import member as member_crud
|
||||
from app.core.security import decode_token
|
||||
from app.schemas.attachment import AttachmentRead
|
||||
from app.schemas.user import UserDisplay
|
||||
|
||||
router = APIRouter()
|
||||
global_router = APIRouter()
|
||||
@@ -74,7 +75,14 @@ async def upload_attachment(
|
||||
operator_id=current_user.id,
|
||||
operator_role=current_user.role,
|
||||
)
|
||||
return attachment
|
||||
return AttachmentRead(
|
||||
id=attachment.id,
|
||||
filename=attachment.filename,
|
||||
file_size=attachment.file_size,
|
||||
uploaded_by=UserDisplay.model_validate(current_user) if current_user else None,
|
||||
uploaded_by_id=attachment.uploaded_by,
|
||||
uploaded_at=attachment.uploaded_at,
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
@@ -90,7 +98,22 @@ async def list_attachments(
|
||||
) -> list[AttachmentRead]:
|
||||
await _ensure_study_exists(db, study_id)
|
||||
attachments = await attachment_crud.list_attachments(db, study_id, entity_type, entity_id)
|
||||
return list(attachments)
|
||||
user_ids = {a.uploaded_by for a in attachments if a.uploaded_by}
|
||||
users_map = await user_crud.get_users_by_ids(db, user_ids)
|
||||
result: list[AttachmentRead] = []
|
||||
for a in attachments:
|
||||
user = users_map.get(a.uploaded_by)
|
||||
result.append(
|
||||
AttachmentRead(
|
||||
id=a.id,
|
||||
filename=a.filename,
|
||||
file_size=a.file_size,
|
||||
uploaded_by=UserDisplay.model_validate(user) if user else None,
|
||||
uploaded_by_id=a.uploaded_by,
|
||||
uploaded_at=a.uploaded_at,
|
||||
)
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
@router.get(
|
||||
|
||||
Reference in New Issue
Block a user