Spaces:
Sleeping
Sleeping
from fastapi import APIRouter, HTTPException | |
from app.schemas import UserSchema | |
from app.models import User | |
from sqlalchemy.orm import sessionmaker | |
router = APIRouter() | |
async def create_user(username: str, password: str): | |
user = User(username=username, password=password) | |
session = sessionmaker(bind=engine)() | |
session.add(user) | |
session.commit() | |
return {"message": "User created successfully"} | |
async def read_users(): | |
session = sessionmaker(bind=engine)() | |
users = session.query(User).all() | |
return [UserSchema.from_orm(user) for user in users] |