Skip to content

Commit

Permalink
fix: patch requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
xerbalind committed May 18, 2024
1 parent 1ff5dbc commit d9aa3d7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backend/src/project/service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Sequence

from sqlalchemy import delete
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
from src.subject.models import InstructorSubject, StudentSubject, Subject
Expand Down Expand Up @@ -59,6 +60,9 @@ async def delete_project(db: AsyncSession, project_id: int):
await db.delete(project)
await db.commit()

async def delete_requirements_for_project(db: AsyncSession, project_id: int):
await db.execute(delete(Requirement).where(Requirement.project_id == project_id))


async def update_project(
db: AsyncSession, project_id: int, project_update: ProjectUpdate
Expand All @@ -77,6 +81,7 @@ async def update_project(
if project_update.is_visible is not None:
project.is_visible = project_update.is_visible
if project_update.requirements is not None:
await delete_requirements_for_project(db,project_id)
project.requirements = [Requirement(**r.model_dump())
for r in project_update.requirements]

Expand Down

0 comments on commit d9aa3d7

Please sign in to comment.