mirror of
https://github.com/a-mayb3/Kanban_clone_backend.git
synced 2026-03-21 10:05:38 +01:00
Fixed project creation endpoint
This commit is contained in:
parent
7b011fd887
commit
a40296929a
2 changed files with 8 additions and 13 deletions
|
|
@ -100,16 +100,15 @@ def create_project(project: ProjectCreate, request:Request, db: db_dependency):
|
||||||
|
|
||||||
user = get_user_from_jwt(request, db)
|
user = get_user_from_jwt(request, db)
|
||||||
|
|
||||||
db_project = ProjectCreate(
|
db_project = Project(
|
||||||
name=project.name,
|
name=project.name,
|
||||||
description=project.description,
|
description=project.description,
|
||||||
tasks=[],
|
tasks=[]
|
||||||
user_ids=[getattr(user, "id")]
|
|
||||||
)
|
)
|
||||||
db.add(db_project)
|
|
||||||
db.commit()
|
|
||||||
db.refresh(db_project)
|
|
||||||
|
|
||||||
|
db_project.users.append(user)
|
||||||
|
|
||||||
|
db.add(db_project)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(db_project)
|
db.refresh(db_project)
|
||||||
|
|
||||||
|
|
@ -207,16 +206,11 @@ def delete_project(project_id: int, db: db_dependency, request: Request):
|
||||||
db_project = get_project_by_id_for_user(user, project_id, db)
|
db_project = get_project_by_id_for_user(user, project_id, db)
|
||||||
|
|
||||||
## Remove dangling tasks and user associations
|
## Remove dangling tasks and user associations
|
||||||
tasks: List[TaskBase] = db.query(TaskBase).filter(getattr(TaskBase, "project_id") == project_id).all()
|
tasks: List[Task] = db.query(Task).filter(Task.project_id == project_id).all()
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
db.delete(task)
|
db.delete(task)
|
||||||
db_project.tasks.remove(task)
|
db_project.tasks.remove(task)
|
||||||
|
|
||||||
users: List[ProjectUserBase] = db.query(ProjectUserBase).join(ProjectUserBase).filter(getattr(ProjectBase, "id") == project_id).all()
|
|
||||||
for proj_user in users:
|
|
||||||
db_project.users.remove(proj_user)
|
|
||||||
proj_user.projects.remove(db_project)
|
|
||||||
|
|
||||||
db.delete(db_project)
|
db.delete(db_project)
|
||||||
db.commit()
|
db.commit()
|
||||||
return {"detail": "Project deleted successfully"}
|
return {"detail": "Project deleted successfully"}
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,11 @@ class ProjectFull(ProjectBase):
|
||||||
id: int
|
id: int
|
||||||
|
|
||||||
class ProjectCreate(BaseModel):
|
class ProjectCreate(BaseModel):
|
||||||
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
tasks: List[TaskBase] = []
|
tasks: List[TaskBase] = []
|
||||||
user_ids: List[int] = []
|
|
||||||
|
|
||||||
class ProjectUpdate(BaseModel):
|
class ProjectUpdate(BaseModel):
|
||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue