This commit is contained in:
2024-06-11 22:56:59 +09:00
parent f430332492
commit da6d957669
8 changed files with 168 additions and 3 deletions

27
backend_fastapi/auth.py Normal file
View File

@ -0,0 +1,27 @@
from fastapi import APIRouter
import backend_fastapi.schemas as schemas
from backend_fastapi.repositories import add_role, add_user, get_role_all, update_role, delete_role
from typing import List
router = APIRouter()
@router.post("/role")
async def create_role(role: schemas.RoleCreate) -> schemas.Role:
return await add_role(role)
@router.get("/role")
async def get_role() -> List[schemas.Role]:
return await get_role_all()
@router.patch("/role")
async def change_role(role: schemas.Role, id: int) -> None:
return await update_role(role, id)
@router.delete("/role")
async def remove_role(id: int) -> schemas.Role:
return await delete_role(id)
@router.post("/user")
async def create_user(user: schemas.UserCreate) -> schemas.User:
import hashlib
user.hashed_password = hashlib.sha256(user.hashed_password.encode('utf-8')).hexdigest()
return await add_user(user)