feat: Update endpoint project
This commit is contained in:
parent
a91422cf81
commit
a62582fbfb
@ -0,0 +1,29 @@
|
|||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user