-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtraModels2.py
More file actions
35 lines (26 loc) · 1010 Bytes
/
ExtraModels2.py
File metadata and controls
35 lines (26 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
# 최대한 중복은 줄이기
class UserBase(BaseModel):
username: str
email: EmailStr
full_name: str | None = None
class UserIn(UserBase):
password: str
class UserOut(UserBase):
pass
class UserInDB(UserBase):
hashed_password: str
def fake_password_hasher(raw_password: str):
return "supersecret" + raw_password
# .dict(): Pydentic model의 데이터를 딕셔너리 타입으로 만들어 줌
def fake_save_user(user_in: UserIn):
hased_password= fake_password_hasher(user_in.password)
user_in_db = UserInDB(**user_in_dict(), hased_password=hased_password) # **: 함수를 호출할 때 키워드 인자를 딕셔너리로 전달하는데 사용
print("User saved! ..not really")
return user_in_db
@app.post("/user/", response_model=UserOut)
async def create_user(user_in: UserIn):
user_saved = fake_save_user(user_in)
return user_saved