From 441cfdbbc18ca234710082b3f8cdd2513b5d7dc2 Mon Sep 17 00:00:00 2001 From: jasta Date: Sat, 17 Aug 2024 14:51:38 +0900 Subject: [PATCH] add pagenation meta class --- api/birdxplorer_api/routers/data.py | 10 ++++++---- common/birdxplorer_common/models.py | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/api/birdxplorer_api/routers/data.py b/api/birdxplorer_api/routers/data.py index ee6f1a7..f5ea26c 100644 --- a/api/birdxplorer_api/routers/data.py +++ b/api/birdxplorer_api/routers/data.py @@ -16,6 +16,7 @@ TopicId, TwitterTimestamp, UserEnrollment, + PagenationMeta ) from birdxplorer_common.storage import Storage @@ -30,6 +31,7 @@ class NoteListResponse(BaseModel): class PostListResponse(BaseModel): data: List[Post] + meta: PagenationMeta def str_to_twitter_timestamp(s: str) -> TwitterTimestamp: @@ -133,10 +135,10 @@ def get_posts( return PostListResponse( data=paginated_posts, - meta={ - "next": next_url, - "prev": prev_url - } + meta=PagenationMeta( + next=next_url, + prev=prev_url + ) ) return router diff --git a/common/birdxplorer_common/models.py b/common/birdxplorer_common/models.py index 7a1803a..afb876a 100644 --- a/common/birdxplorer_common/models.py +++ b/common/birdxplorer_common/models.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod from datetime import datetime, timezone from enum import Enum -from typing import Any, Dict, List, Literal, Type, TypeAlias, TypeVar, Union +from typing import Any, Dict, List, Literal, Type, TypeAlias, TypeVar, Union, Optional from pydantic import BaseModel as PydanticBaseModel from pydantic import ConfigDict, GetCoreSchemaHandler, HttpUrl, TypeAdapter @@ -672,3 +672,7 @@ class Post(BaseModel): like_count: NonNegativeInt repost_count: NonNegativeInt impression_count: NonNegativeInt + +class PagenationMeta(BaseModel): + next: Optional[HttpUrl] = None + prev: Optional[HttpUrl] = None \ No newline at end of file