Skip to content

Commit

Permalink
fix(common): File to be optional scalar, enable pagination & new fiel…
Browse files Browse the repository at this point in the history
…ds for MediaType, update model method name

Signed-off-by: Kwong Tung Nan <tungnan5636@gmail.com>
  • Loading branch information
kwongtn committed Jun 21, 2024
1 parent ab4fc5e commit bcccfc6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def url(self) -> str:
return f"https://cdn.discordapp.com/attachments/{self.discord_suffix}"

@property
def resizer_url(self) -> str:
def discord_resizer_url(self) -> str:
if self.file_id is None or self.file_name is None:
return None

Expand Down
10 changes: 6 additions & 4 deletions common/schema/scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class MediaScalar:
id: strawberry.ID
uploader: "UserScalar"
file: strawberry_django.DjangoImageType
file: Optional[strawberry_django.DjangoImageType]
width: int
height: int
url: Optional[str]
Expand All @@ -44,16 +44,18 @@ class MediasGroupByPeriodScalar:
medias: List["MediaScalar"]


@strawberry_django.type(models.Media, order=MediaOrder)
@strawberry_django.type(models.Media, order=MediaOrder, pagination=True)
class MediaType(strawberry.relay.Node):
id: strawberry.relay.NodeID[str]
created: datetime
uploader: "UserScalar"
file: strawberry_django.DjangoFileType
width: int
height: int
url: Optional[str]
discord_suffix: str

@strawberry_django.field
def created_date(self) -> str:
return self.created.date()


@strawberry_django.type(models.User)
Expand Down

0 comments on commit bcccfc6

Please sign in to comment.