generated from bomzheg/aiogram_template
-
Notifications
You must be signed in to change notification settings - Fork 11
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
ychebyshev
committed
Mar 14, 2024
1 parent
0d6e039
commit e264b6f
Showing
13 changed files
with
185 additions
and
38 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
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,13 @@ | ||
from fastapi import HTTPException | ||
from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR | ||
|
||
from shvatka.core.utils import exceptions | ||
|
||
|
||
def to_http_error( | ||
error: exceptions.SHError, | ||
code: int = HTTP_500_INTERNAL_SERVER_ERROR, | ||
) -> HTTPException: | ||
return HTTPException( | ||
status_code=code, detail={"text": error.notify_user, "description": error.text} | ||
) |
Empty file.
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,30 @@ | ||
from typing import BinaryIO | ||
|
||
from shvatka.core.interfaces.clients.file_storage import FileGateway | ||
from shvatka.core.interfaces.dal.complex import GameFileLoader | ||
from shvatka.core.models import dto | ||
from shvatka.core.services.scenario.files import check_file_meta_can_read | ||
from shvatka.core.utils import exceptions | ||
|
||
|
||
class FileReader: | ||
def __init__(self, dao: GameFileLoader, file_gateway: FileGateway): | ||
self.file_gateway = file_gateway | ||
self.dao = dao | ||
|
||
async def __call__(self, guid: str, game_id: int, user: dto.User) -> BinaryIO: | ||
author = await self.dao.get_by_user(user) | ||
game = await self.dao.get_full(game_id) | ||
if guid not in game.get_guids(): | ||
raise exceptions.FileNotFound( | ||
text=f"There is no file with uuid {guid} associated with game id {game_id}", | ||
game_id=game_id, | ||
game=game, | ||
user_id=user.db_id, | ||
user=user, | ||
player_id=author.id, | ||
player=author, | ||
) | ||
meta = await self.dao.get_by_guid(guid) | ||
check_file_meta_can_read(author, meta, game) | ||
return await self.file_gateway.get(meta) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from dishka import Provider, Scope, provide | ||
|
||
from shvatka.core.games.interactors import FileReader | ||
from shvatka.core.interfaces.dal.complex import GameFileLoader | ||
from shvatka.infrastructure.db.dao.complex.game import GameFilesGetterImpl | ||
from shvatka.infrastructure.db.dao.holder import HolderDao | ||
|
||
|
||
class DAOProvider(Provider): | ||
scope = Scope.REQUEST | ||
|
||
@provide | ||
def get_game_files(self, dao: HolderDao) -> GameFileLoader: | ||
return GameFilesGetterImpl(dao) | ||
|
||
|
||
class InteractorProvider(Provider): | ||
scope = Scope.REQUEST | ||
file_reader = provide(FileReader) |
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