mirror of
https://github.com/PaiGramTeam/GramCore.git
synced 2024-11-16 03:55:27 +00:00
✨ Support query players when only account_id
This commit is contained in:
parent
fdaeaa19e9
commit
fb76a75ee1
@ -62,8 +62,15 @@ class PlayersRepository(BaseService.Component):
|
|||||||
async with AsyncSession(self.engine) as session:
|
async with AsyncSession(self.engine) as session:
|
||||||
statement = select(Player).where(Player.user_id == user_id)
|
statement = select(Player).where(Player.user_id == user_id)
|
||||||
results = await session.exec(statement)
|
results = await session.exec(statement)
|
||||||
players = results.all()
|
return results.all()
|
||||||
return players
|
|
||||||
|
async def get_all_by_account_id(self, account_id: int, region: Optional[RegionEnum] = None) -> List[Player]:
|
||||||
|
async with AsyncSession(self.engine) as session:
|
||||||
|
statement = select(Player).where(Player.account_id == account_id)
|
||||||
|
if region is not None:
|
||||||
|
statement = statement.where(Player.region == region)
|
||||||
|
results = await session.exec(statement)
|
||||||
|
return results.all()
|
||||||
|
|
||||||
|
|
||||||
class PlayerInfoRepository(BaseService.Component):
|
class PlayerInfoRepository(BaseService.Component):
|
||||||
|
@ -45,5 +45,14 @@ class PlayersService(BaseService):
|
|||||||
for player in players:
|
for player in players:
|
||||||
await self._repository.delete(player)
|
await self._repository.delete(player)
|
||||||
|
|
||||||
|
async def get_all_by_account_id(self, account_id: int, region: Optional[RegionEnum] = None) -> List[Player]:
|
||||||
|
return await self._repository.get_all_by_account_id(account_id, region)
|
||||||
|
|
||||||
|
async def set_player_to_main(self, user_id: int, player_id: int) -> bool:
|
||||||
|
players = await self._repository.get_all_by_user_id(user_id)
|
||||||
|
for player in players:
|
||||||
|
player.is_chosen = player.player_id == player_id
|
||||||
|
await self._repository.update(player)
|
||||||
|
|
||||||
async def delete(self, player: Player):
|
async def delete(self, player: Player):
|
||||||
await self._repository.delete(player)
|
await self._repository.delete(player)
|
||||||
|
Loading…
Reference in New Issue
Block a user