Skip to content

Commit

Permalink
frontend: use group num instead of global id
Browse files Browse the repository at this point in the history
  • Loading branch information
xerbalind committed May 18, 2024
1 parent ddc22e5 commit bdf3c5c
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 23 deletions.
6 changes: 4 additions & 2 deletions backend/alembic/versions/937c04aa37a1_add_group_num_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('team', sa.Column('num', sa.Integer(), nullable=False, server_default="0"))
op.add_column('team', sa.Column('num', sa.Integer(),
nullable=False, server_default="0"))
op.drop_column('team', 'team_name')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('team', sa.Column('team_name', sa.VARCHAR(), autoincrement=False, nullable=False))
op.add_column('team', sa.Column('team_name', sa.VARCHAR(),
autoincrement=False, nullable=False))
op.drop_column('team', 'num')
# ### end Alembic commands ###
3 changes: 2 additions & 1 deletion backend/src/group/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ async def retrieve_groups_by_user(
async def retrieve_groups_by_project(
project_id: int, db: AsyncSession = Depends(get_async_db)
) -> GroupList:
groups = await service.get_groups_by_project(db, project_id)
groups = list(await service.get_groups_by_project(db, project_id))
groups.sort(key=lambda x: x.num)
return GroupList(groups=groups)


Expand Down
7 changes: 4 additions & 3 deletions backend/src/group/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import Column, ForeignKey, Table,ForeignKeyConstraint,Integer,event, select, func
from sqlalchemy import Column, ForeignKey, Table, ForeignKeyConstraint, Integer, event, select, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from src.database import Base
from typing import List
Expand All @@ -24,8 +24,9 @@ class Group(Base):
)
members: Mapped[List["User"]] = relationship(secondary=StudentGroup, lazy="joined")

@event.listens_for(Group,"before_insert")
def set_id(_,connect,target: Group):

@event.listens_for(Group, "before_insert")
def set_id(_, connect, target: Group):
query = select(func.max(Group.num)).where(Group.project_id == target.project_id)
max_id = connect.execute(query).scalar()
target.num = (max_id or 0) + 1
4 changes: 2 additions & 2 deletions backend/tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"requirements": [],
"test_files": [],
}
group_data = { "project_id": 0}
group_data = {"project_id": 0}


@pytest_asyncio.fixture
Expand All @@ -41,7 +41,7 @@ async def group_id(client: AsyncClient, db: AsyncSession, project_id: int):

@pytest.mark.asyncio
async def test_create_group(client: AsyncClient, db: AsyncSession, project_id: int):
group_data = { "project_id": project_id}
group_data = {"project_id": project_id}
response = await client.post("/api/groups/", json=group_data)
assert response.status_code == 403

Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/groups/GroupCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<v-card class="groupcard" variant="flat">
<v-row>
<v-col cols="7">
<StudentsDialog :students="group.members" :title="group.team_name" />
<StudentsDialog
:students="group.members"
:title="$t('project.group', { number: group.num })"
/>
<v-btn v-if="isTeacher" variant="flat" @click="toGroupPage">
{{ $t("group.to_grouppage") }}
</v-btn>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/project/ProjectSideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</router-link>
<router-link v-if="group && !isSoloProject && !isTeacher" :to="`/groups/${group!.id}`">
<v-btn class="group-button" prepend-icon="mdi-account-group">
{{ $t("project.group", { number: group!.id }) }}
{{ $t("project.group", { number: group!.num }) }}
</v-btn>
</router-link>
<router-link v-else-if="!isSoloProject && !isTeacher" :to="`/project/${project!.id}/groups`">
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/models/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import type User from "@/models/User";
export default interface Group {
id: number;
project_id: number;
num: number;
score: number;
team_name: string;
members: User[];
}

export interface GroupForm {
project_id: number;
score: number;
team_name: string;
}
4 changes: 1 addition & 3 deletions frontend/src/views/CreateProjectView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,16 @@ async function submitForm() {
const emptyGroup: GroupForm = {
project_id: createdProjectId,
score: 0,
team_name: "Group 1",
};
await createGroupsMutation.mutateAsync({
projectId: createdProjectId,
groups: [emptyGroup],
});
} else if (selectedGroupProject.value === "random") {
const groups = divideStudentsIntoGroups(studentsData.value || [], capacity.value);
const groupsToCreate = groups.map((_, i) => ({
const groupsToCreate = groups.map((_) => ({

Check warning on line 173 in frontend/src/views/CreateProjectView.vue

View workflow job for this annotation

GitHub Actions / Run linters

'_' is defined but never used
project_id: createdProjectId,
score: 0,
team_name: "Group " + (i + 1),
}));
const createdGroups = await createGroupsMutation.mutateAsync({
projectId: createdProjectId,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/GroupView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{ $t("group.not_found") }}
</h1>
<div v-else>
<h1>{{ group!.team_name }}</h1>
<h1>{{ $t("project.group", { number: group!.num }) }}</h1>
<h2>{{ "Project: " + project!.name }}</h2>
<v-card>
<v-card-item :title="$t('group.members')">
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/views/GroupsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ const isTeacher = computed(() => {
if (!user.value || !instructors.value) {
return false;
}
return instructors.value.some((instructor) => instructor.uid === user.value.uid);
return (
user.value.is_teacher ||
user.value.is_admin ||
instructors.value.some((instructor) => instructor.uid === user.value.uid)
);
});
const { mutateAsync: createGroupMutate } = useCreateGroupsMutation();
Expand All @@ -107,7 +111,6 @@ async function createGroup() {
const groupForm: GroupForm = {
project_id: project.value!.id,
score: 0,
team_name: "Group " + groups.value!.length, // Set the default team name or prompt the user for input
};
try {
Expand Down
3 changes: 1 addition & 2 deletions frontend/tests/components/buttons/GroupButtons.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {ref} from "vue";
const mockGroup = {
members: [
{uid: "student1"}
],
team_name: "testgroep"
]
}

const mockMembers = [
Expand Down
3 changes: 1 addition & 2 deletions frontend/tests/components/groups/GroupCard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ vi.mock("@/components/buttons/GroupButtons.vue", () => ({
const mockGroup = {
members: [
{uid: "student1"}
],
team_name: "testgroep"
]
}

const mockProject = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/views/GroupsView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const mockProject = {
}

const mockGroups = [
{id: 1, team_name: "Group 1"}
{id: 1}
]

const mockUser = {
Expand Down

0 comments on commit bdf3c5c

Please sign in to comment.