🚚 Re-sort tutorial example files

This commit is contained in:
Sebastián Ramírez committed 2018-12-13 21:25:45 +04:00
1 parent 8eaae72b76
commit a47243d915
71 files changed
+656 -656

No files matched your search

+10 -34
View File
@@ -1,43 +1,19 @@
from fastapi import Body, FastAPI, Path, Query
from pydantic import BaseModel
from pydantic.types import EmailStr
from pydantic.types import UrlStr
from typing import Set, List
from uuid import UUID, uuid4
app = FastAPI()
class UserIn(BaseModel):
username: str
password: str
email: EmailStr
full_name: str = None
class Item(BaseModel):
name: str
description: str = None
price: float
tax: float = None
tags: Set[str] = []
class UserOut(BaseModel):
username: str
email: EmailStr
full_name: str = None
class UserInDB(BaseModel):
username: str
hashed_password: str
email: EmailStr
full_name: str = None
def fake_password_hasher(raw_password: str):
return "supersecret" + raw_password
def fake_save_user(user_in: UserIn):
hashed_password = fake_password_hasher(user_in.password)
user_in_db = UserInDB(**user_in.dict(), hashed_password=hashed_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
@app.post("/items/", response_model=Item)
async def create_item(*, item: Item):
return item