File tree Expand file tree Collapse file tree 16 files changed +161
-156
lines changed Expand file tree Collapse file tree 16 files changed +161
-156
lines changed Original file line number Diff line number Diff line change 2
2
from starlette .middleware .authentication import AuthenticationMiddleware
3
3
4
4
from 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
6
6
from api .settings import Server
7
7
8
8
app = FastAPI (redoc_url = "/" , docs_url = "/swagger" )
13
13
on_error = on_auth_error ,
14
14
)
15
15
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):
17
17
user_id : Mapped [int ] = mapped_column (ForeignKey ("users.user_id" ))
18
18
issued_in_jam_id : Mapped [int ] = mapped_column (ForeignKey ("jams.jam_id" ))
19
19
infraction_type : Mapped [InfractionType ] = mapped_column (
20
- Enum (* InfractionType .__args__ , name = "infraction_type_enum " ),
20
+ Enum (* InfractionType .__args__ , name = "infraction_type " ),
21
21
nullable = False ,
22
22
)
23
23
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 1
1
from pydantic import BaseModel
2
2
3
- from api .models .schemas .old import infraction , team , winner
3
+ from api .models .schemas .v1 import infraction , team , winner
4
4
5
5
6
- class CodeJam (BaseModel ):
7
- """A model representing a codejam."""
6
+ class CodeJamBase (BaseModel ):
7
+ """A Base model representing a codejam."""
8
8
9
9
name : str
10
10
teams : list [team .Team ]
11
11
ongoing : bool = False
12
12
13
13
14
- class CodeJamResponse (CodeJam ):
14
+ class CodeJamCreate (CodeJamBase ):
15
+ """The expected fields to create a new Code Jam."""
16
+
17
+
18
+ class CodeJam (CodeJamBase ):
15
19
"""Response model representing a code jam."""
16
20
17
21
id : int
18
- teams : list [team .TeamResponse ]
19
- infractions : list [infraction .InfractionResponse ]
22
+ infractions : list [infraction .Infraction ]
20
23
winners : list [winner .Winner ]
21
24
22
25
class Config :
Original file line number Diff line number Diff line change 2
2
3
3
from pydantic import BaseModel
4
4
5
- from api .models .schemas .old import user
5
+ from api .models .schemas .v1 import user
6
6
7
7
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."""
10
10
11
11
name : str
12
12
users : list [user .User ]
13
13
discord_role_id : Optional [int ] = None
14
14
discord_channel_id : Optional [int ] = None
15
15
16
16
17
- class TeamResponse ( Team ):
17
+ class Team ( TeamBase ):
18
18
"""Response model representing a team."""
19
19
20
20
id : int
@@ -26,11 +26,11 @@ class Config:
26
26
orm_mode = True
27
27
28
28
29
- class UserTeamResponse (BaseModel ):
30
- """Response model representing user and team relationship."""
29
+ class UserTeam (BaseModel ):
30
+ """A model representing user and team relationship."""
31
31
32
32
user_id : int
33
- team : TeamResponse
33
+ team : Team
34
34
is_leader : bool
35
35
36
36
class Config :
Original file line number Diff line number Diff line change 1
1
from pydantic import BaseModel
2
2
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
16
4
17
5
18
6
class ParticipationHistory (BaseModel ):
@@ -23,18 +11,23 @@ class ParticipationHistory(BaseModel):
23
11
first_place : bool
24
12
team_id : int
25
13
is_leader : bool
26
- infractions : list [infraction .InfractionResponse ]
14
+ infractions : list [infraction .Infraction ]
27
15
28
16
class Config :
29
17
"""Sets ORM mode to true so that pydantic will validate the objects returned by SQLAlchemy."""
30
18
31
19
orm_mode = True
32
20
33
21
34
- class UserResponse (BaseModel ):
35
- """Response model representing a user."""
22
+ class UserBase (BaseModel ):
23
+ """A Base model representing core data about a user."""
36
24
37
25
id : int
26
+
27
+
28
+ class User (UserBase ):
29
+ """Response model representing everything about a user."""
30
+
38
31
participation_history : list [ParticipationHistory ]
39
32
40
33
class Config :
File renamed without changes.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments