diff --git a/api/birdxplorer_api/routers/data.py b/api/birdxplorer_api/routers/data.py index 9af0e71..b496eed 100644 --- a/api/birdxplorer_api/routers/data.py +++ b/api/birdxplorer_api/routers/data.py @@ -3,6 +3,7 @@ from dateutil.parser import parse as dateutil_parse from fastapi import APIRouter, HTTPException, Query, Request +from pydantic import HttpUrl from birdxplorer_common.models import ( BaseModel, @@ -126,6 +127,9 @@ def get_posts( total_count = len(posts) paginated_posts = posts[offset : offset + limit] + for post in paginated_posts: + post.link = HttpUrl(f"https://x.com/{post.x_user.name}/status/{post.post_id}") + base_url = str(request.url).split("?")[0] next_offset = offset + limit prev_offset = max(offset - limit, 0) diff --git a/common/birdxplorer_common/models.py b/common/birdxplorer_common/models.py index 7e3ab8e..72052dd 100644 --- a/common/birdxplorer_common/models.py +++ b/common/birdxplorer_common/models.py @@ -679,6 +679,7 @@ class XUser(BaseModel): class Post(BaseModel): post_id: PostId + link: Optional[HttpUrl] = None x_user_id: UserId x_user: XUser text: str diff --git a/common/tests/conftest.py b/common/tests/conftest.py index 5af7934..a8c048b 100644 --- a/common/tests/conftest.py +++ b/common/tests/conftest.py @@ -205,6 +205,7 @@ def post_samples(post_factory: PostFactory, x_user_samples: List[XUser]) -> Gene posts = [ post_factory.build( post_id="2234567890123456781", + link=None, x_user_id="1234567890123456781", x_user=x_user_samples[0], text="""\ @@ -219,6 +220,7 @@ def post_samples(post_factory: PostFactory, x_user_samples: List[XUser]) -> Gene ), post_factory.build( post_id="2234567890123456791", + link=None, x_user_id="1234567890123456781", x_user=x_user_samples[0], text="""\ @@ -233,6 +235,7 @@ def post_samples(post_factory: PostFactory, x_user_samples: List[XUser]) -> Gene ), post_factory.build( post_id="2234567890123456801", + link=None, x_user_id="1234567890123456782", x_user=x_user_samples[1], text="""\