Spaces:
Sleeping
Sleeping
Caner Giden commited on
Update workflows.py
Browse files10 unmodified lines1112131415162 unmodified lines192021222324252627284 unmodified lines3334353637383940414243444546473 unmodified lines51525354555657585960616 unmodified lines6869707172737475767711 unmodified lines899091929394959697989910 unmodified linesWorkflowRead,WorkflowUpdate,)router = APIRouter(prefix="/workflows",2 unmodified lines@router.get("/", response_model=List[WorkflowRead])def list_workflows(db: Session = Depends(get_db)) -> List[WorkflowRead]:"""Tüm workflow kayıtlarını listele."""workflows: List[models.Workflow] = (db.query(models.Workflow).order_by(models.Workflow.created_at.desc()).all())4 unmodified lines"/", response_model=WorkflowRead, status_code=status.HTTP_201_CREATED)def create_workflow(payload: WorkflowCreate, db: Session = Depends(get_db)) -> WorkflowRead:"""Yeni bir workflow yarat."""wf = models.Workflow(name=payload.name,description=payload.description,graph_json=payload.graph_json,is_active=payload.is_active,owner_id=payload.owner_id,)db.add(wf)db.commit()3 unmodified lines@router.get("/{workflow_id}", response_model=WorkflowRead)def get_workflow(workflow_id: int, db: Session = Depends(get_db)) -> WorkflowRead:"""Tek bir workflow getir."""wf = db.query(models.Workflow).filter_by(id=workflow_id).first()if not wf:raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,detail="Workflow not found",6 unmodified linesworkflow_id: int,payload: WorkflowUpdate,db: Session = Depends(get_db),) -> WorkflowRead:"""Workflow güncelle."""wf = db.query(models.Workflow).filter_by(id=workflow_id).first()if not wf:raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,detail="Workflow not found",11 unmodified lines@router.delete("/{workflow_id}", status_code=status.HTTP_204_NO_CONTENT)def delete_workflow(workflow_id: int, db: Session = Depends(get_db)) -> None:"""Workflow sil."""wf = db.query(models.Workflow).filter_by(id=workflow_id).first()if not wf:raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,detail="Workflow not found",10 unmodified lines11121314151617182 unmodified lines212223242526272829303132333435364 unmodified lines41424344454647484950515253545556575859603 unmodified lines646566676869707172737475767778796 unmodified lines868788899091929394959697989911 unmodified lines11111211311411511611711811912012112212312412512610 unmodified linesWorkflowRead,WorkflowUpdate,)from app.security import get_current_user # 👈 Auth dependencyrouter = APIRouter(prefix="/workflows",2 unmodified lines@router.get("/", response_model=List[WorkflowRead])def list_workflows(db: Session = Depends(get_db),current_user: models.User = Depends(get_current_user),) -> List[WorkflowRead]:"""Giriş yapmış kullanıcının tüm workflow kayıtlarını listele."""workflows: List[models.Workflow] = (db.query(models.Workflow).filter_by(owner_id=current_user.id).order_by(models.Workflow.created_at.desc()).all())4 unmodified lines"/", response_model=WorkflowRead, status_code=status.HTTP_201_CREATED)def create_workflow(payload: WorkflowCreate,db: Session = Depends(get_db),current_user: models.User = Depends(get_current_user),) -> WorkflowRead:"""Giriş yapmış kullanıcı için yeni bir workflow yarat.owner_id dışarıdan gelmez, current_user'dan alınır."""wf = models.Workflow(name=payload.name,description=payload.description,graph_json=payload.graph_json,is_active=payload.is_active,owner_id=current_user.id, # 👈 kritik nokta)db.add(wf)db.commit()3 unmodified lines@router.get("/{workflow_id}", response_model=WorkflowRead)def get_workflow(workflow_id: int,db: Session = Depends(get_db),current_user: models.User = Depends(get_current_user),) -> WorkflowRead:"""Tek bir workflow getir.Sadece sahibiyse görebilir."""wf = db.query(models.Workflow).filter_by(id=workflow_id).first()if not wf or wf.owner_id != current_user.id:raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,detail="Workflow not found",6 unmodified linesworkflow_id: int,payload: WorkflowUpdate,db: Session = Depends(get_db),current_user: models.User = Depends(get_current_user),) -> WorkflowRead:"""Workflow güncelle.Kullanıcı sadece kendi workflow'unu güncelleyebilir."""wf = db.query(models.Workflow).filter_by(id=workflow_id).first()if not wf or wf.owner_id != current_user.id:raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,detail="Workflow not found",11 unmodified lines@router.delete("/{workflow_id}", status_code=status.HTTP_204_NO_CONTENT)def delete_workflow(workflow_id: int,db: Session = Depends(get_db),current_user: models.User = Depends(get_current_user),) -> None:"""Workflow sil.Kullanıcı sadece kendi workflow'unu silebilir."""wf = db.query(models.Workflow).filter_by(id=workflow_id).first()if not wf or wf.owner_id != current_user.id:raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,detail="Workflow not found",
app/routers/workflows.py+40-13