Skip to content

Commit

Permalink
Merge pull request #101 from codeforjapan/postLink
Browse files Browse the repository at this point in the history
Links Added to Posts in the Response
  • Loading branch information
yu23ki14 authored Aug 18, 2024
2 parents ea859de + 88a7c07 commit d0a8258
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
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 @@ -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)
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="""\
Expand All @@ -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="""\
Expand All @@ -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="""\
Expand Down

0 comments on commit d0a8258

Please sign in to comment.