Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: patch requirements #222

Merged
merged 1 commit into from
May 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 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 @@ -60,6 +61,10 @@ async def delete_project(db: AsyncSession, project_id: int):
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
) -> Project:
Expand All @@ -77,6 +82,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
Loading