File size: 489 Bytes
df50319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from fastapi import APIRouter
from app.schemas import TeamSchema
from app.models import Team
from sqlalchemy.orm import sessionmaker

router = APIRouter()

@router.post("/teams")
async def create_team(team: TeamSchema):
    new_team = Team(name=team.name)
    session.add(new_team)
    session.commit()
    return {"message": "Team created successfully"}

@router.get("/teams")
async def get_teams():
    teams = session.query(Team).all()
    return [{"name": team.name} for team in teams]