-
Notifications
You must be signed in to change notification settings - Fork 1
/
repo.py
30 lines (24 loc) · 871 Bytes
/
repo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import Type
from fastapi.params import Depends
from fastapi.requests import Request
from ...repos.base import BaseRepo
from ....middleware.database import DatabaseMiddleware, Database
from ....middleware.language import LanguageMiddleware
from ....middleware.session import SessionMiddleware, User
class Repo(Depends):
def __init__(self, repo: Type[BaseRepo]):
super(Repo, self).__init__(dependency=self.construct)
self.repo_class = repo
def construct(
self,
request: Request,
db: Database = Depends(DatabaseMiddleware.default),
user: User = Depends(SessionMiddleware.user),
lang: str = Depends(LanguageMiddleware.get),
):
return self.repo_class(
db=db,
user=user,
lang=lang,
**request.path_params,
)