From 7594a73290bc4322cad99843b000b580ae79d1a7 Mon Sep 17 00:00:00 2001 From: seeleng Date: Tue, 24 Sep 2024 03:36:22 +0800 Subject: [PATCH] fix: add original article to event routes --- backend/src/events/dependencies.py | 1 + backend/src/events/router.py | 1 + backend/src/events/schemas.py | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/backend/src/events/dependencies.py b/backend/src/events/dependencies.py index a32d3f0c..10465bc6 100644 --- a/backend/src/events/dependencies.py +++ b/backend/src/events/dependencies.py @@ -22,6 +22,7 @@ def retrieve_event( Event.categories, ), selectinload(Event.analysises, Analysis.category), + selectinload(Event.original_article), ) ) if not event: diff --git a/backend/src/events/router.py b/backend/src/events/router.py index 106e9f8f..6ccf0e9f 100644 --- a/backend/src/events/router.py +++ b/backend/src/events/router.py @@ -35,6 +35,7 @@ def get_events( event_query = ( select(Event) .options(selectinload(Event.categories)) + .options(selectinload(Event.original_article)) .where(Event.id.in_(relevant_ids)) ) if limit is not None: diff --git a/backend/src/events/schemas.py b/backend/src/events/schemas.py index c0fc3af9..6a8f79c0 100644 --- a/backend/src/events/schemas.py +++ b/backend/src/events/schemas.py @@ -1,6 +1,19 @@ from datetime import datetime from pydantic import BaseModel, ConfigDict from src.categories.schemas import CategoryDTO +from src.events.models import ArticleSource + + +class ArticleDTO(BaseModel): + model_config = ConfigDict(from_attributes=True) + id: int + title: str + summary: str + body: str + url: str + source: ArticleSource + date: datetime + image_url: str class MiniEventDTO(BaseModel): @@ -12,6 +25,7 @@ class MiniEventDTO(BaseModel): date: datetime categories: list[CategoryDTO] + original_article: ArticleDTO class AnalysisDTO(BaseModel):