41 lines
876 B
Python
41 lines
876 B
Python
import json
|
|
|
|
from fastapi import APIRouter, Response, status
|
|
from pydantic import BaseModel
|
|
|
|
import backend.postgres as postgres
|
|
from api.middleware.verify_token import VerifyTokenRoute
|
|
|
|
users_routes = APIRouter()
|
|
|
|
|
|
class User(BaseModel):
|
|
username: str
|
|
password: str
|
|
|
|
|
|
@users_routes.post("/users")
|
|
def create_user(aux: User, response: Response):
|
|
postgres.add_user(aux.username, aux.password)
|
|
response.status_code = status.HTTP_201_CREATED
|
|
|
|
|
|
users_routes.route_class = VerifyTokenRoute
|
|
|
|
|
|
@users_routes.get("/users")
|
|
def get_users():
|
|
return postgres.get_users()
|
|
|
|
|
|
@users_routes.get("/users/{id}")
|
|
def get_by_id(id: str):
|
|
return postgres.get_user_by_id(id)
|
|
|
|
|
|
@users_routes.put("/users/{id}")
|
|
def edit_user(aux: User, id: str, response: Response):
|
|
postgres.edit_user(id, aux.username, aux.password)
|
|
response.status_code = status.HTTP_202_ACCEPTED
|
|
|