+
Skip to content

feat: add galnet pagination #131

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

Merged
merged 2 commits into from
Jun 2, 2025
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
7 changes: 5 additions & 2 deletions app/routers/galnet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from fastapi import APIRouter, Depends
from typing import Annotated

from fastapi import APIRouter, Depends, Query

from app.models.galnet import GalnetArticle
from app.models.language import Language
Expand All @@ -10,7 +12,8 @@
@router.get("", response_model=list[GalnetArticle])
async def get_latest_articles(
lang: Language = Language.ENGLISH,
page: Annotated[int, Query(ge=1)] = 1,
galnet_service: GalnetService = Depends(),
) -> list[GalnetArticle]:
"""Get latest Galnet news."""
return await galnet_service.get_articles(lang)
return await galnet_service.get_articles(lang, page)
14 changes: 12 additions & 2 deletions app/services/galnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ class GalnetService:
"""Main class for the Galnet service."""

BASE_PICTURE_PATH = "http://hosting.zaonce.net/elite-dangerous/galnet"
NUMBER_OF_ARTICLES = 50

async def get_articles(self, language: Language) -> list[GalnetArticle]:
def _get_offset_for_articles(self, page: int) -> int:
"""
Get the offset for articles.
"""
return (page - 1) * self.NUMBER_OF_ARTICLES

async def get_articles(self, language: Language, page: int) -> list[GalnetArticle]:
"""Get the latest Galnet articles.

:raises ContentFetchingException: Unable to retrieve the articles
"""
url = f"{get_frontier_api_url_for_language(language)}/galnet_article?&sort=-published_at&page[offset]=0&page[limit]=12"
url = (
f"{get_frontier_api_url_for_language(language)}/galnet_article?&sort=-published_at"
f"&page[offset]={self._get_offset_for_articles(page)}&page[limit]={self.NUMBER_OF_ARTICLES}"
)
async with get_async_httpx_client() as client:
try:
api_response = await client.get(url)
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载