File tree 2 files changed +5
-11
lines changed
building-with-fast-api/chapter_05
2 files changed +5
-11
lines changed Original file line number Diff line number Diff line change 5
5
# ------------------------------------------------------------------------------
6
6
# Our USER model
7
7
# ==============================================================================
8
- # Here we'll set our user model, which has a `User.Events` column, to list all
8
+ # ~~ Here we'll set our user model, which has a `User.Events` column, to list all
9
9
# the events attached to that specific user. We have a couple of types, depending
10
- # on the situation (for example, sign-in form). We could also create a separate
10
+ # on the situation (for example, sign-in form).~~ We could also create a separate
11
11
# `User` model for the `response_model=` in our routes, to hide the `password`.
12
12
#
13
13
# Questions
19
19
class User (BaseModel ):
20
20
email : EmailStr # A custom type for emails
21
21
password : str
22
- events : Optional [List [Event ]] # Empty by default, currently not used
23
-
24
- # For `sign-up` and `sign-in`
25
- class UserSign (BaseModel ):
26
- email : EmailStr
27
- password : str
Original file line number Diff line number Diff line change 1
1
from fastapi import APIRouter , HTTPException , status
2
- from models .users import User , UserSign
2
+ from models .users import User
3
3
4
4
# ------------------------------------------------------------------------------
5
5
# Our USERS routes
27
27
# for both, rather than creating separate models for `sign-up` and `sign-in`.
28
28
29
29
@user_router .post ("/signup" )
30
- async def sign_new_user (data : UserSign ) -> dict :
30
+ async def sign_new_user (data : User ) -> dict :
31
31
if data .email in users :
32
32
raise HTTPException (status_code = 409 , detail = "Username already exists" )
33
33
34
34
users [data .email ] = data # != Ask copilot to explain this line
35
35
return { "message" : "User registered!" }
36
36
37
37
@user_router .post ("/signin" )
38
- async def sign_in_user (user : UserSign ) -> dict :
38
+ async def sign_in_user (user : User ) -> dict :
39
39
# Check if `UserSign().email` is in the `users` dictionary
40
40
# You could also use `if _ or _` here!
41
41
if user .email not in users :
You can’t perform that action at this time.
0 commit comments