Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links Added to Posts in the Response #101

Merged
merged 3 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/birdxplorer_api/routers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -123,6 +124,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)
Expand Down
1 change: 1 addition & 0 deletions common/birdxplorer_common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions common/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="text11",
Expand All @@ -216,6 +217,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="text12",
Expand All @@ -227,6 +229,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="text21",
Expand Down
Loading