File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change 77from db import get_db , init_models
88from fastapi import Depends , FastAPI
99from models import User
10+ from schema import UserResponseModel
1011from sqlalchemy import select
1112from sqlalchemy .ext .asyncio import AsyncSession
1213
@@ -27,7 +28,7 @@ async def root() -> dict[str, str]:
2728 return {"message" : "Test API for FastAPI and Async SQLAlchemy ." }
2829
2930
30- @app .post ("/users/" )
31+ @app .post ("/users/" , response_model = UserResponseModel )
3132async def create_user (
3233 name : str , email : str , session : AsyncSession = Depends (get_db )
3334) -> User :
@@ -37,7 +38,7 @@ async def create_user(
3738 return user
3839
3940
40- @app .get ("/users/" )
41+ @app .get ("/users/" , response_model = Sequence [ UserResponseModel ] )
4142async def get_users (session : AsyncSession = Depends (get_db )) -> Sequence [User ]:
4243 """Get all users."""
4344 result = await session .execute (select (User ))
Original file line number Diff line number Diff line change 1+ """Set up some schemas for the database."""
2+ from pydantic import BaseModel
3+
4+
5+ class UserResponseModel (BaseModel ):
6+ """Response model for the User model."""
7+
8+ # id: int
9+ name : str
10+ email : str
You can’t perform that action at this time.
0 commit comments