-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
336a0d7
commit 3932f02
Showing
15 changed files
with
250 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from sqlalchemy.ext.asyncio import AsyncConnection | ||
|
||
from ...db.helpers.gacha import get_all_gacha_entities | ||
from ...schemas.common import Language | ||
from ...schemas.gameenums import COND_TYPE_NAME, GACHA_FLAG_NAME, PAY_TYPE_NAME | ||
from ...schemas.nice import GachaStoryAdjust, NiceGacha | ||
from ...schemas.raw import GachaEntity, MstGachaStoryAdjust | ||
from ..raw import get_gacha_entity | ||
from ..utils import get_flags, get_translation | ||
|
||
|
||
def get_nice_gacha_story_adjust(gacha_story: MstGachaStoryAdjust) -> GachaStoryAdjust: | ||
return GachaStoryAdjust( | ||
idx=gacha_story.idx, | ||
adjustId=gacha_story.adjustId, | ||
condType=COND_TYPE_NAME[gacha_story.condType], | ||
targetId=gacha_story.targetId, | ||
value=gacha_story.value, | ||
imageId=gacha_story.imageId, | ||
) | ||
|
||
|
||
def get_nice_gacha(gacha: GachaEntity, lang: Language = Language.jp) -> NiceGacha: | ||
return NiceGacha( | ||
id=gacha.mstGacha.id, | ||
name=get_translation(lang, gacha.mstGacha.name), | ||
imageId=gacha.mstGacha.imageId, | ||
type=PAY_TYPE_NAME[gacha.mstGacha.type], | ||
adjustId=gacha.mstGacha.adjustId, | ||
pickupId=gacha.mstGacha.pickupId, | ||
drawNum1=gacha.mstGacha.drawNum1, | ||
drawNum2=gacha.mstGacha.drawNum2, | ||
maxDrawNum=gacha.mstGacha.maxDrawNum, | ||
openedAt=gacha.mstGacha.openedAt, | ||
closedAt=gacha.mstGacha.closedAt, | ||
detailUrl=gacha.mstGacha.detailUrl, | ||
flags=get_flags(gacha.mstGacha.flag, GACHA_FLAG_NAME), | ||
storyAdjusts=[ | ||
get_nice_gacha_story_adjust(story) for story in gacha.mstGachaStoryAdjust | ||
], | ||
) | ||
|
||
|
||
async def get_nice_gacha_from_id( | ||
conn: AsyncConnection, gacha_id: int, lang: Language = Language.jp | ||
) -> NiceGacha: | ||
raw_gacha = await get_gacha_entity(conn, gacha_id) | ||
return get_nice_gacha(raw_gacha, lang) | ||
|
||
|
||
async def get_all_nice_gachas(conn: AsyncConnection) -> list[NiceGacha]: | ||
all_raw = await get_all_gacha_entities(conn) | ||
return [get_nice_gacha(gacha) for gacha in all_raw] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from sqlalchemy.ext.asyncio import AsyncConnection | ||
from sqlalchemy.sql import func, select | ||
|
||
from ...models.raw import mstGacha, mstGachaStoryAdjust | ||
from ...schemas.raw import GachaEntity | ||
from .utils import sql_jsonb_agg | ||
|
||
|
||
SELECT_GACHA_ENTITY = select( | ||
func.to_jsonb(mstGacha.table_valued()).label(mstGacha.name), | ||
sql_jsonb_agg(mstGachaStoryAdjust), | ||
).select_from( | ||
mstGacha.outerjoin( | ||
mstGachaStoryAdjust, mstGacha.c.id == mstGachaStoryAdjust.c.gachaId | ||
) | ||
) | ||
|
||
|
||
async def get_gacha_entity(conn: AsyncConnection, gacha_id: int) -> GachaEntity | None: | ||
stmt = SELECT_GACHA_ENTITY.where(mstGacha.c.id == gacha_id).group_by( | ||
mstGacha.table_valued() | ||
) | ||
res = (await conn.execute(stmt)).fetchone() | ||
|
||
if res is not None: | ||
return GachaEntity.from_orm(res) | ||
else: | ||
return None | ||
|
||
|
||
async def get_all_gacha_entities(conn: AsyncConnection) -> list[GachaEntity]: | ||
stmt = SELECT_GACHA_ENTITY.group_by(mstGacha.table_valued()) | ||
|
||
return [ | ||
GachaEntity.from_orm(gacha) for gacha in ((await conn.execute(stmt)).fetchall()) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters