feat: add chat_id to project response
Some checks failed
Deploy Tracker / deploy (push) Failing after 0s
Some checks failed
Deploy Tracker / deploy (push) Failing after 0s
This commit is contained in:
parent
e65d66125e
commit
999b049a9d
@ -33,12 +33,18 @@ class ProjectOut(BaseModel):
|
|||||||
repo_urls: list[str] = []
|
repo_urls: list[str] = []
|
||||||
status: str
|
status: str
|
||||||
task_counter: int
|
task_counter: int
|
||||||
|
chat_id: str | None = None
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
from_attributes = True
|
from_attributes = True
|
||||||
|
|
||||||
|
|
||||||
def _project_out(p: Project) -> dict:
|
async def _project_out(p: Project, db: AsyncSession) -> dict:
|
||||||
|
# Get project chat
|
||||||
|
chat_result = await db.execute(
|
||||||
|
select(Chat).where(Chat.project_id == p.id, Chat.kind == "project")
|
||||||
|
)
|
||||||
|
chat = chat_result.scalar_one_or_none()
|
||||||
return {
|
return {
|
||||||
"id": str(p.id),
|
"id": str(p.id),
|
||||||
"name": p.name,
|
"name": p.name,
|
||||||
@ -47,13 +53,14 @@ def _project_out(p: Project) -> dict:
|
|||||||
"repo_urls": p.repo_urls or [],
|
"repo_urls": p.repo_urls or [],
|
||||||
"status": p.status,
|
"status": p.status,
|
||||||
"task_counter": p.task_counter,
|
"task_counter": p.task_counter,
|
||||||
|
"chat_id": str(chat.id) if chat else None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/projects", response_model=list[ProjectOut])
|
@router.get("/projects", response_model=list[ProjectOut])
|
||||||
async def list_projects(db: AsyncSession = Depends(get_db)):
|
async def list_projects(db: AsyncSession = Depends(get_db)):
|
||||||
result = await db.execute(select(Project).where(Project.status == "active"))
|
result = await db.execute(select(Project).where(Project.status == "active"))
|
||||||
return [_project_out(p) for p in result.scalars()]
|
return [await _project_out(p, db) for p in result.scalars()]
|
||||||
|
|
||||||
|
|
||||||
@router.get("/projects/{slug}", response_model=ProjectOut)
|
@router.get("/projects/{slug}", response_model=ProjectOut)
|
||||||
@ -62,7 +69,7 @@ async def get_project(slug: str, db: AsyncSession = Depends(get_db)):
|
|||||||
project = result.scalar_one_or_none()
|
project = result.scalar_one_or_none()
|
||||||
if not project:
|
if not project:
|
||||||
raise HTTPException(404, "Project not found")
|
raise HTTPException(404, "Project not found")
|
||||||
return _project_out(project)
|
return await _project_out(project, db)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/projects", response_model=ProjectOut)
|
@router.post("/projects", response_model=ProjectOut)
|
||||||
@ -85,7 +92,7 @@ async def create_project(req: ProjectCreate, db: AsyncSession = Depends(get_db))
|
|||||||
db.add(chat)
|
db.add(chat)
|
||||||
|
|
||||||
await db.commit()
|
await db.commit()
|
||||||
return _project_out(project)
|
return await _project_out(project, db)
|
||||||
|
|
||||||
|
|
||||||
@router.patch("/projects/{slug}", response_model=ProjectOut)
|
@router.patch("/projects/{slug}", response_model=ProjectOut)
|
||||||
@ -105,7 +112,7 @@ async def update_project(slug: str, req: ProjectUpdate, db: AsyncSession = Depen
|
|||||||
project.status = req.status
|
project.status = req.status
|
||||||
|
|
||||||
await db.commit()
|
await db.commit()
|
||||||
return _project_out(project)
|
return await _project_out(project, db)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/projects/{slug}")
|
@router.delete("/projects/{slug}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user