mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
🎉 first commit
This commit is contained in:
parent
8c00f9a074
commit
91f4291d9b
21 changed files with 614 additions and 3 deletions
51
src/routers/users.py
Normal file
51
src/routers/users.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
from fastapi import Depends, FastAPI, APIRouter
|
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||
from pydantic import BaseModel
|
||||
from ..services.auth import *
|
||||
from ..services.users import *
|
||||
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/auth/token")
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/me")
|
||||
async def api_get_current_user(current_user: User = Depends(get_current_user)):
|
||||
"""
|
||||
Get current user
|
||||
"""
|
||||
return current_user.dict()
|
||||
|
||||
|
||||
@router.get("/username/{username}")
|
||||
async def api_get_user_by_username(username: str):
|
||||
"""
|
||||
Get single user by username
|
||||
"""
|
||||
return await get_user(username)
|
||||
|
||||
|
||||
@router.post("/")
|
||||
async def api_create_user(user_object: UserInDB):
|
||||
"""
|
||||
Create new user
|
||||
"""
|
||||
return await create_user(user_object)
|
||||
|
||||
|
||||
@router.delete("/username/{username}")
|
||||
async def api_delete_user(username: str):
|
||||
"""
|
||||
Delete user by ID
|
||||
"""
|
||||
|
||||
return await delete_user(username)
|
||||
|
||||
|
||||
@router.put("/username/{username}")
|
||||
async def api_update_user(user_object: UserInDB):
|
||||
"""
|
||||
Update user by ID
|
||||
"""
|
||||
return await update_user(user_object)
|
||||
Loading…
Add table
Add a link
Reference in a new issue