Add database abstraction

This commit is contained in:
François Voron
2019-10-06 08:53:13 +02:00
parent 4e0b0f6f7d
commit 552f313d76
7 changed files with 67 additions and 10 deletions

View File

@ -1,12 +1,20 @@
from fastapi import APIRouter
from .db import UserDBInterface
from .models import UserCreate, UserDB
from .password import get_password_hash
router = APIRouter()
class UserRouter:
@router.post('/register')
async def register(user: UserCreate):
hashed_password = get_password_hash(user.password)
return UserDB(**user.dict(), hashed_password=hashed_password)
def __new__(cls, userDB: UserDBInterface) -> APIRouter:
router = APIRouter()
@router.post('/register')
async def register(user: UserCreate):
hashed_password = get_password_hash(user.password)
db_user = UserDB(**user.dict(), hashed_password=hashed_password)
created_user = await userDB.create(db_user)
return created_user
return router