From 1efaf42faa06dae94c266f34c5b348c7b7f58038 Mon Sep 17 00:00:00 2001 From: drieshuybens Date: Thu, 23 May 2024 17:19:08 +0200 Subject: [PATCH] Groupfixes (#254) * fix group wrong num error * dries fix --------- Co-authored-by: Xander Bil --- backend/src/group/models.py | 2 +- backend/src/group/schemas.py | 2 +- backend/src/group/service.py | 16 +++++++++++----- .../src/components/project/RadiobuttonList.vue | 4 ++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/backend/src/group/models.py b/backend/src/group/models.py index d40855d8..9f89eb75 100644 --- a/backend/src/group/models.py +++ b/backend/src/group/models.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, ForeignKey, Table, ForeignKeyConstraint, Integer, event, select, func +from sqlalchemy import Column, ForeignKey, Table, event, select, func from sqlalchemy.orm import Mapped, mapped_column, relationship from src.database import Base from typing import List diff --git a/backend/src/group/schemas.py b/backend/src/group/schemas.py index 151aeb0b..9d58802f 100644 --- a/backend/src/group/schemas.py +++ b/backend/src/group/schemas.py @@ -1,6 +1,6 @@ from typing import Sequence -from pydantic import BaseModel, ConfigDict, Field +from pydantic import BaseModel, ConfigDict from src.user.schemas import User diff --git a/backend/src/group/service.py b/backend/src/group/service.py index a675bd4a..5b660d95 100644 --- a/backend/src/group/service.py +++ b/backend/src/group/service.py @@ -7,6 +7,11 @@ from . import schemas from .models import Group, StudentGroup +from collections import defaultdict +import asyncio + +locks = defaultdict(asyncio.Lock) + async def get_group_by_id(db: AsyncSession, group_id: int) -> Group | None: return (await db.execute(select(Group).filter_by(id=group_id))).unique().scalar_one_or_none() @@ -31,11 +36,12 @@ async def get_groups_by_user(db: AsyncSession, user_id: str) -> Sequence[Group]: async def create_group(db: AsyncSession, group: schemas.GroupCreate) -> Group: - db_group = Group(**group.model_dump()) - db.add(db_group) - await db.commit() - await db.refresh(db_group) - return db_group + async with locks[group.project_id]: + db_group = Group(**group.model_dump()) + db.add(db_group) + await db.commit() + await db.refresh(db_group) + return db_group async def join_group(db: AsyncSession, team_id: int, user_id: str): diff --git a/frontend/src/components/project/RadiobuttonList.vue b/frontend/src/components/project/RadiobuttonList.vue index 6df6cf28..71e2707f 100644 --- a/frontend/src/components/project/RadiobuttonList.vue +++ b/frontend/src/components/project/RadiobuttonList.vue @@ -59,6 +59,10 @@ watch(isToggled, (newVal) => { } }); +watch(selectedOption, (newVal) => { + emit("update:selectedOption", newVal); +}); + function handleDateChange(value: Date) { emit("update:date", value); }