🚨 Python Black commit

This commit is contained in:
Brian Wiborg 2025-09-28 19:40:54 +02:00
parent ff8384d2c5
commit b07df29c9c
No known key found for this signature in database
3 changed files with 30 additions and 29 deletions

View file

@ -64,9 +64,7 @@ class TokenType(str, Enum):
refresh = "refresh"
def claims(
token_type: TokenType, user: User, groups: List[Group] = []
) -> Claims:
def claims(token_type: TokenType, user: User, groups: List[Group] = []) -> Claims:
return Claims(
type=token_type,
sub=str(user.id),
@ -83,7 +81,7 @@ def claims(
def create_token(claims: Claims, expires_in: int) -> str:
to_encode = claims.model_dump()
to_encode['exp'] = int(time.time()) + expires_in
to_encode["exp"] = int(time.time()) + expires_in
token = jwt.encode(to_encode, JWT_SECRET, algorithm=JWT_ALGORITHM)
if isinstance(token, bytes):
token = token.decode("utf-8")

View file

@ -10,9 +10,9 @@ class Team(Model):
id: UUID = field.data.UUIDField(primary_key=True)
name: str = field.TextField()
members: field.ManyToManyRelation[User] = field.ManyToManyField(
'ohmyapi_auth.User',
"ohmyapi_auth.User",
related_name="tournament_teams",
through='user_tournament_teams',
through="user_tournament_teams",
)
def __str__(self):
@ -32,19 +32,19 @@ class Event(Model):
id: UUID = field.data.UUIDField(primary_key=True)
name: str = field.TextField()
tournament: field.ForeignKeyRelation[Tournament] = field.ForeignKeyField(
'ohmyapi_demo.Tournament',
related_name='events',
"ohmyapi_demo.Tournament",
related_name="events",
)
participants: field.ManyToManyRelation[Team] = field.ManyToManyField(
'ohmyapi_demo.Team',
related_name='events',
through='event_team',
"ohmyapi_demo.Team",
related_name="events",
through="event_team",
)
modified: datetime = field.DatetimeField(auto_now=True)
prize: Decimal = field.DecimalField(max_digits=10, decimal_places=2, null=True)
class Schema:
exclude = ['tournament_id']
exclude = ["tournament_id"]
def __str__(self):
return self.name

View file

@ -11,37 +11,41 @@ from typing import List
router = APIRouter(prefix="/tournemant")
@router.get("/",
tags=["tournament"],
response_model=List[models.Tournament.Schema.model])
@router.get(
"/", tags=["tournament"], response_model=List[models.Tournament.Schema.model]
)
async def list():
"""List all tournaments."""
return await models.Tournament.Schema.model.from_queryset(Tournament.all())
@router.post("/",
tags=["tournament"],
status_code=HTTPStatus.CREATED)
@router.post("/", tags=["tournament"], status_code=HTTPStatus.CREATED)
async def post(tournament: models.Tournament.Schema.readonly):
"""Create tournament."""
return await models.Tournament.Schema.model.from_queryset(models.Tournament.create(**tournament.model_dump()))
return await models.Tournament.Schema.model.from_queryset(
models.Tournament.create(**tournament.model_dump())
)
@router.get("/{id}",
tags=["tournament"],
response_model=models.Tournament.Schema.model)
@router.get("/{id}", tags=["tournament"], response_model=models.Tournament.Schema.model)
async def get(id: str):
"""Get tournament by id."""
return await models.Tournament.Schema.model.from_queryset(models.Tournament.get(id=id))
return await models.Tournament.Schema.model.from_queryset(
models.Tournament.get(id=id)
)
@router.put("/{id}",
@router.put(
"/{id}",
tags=["tournament"],
response_model=models.Tournament.Schema.model,
status_code=HTTPStatus.ACCEPTED)
status_code=HTTPStatus.ACCEPTED,
)
async def put(tournament: models.Tournament.Schema.model):
"""Update tournament."""
return await models.Tournament.Schema.model.from_queryset(models.Tournament.update(**tournament.model_dump()))
return await models.Tournament.Schema.model.from_queryset(
models.Tournament.update(**tournament.model_dump())
)
@router.delete("/{id}", tags=["tournament"])
@ -51,4 +55,3 @@ async def delete(id: str):
return await tournament.delete()
except DoesNotExist:
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="not found")