Skip to content

Commit

Permalink
名称をMediaに統一
Browse files Browse the repository at this point in the history
  • Loading branch information
sushichan044 committed Oct 8, 2024
1 parent f26dc80 commit 20dff3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions common/birdxplorer_common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,19 +694,19 @@ class XUser(BaseModel):


# ref: https://developer.x.com/en/docs/x-api/data-dictionary/object-model/media
XMediaType: TypeAlias = Literal["photo", "video", "animated_gif"]
MediaType: TypeAlias = Literal["photo", "video", "animated_gif"]


class XMedia(BaseModel):
class Media(BaseModel):
media_key: str

type: XMediaType
type: MediaType
url: HttpUrl
width: NonNegativeInt
height: NonNegativeInt


MediaDetails: TypeAlias = List[XMedia]
MediaDetails: TypeAlias = List[Media]


class LinkId(UUID):
Expand Down
14 changes: 7 additions & 7 deletions common/birdxplorer_common/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
BinaryBool,
LanguageIdentifier,
LinkId,
Media,
MediaDetails,
MediaType,
NonNegativeInt,
NoteId,
NotesClassification,
Expand All @@ -25,8 +27,6 @@
UserEnrollment,
UserId,
UserName,
XMedia,
XMediaType,
)
from .models import Link as LinkModel
from .models import Note as NoteModel
Expand Down Expand Up @@ -120,18 +120,18 @@ class PostMediaAssociation(Base):
__tablename__ = "post_media"

post_id: Mapped[PostId] = mapped_column(ForeignKey("posts.post_id"), primary_key=True)
media_key: Mapped[str] = mapped_column(ForeignKey("x_medias.media_key"), primary_key=True)
media_key: Mapped[str] = mapped_column(ForeignKey("media.media_key"), primary_key=True)

# このテーブルにアクセスした時点でほぼ間違いなく MediaRecord も必要なので一気に引っ張る
media: Mapped["MediaRecord"] = relationship(back_populates="post_media_association", lazy="joined")


class MediaRecord(Base):
__tablename__ = "x_medias"
__tablename__ = "media"

media_key: Mapped[str] = mapped_column(primary_key=True)

type: Mapped[XMediaType] = mapped_column(nullable=False)
type: Mapped[MediaType] = mapped_column(nullable=False)
url: Mapped[HttpUrl] = mapped_column(nullable=False)
width: Mapped[NonNegativeInt] = mapped_column(nullable=False)
height: Mapped[NonNegativeInt] = mapped_column(nullable=False)
Expand Down Expand Up @@ -268,8 +268,8 @@ def engine(self) -> Engine:
return self._engine

@classmethod
def _media_record_to_model(cls, media_record: MediaRecord) -> XMedia:
return XMedia(
def _media_record_to_model(cls, media_record: MediaRecord) -> Media:
return Media(
media_key=media_record.media_key,
type=media_record.type,
url=media_record.url,
Expand Down

0 comments on commit 20dff3c

Please sign in to comment.