Skip to content

Commit ab0e3d9

Browse files
authored
Merge pull request #52 from OpenBuilders/feat/sticker-character-logo
feat: Add logo_url to the StickerCharacter
2 parents 57c0a63 + 8a9c482 commit ab0e3d9

File tree

8 files changed

+70
-6
lines changed

8 files changed

+70
-6
lines changed

backend/api/pos/sticker.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
1+
from typing import Self
2+
13
from api.pos.base import BaseFDO
2-
from core.dtos.sticker import MinimalStickerCollectionWithCharactersDTO
4+
from core.dtos.sticker import (
5+
MinimalStickerCollectionWithCharactersDTO,
6+
MinimalStickerCharacterDTO,
7+
)
8+
9+
10+
class MinimalStickerCharacterFDO(BaseFDO, MinimalStickerCharacterDTO):
11+
@classmethod
12+
def from_dto(cls, dto: MinimalStickerCharacterDTO) -> Self:
13+
return cls(
14+
id=dto.id,
15+
name=dto.name,
16+
logo_url=dto.logo_url,
17+
)
318

419

520
class MinimalStickerCollectionWithCharactersFDO(
621
BaseFDO, MinimalStickerCollectionWithCharactersDTO
722
):
8-
...
23+
characters: list[MinimalStickerCharacterFDO]
24+
25+
@classmethod
26+
def from_dto(cls, dto: MinimalStickerCollectionWithCharactersDTO) -> Self:
27+
return cls(
28+
id=dto.id,
29+
title=dto.title,
30+
logo_url=dto.logo_url,
31+
characters=[MinimalStickerCharacterFDO.from_dto(c) for c in dto.characters],
32+
)

backend/api/routes/admin/resource.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ async def get_stickers_collections(
8989
collections = await action.get_all_grouped()
9090

9191
return [
92-
MinimalStickerCollectionWithCharactersFDO.model_validate(
93-
collection.model_dump()
94-
)
92+
MinimalStickerCollectionWithCharactersFDO.from_dto(collection)
9593
for collection in collections
9694
]
9795

backend/core/actions/sticker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def create(self, dto: StickerCharacterDTO) -> StickerCharacterDTO:
9393
name=dto.name,
9494
description=dto.description,
9595
supply=dto.supply,
96+
logo_url=dto.logo_url,
9697
)
9798
return StickerCharacterDTO.from_orm(sticker_character)
9899

backend/core/dtos/sticker.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ def from_orm(cls, obj: StickerCollection) -> Self:
2323
class MinimalStickerCharacterDTO(BaseModel):
2424
id: int
2525
name: str
26+
logo_url: str | None
2627

2728
@classmethod
2829
def from_orm(cls, obj: Any) -> Self:
2930
return cls(
3031
id=obj.id,
3132
name=obj.name,
33+
logo_url=obj.logo_url,
3234
)
3335

3436

@@ -50,7 +52,6 @@ def from_orm(cls, obj: StickerCollection) -> Self:
5052

5153
class StickerCollectionDTO(MinimalStickerCollectionDTO):
5254
description: str | None
53-
logo_url: str | None
5455

5556
@classmethod
5657
def from_orm(cls, obj: StickerCollection) -> Self:
@@ -75,6 +76,7 @@ def from_orm(cls, obj: Any) -> Self:
7576
collection_id=obj.collection_id,
7677
description=obj.description,
7778
supply=obj.supply,
79+
logo_url=obj.logo_url,
7880
)
7981

8082

@@ -151,6 +153,7 @@ def from_json(cls, collection_json: dict[str, Any]) -> Self:
151153
collection_id=collection_json["id"],
152154
description=character["description"],
153155
supply=character["supply"],
156+
logo_url=character.get("logo_url"),
154157
)
155158
for character in collection_json["characters"]
156159
],
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""sticker character logo
2+
3+
Revision ID: 02d2e4791b2c
4+
Revises: ae8e0ea77cf0
5+
Create Date: 2025-04-29 10:54:21.198049
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = "02d2e4791b2c"
16+
down_revision: Union[str, None] = "ae8e0ea77cf0"
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
op.add_column(
23+
"sticker_character", sa.Column("logo_url", sa.String(length=255), nullable=True)
24+
)
25+
26+
27+
def downgrade() -> None:
28+
op.drop_column("sticker_character", "logo_url")

backend/core/models/sticker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class StickerCharacter(Base):
2525
name = mapped_column(String(255), nullable=False)
2626
description = mapped_column(String(255), nullable=True)
2727
supply = mapped_column(Integer, nullable=False)
28+
logo_url = mapped_column(String(255), nullable=True)
2829

2930
collection = relationship(
3031
"StickerCollection",

backend/core/services/sticker/character.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ def create(
2424
name: str,
2525
description: str,
2626
supply: int,
27+
logo_url: str | None,
2728
) -> StickerCharacter:
2829
new_character = StickerCharacter(
2930
external_id=character_id,
3031
collection_id=collection_id,
3132
name=name,
3233
description=description,
3334
supply=supply,
35+
logo_url=logo_url,
3436
)
3537
self.db_session.add(new_character)
3638
self.db_session.commit()
@@ -42,12 +44,14 @@ def is_update_required(
4244
name: str,
4345
description: str,
4446
supply: int,
47+
logo_url: str | None,
4548
) -> bool:
4649
return any(
4750
[
4851
character.name != name,
4952
character.description != description,
5053
character.supply != supply,
54+
character.logo_url != logo_url,
5155
]
5256
)
5357

@@ -57,9 +61,11 @@ def update(
5761
name: str,
5862
description: str,
5963
supply: int,
64+
logo_url: str | None,
6065
) -> StickerCharacter:
6166
character.name = name
6267
character.description = description
6368
character.supply = supply
69+
character.logo_url = logo_url
6470
self.db_session.commit()
6571
return character

backend/indexer/actions/sticker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,15 @@ async def refresh_collections(self) -> None:
159159
name=character.name,
160160
description=character.description,
161161
supply=character.supply,
162+
logo_url=character.logo_url,
162163
)
163164
else:
164165
if self.sticker_character_service.is_update_required(
165166
character=current_character,
166167
name=character.name,
167168
description=character.description,
168169
supply=character.supply,
170+
logo_url=character.logo_url,
169171
):
170172
logger.info(
171173
f"Character {character.id=} for collection {collection.id=} has changed. Updating..."
@@ -175,6 +177,7 @@ async def refresh_collections(self) -> None:
175177
name=character.name,
176178
description=character.description,
177179
supply=character.supply,
180+
logo_url=character.logo_url,
178181
)
179182

180183
# Set cache only on successful processing

0 commit comments

Comments
 (0)