Spaces:
Building
on
Zero
Building
on
Zero
File size: 624 Bytes
dfcff8f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.database import get_db
from app.schemas import TeamCreate, Team
from app.models import Team as TeamModel
router = APIRouter()
@router.post("/teams/")
def create_team(team: TeamCreate, db: Session = Depends()):
new_team = TeamModel(name=team.name)
db.add(new_team)
db.commit()
return {"message": "Team created successfully"}
@router.get("/teams/")
def read_teams(db: Session = Depends()):
teams = db.query(TeamModel).all()
return [{"id": team.id, "name": team.name, "created_at": team.created_at} for team in teams] |