File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22from starlette .middleware .authentication import AuthenticationMiddleware
33
44from api .middleware import TokenAuthentication , on_auth_error
5- from api .routers .old import old_routes_router
5+ from api .routers .v1 import v1_routes_router
66from api .settings import Server
77
88app = FastAPI (redoc_url = "/" , docs_url = "/swagger" )
1313 on_error = on_auth_error ,
1414)
1515
16- app .include_router (old_routes_router )
16+ app .include_router (v1_routes_router )
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ class Infraction(Base):
1717 user_id : Mapped [int ] = mapped_column (ForeignKey ("users.user_id" ))
1818 issued_in_jam_id : Mapped [int ] = mapped_column (ForeignKey ("jams.jam_id" ))
1919 infraction_type : Mapped [InfractionType ] = mapped_column (
20- Enum (* InfractionType .__args__ , name = "infraction_type_enum " ),
20+ Enum (* InfractionType .__args__ , name = "infraction_type " ),
2121 nullable = False ,
2222 )
2323 reason : Mapped [str ] = mapped_column (String (), nullable = False )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ def discord_ids_must_be_snowflake (field_to_check : int ) -> int :
2+ """Ensure the ids are valid Discord snowflakes."""
3+ if field_to_check and field_to_check .bit_length () > 64 :
4+ raise ValueError ("Field must fit within a 64 bit int." )
5+ return field_to_check
Original file line number Diff line number Diff line change 1+ from pydantic import BaseModel , validator
2+
3+ from api .models .orm .infraction import InfractionType
4+ from api .models .schemas .utils import discord_ids_must_be_snowflake
5+
6+
7+ class InfractionBase (BaseModel ):
8+ """Base model for all infraction types."""
9+
10+ user_id : int
11+ jam_id : int
12+ reason : str
13+ infraction_type : InfractionType
14+
15+ # validators
16+ _ensure_valid_discord_id = validator ("user_id" , allow_reuse = True )(discord_ids_must_be_snowflake )
17+
18+
19+ class InfractionCreate (InfractionBase ):
20+ """The expected fields to create a new infraction."""
21+
22+
23+ class Infraction (InfractionBase ):
24+ """A model representing an infraction."""
25+
26+ id : int
27+
28+ class Config :
29+ """Sets ORM mode to true so that pydantic will validate the objects returned by SQLAlchemy."""
30+
31+ orm_mode = True
Original file line number Diff line number Diff line change 11from pydantic import BaseModel
22
3- from api .models .schemas .old import infraction , team , winner
3+ from api .models .schemas .v1 import infraction , team , winner
44
55
6- class CodeJam (BaseModel ):
7- """A model representing a codejam."""
6+ class CodeJamBase (BaseModel ):
7+ """A Base model representing a codejam."""
88
99 name : str
1010 teams : list [team .Team ]
1111 ongoing : bool = False
1212
1313
14- class CodeJamResponse (CodeJam ):
14+ class CodeJamCreate (CodeJamBase ):
15+ """The expected fields to create a new Code Jam."""
16+
17+
18+ class CodeJam (CodeJamBase ):
1519 """Response model representing a code jam."""
1620
1721 id : int
18- teams : list [team .TeamResponse ]
19- infractions : list [infraction .InfractionResponse ]
22+ infractions : list [infraction .Infraction ]
2023 winners : list [winner .Winner ]
2124
2225 class Config :
Original file line number Diff line number Diff line change 22
33from pydantic import BaseModel
44
5- from api .models .schemas .old import user
5+ from api .models .schemas .v1 import user
66
77
8- class Team (BaseModel ):
9- """A model representing a team for a codejam."""
8+ class TeamBase (BaseModel ):
9+ """A Base model representing a team for a codejam."""
1010
1111 name : str
1212 users : list [user .User ]
1313 discord_role_id : Optional [int ] = None
1414 discord_channel_id : Optional [int ] = None
1515
1616
17- class TeamResponse ( Team ):
17+ class Team ( TeamBase ):
1818 """Response model representing a team."""
1919
2020 id : int
@@ -26,11 +26,11 @@ class Config:
2626 orm_mode = True
2727
2828
29- class UserTeamResponse (BaseModel ):
30- """Response model representing user and team relationship."""
29+ class UserTeam (BaseModel ):
30+ """A model representing user and team relationship."""
3131
3232 user_id : int
33- team : TeamResponse
33+ team : Team
3434 is_leader : bool
3535
3636 class Config :
Original file line number Diff line number Diff line change 11from pydantic import BaseModel
22
3- from api .models .schemas .old import infraction
4-
5-
6- class User (BaseModel ):
7- """A model representing a user for a codejam."""
8-
9- user_id : int
10- is_leader : bool
11-
12- class Config :
13- """Sets ORM mode to true so that pydantic will validate the objects returned by SQLAlchemy."""
14-
15- orm_mode = True
3+ from api .models .schemas .v1 import infraction
164
175
186class ParticipationHistory (BaseModel ):
@@ -23,18 +11,23 @@ class ParticipationHistory(BaseModel):
2311 first_place : bool
2412 team_id : int
2513 is_leader : bool
26- infractions : list [infraction .InfractionResponse ]
14+ infractions : list [infraction .Infraction ]
2715
2816 class Config :
2917 """Sets ORM mode to true so that pydantic will validate the objects returned by SQLAlchemy."""
3018
3119 orm_mode = True
3220
3321
34- class UserResponse (BaseModel ):
35- """Response model representing a user."""
22+ class UserBase (BaseModel ):
23+ """A Base model representing core data about a user."""
3624
3725 id : int
26+
27+
28+ class User (UserBase ):
29+ """Response model representing everything about a user."""
30+
3831 participation_history : list [ParticipationHistory ]
3932
4033 class Config :
File renamed without changes.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments