29 lines
622 B
Python
29 lines
622 B
Python
from typing import Optional
|
|
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel
|
|
|
|
router = APIRouter()
|
|
|
|
class ProjectBase(BaseModel):
|
|
name: str
|
|
description: Optional[str] = None
|
|
|
|
class ProjectCreate(ProjectBase):
|
|
pass
|
|
|
|
class Project(ProjectBase):
|
|
id: int
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
@router.post("/project", response_model=Project)
|
|
async def create_project(project: ProjectCreate, db=Depends(get_db)):
|
|
"""
|
|
Create a new project
|
|
"""
|
|
db_project = Project(**project.dict())
|
|
db.add(db_project)
|
|
db.commit()
|
|
db.refresh(db_project)
|
|
return db_project |