-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update old schemas and routes to use new ORM layout
- Loading branch information
1 parent
ab5f01e
commit 3b3a862
Showing
17 changed files
with
347 additions
and
143 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 was deleted.
Oops, something went wrong.
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,5 @@ | ||
def discord_ids_must_be_snowflake(field_to_check: int) -> int: | ||
"""Ensure the ids are valid Discord snowflakes.""" | ||
if field_to_check and field_to_check.bit_length() > 64: | ||
raise ValueError("Field must fit within a 64 bit int.") | ||
return field_to_check |
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,31 @@ | ||
from pydantic import BaseModel, validator | ||
|
||
from api.models.orm.infraction import InfractionType | ||
from api.models.schemas.utils import discord_ids_must_be_snowflake | ||
|
||
|
||
class InfractionBase(BaseModel): | ||
"""Base model for all infraction types.""" | ||
|
||
user_id: int | ||
jam_id: int | ||
reason: str | ||
infraction_type: InfractionType | ||
|
||
# validators | ||
_ensure_valid_discord_id = validator("user_id", allow_reuse=True)(discord_ids_must_be_snowflake) | ||
|
||
|
||
class InfractionCreate(InfractionBase): | ||
"""The expected fields to create a new infraction.""" | ||
|
||
|
||
class Infraction(InfractionBase): | ||
"""A model representing an infraction.""" | ||
|
||
id: int | ||
|
||
class Config: | ||
"""Sets ORM mode to true so that pydantic will validate the objects returned by SQLAlchemy.""" | ||
|
||
orm_mode = True |
15 changes: 9 additions & 6 deletions
15
api/models/schemas/old/jam.py → api/models/schemas/v1/jam.py
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
from fastapi import APIRouter | ||
|
||
from api.routers.v1 import codejams, infractions, teams, users, winners | ||
|
||
v1_routes_router = APIRouter() | ||
v1_routes_router.include_router(codejams.router) | ||
v1_routes_router.include_router(infractions.router) | ||
v1_routes_router.include_router(teams.router) | ||
v1_routes_router.include_router(users.router) | ||
v1_routes_router.include_router(winners.router) |
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
Oops, something went wrong.