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

Skill descriptions #396

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Add description to skills_sub_skill

Revision ID: 92dd17d5ba45
Create Date: 2024-10-31 04:08:26.375163
"""

from alembic import op

import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "92dd17d5ba45"
down_revision = "e976176560c2"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column("skills_sub_skill", sa.Column("description", sa.Text, nullable=True))


def downgrade() -> None:
op.drop_column("skills_sub_skill", "description")
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Add description to skills_root_skill

Revision ID: e976176560c2
Create Date: 2024-10-31 04:08:11.984151
"""

from alembic import op

import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "e976176560c2"
down_revision = "1a9e957978e2"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column("skills_root_skill", sa.Column("description", sa.Text, nullable=True))


def downgrade() -> None:
op.drop_column("skills_root_skill", "description")
8 changes: 8 additions & 0 deletions api/endpoints/skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ async def create_root_skill(data: CreateRootSkill) -> Any:
skill = models.RootSkill(
id=data.id,
name=data.name,
description=data.description,
sub_skills=[],
dependencies=cast(list[models.RootSkill], dependencies),
row=data.row,
Expand Down Expand Up @@ -151,6 +152,9 @@ async def update_root_skill(*, skill: models.RootSkill = get_root_skill, data: U
if data.name is not None and data.name != skill.name:
skill.name = data.name

if data.description is not None and data.description != skill.description:
skill.description = data.description

if data.dependencies is not None and data.dependencies != {dep.id for dep in skill.dependencies}:
skills: dict[str, models.RootSkill] = {
skill.id: skill async for skill in await db.stream(select(models.RootSkill))
Expand Down Expand Up @@ -244,6 +248,7 @@ async def create_sub_skill(*, root_skill: models.RootSkill = get_root_skill, dat
id=data.id,
parent_id=root_skill.id,
name=data.name,
description=data.description,
dependencies=cast(list[models.SubSkill], dependencies),
courses=[models.SkillCourse(skill_id=data.id, course_id=course.id) for course in cast(list[Course], courses)],
row=data.row,
Expand Down Expand Up @@ -272,6 +277,9 @@ async def update_sub_skill(*, skill: models.SubSkill = get_sub_skill, data: Upda
if data.name is not None and data.name != skill.name:
skill.name = data.name

if data.description is not None and data.description != skill.description:
skill.description = data.description

if data.dependencies is not None and data.dependencies != {dep.id for dep in skill.dependencies}:
skills: dict[str, models.RootSkill] = {
skill.id: skill async for skill in await db.stream(filter_by(models.SubSkill, parent_id=skill.parent_id))
Expand Down
4 changes: 3 additions & 1 deletion api/models/root_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING, Any

from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, relationship

from api.database import Base
Expand All @@ -24,6 +24,7 @@ class RootSkill(Base):

id: Mapped[str] = Column(String(256), primary_key=True, unique=True)
name: Mapped[str] = Column(String(256))
description: Mapped[str | None] = Column(Text)
row: Mapped[int] = Column(Integer)
column: Mapped[int] = Column(Integer)
sub_tree_rows: Mapped[int] = Column(Integer)
Expand Down Expand Up @@ -56,6 +57,7 @@ def serialize(self) -> dict[str, Any]:
return {
"id": self.id,
"name": self.name,
"description": self.description,
"dependencies": [dependency.id for dependency in self.dependencies],
"dependents": [dependent.id for dependent in self.dependents],
"skills": [sub_skill.id for sub_skill in self.sub_skills],
Expand Down
4 changes: 3 additions & 1 deletion api/models/sub_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING

from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, relationship

from api.database import Base
Expand All @@ -29,6 +29,7 @@ class SubSkill(Base):
parent_id: Mapped[str] = Column(String(256), ForeignKey("skills_root_skill.id"))
parent: RootSkill = relationship("RootSkill", back_populates="sub_skills", lazy="selectin")
name: Mapped[str] = Column(String(256))
description: Mapped[str | None] = Column(Text)
row: Mapped[int] = Column(Integer)
column: Mapped[int] = Column(Integer)
icon: Mapped[str | None] = Column(String(256), nullable=True)
Expand Down Expand Up @@ -61,6 +62,7 @@ def serialize(self) -> schemas.SubSkill:
id=self.id,
parent_id=self.parent_id,
name=self.name,
description=self.description,
dependencies=[dependency.id for dependency in self.dependencies],
dependents=[dependent.id for dependent in self.dependents],
courses=[course.course_id for course in self.courses],
Expand Down
8 changes: 8 additions & 0 deletions api/schemas/skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class RootSkill(BaseModel):
id: str = Field(description="ID of the skill")
name: str = Field(description="Name of the skill")
description: str | None = Field(description="Description of the skill")
dependencies: list[str] = Field(description="List of skill dependencies")
dependents: list[str] = Field(description="List of skills that depend on this skill")
skills: list[str] = Field(description="List of sub skills")
Expand All @@ -18,6 +19,7 @@ class RootSkill(BaseModel):
Config = example(
id="datenbank_experte",
name="Datenbank-Experte",
description="Introduction to the skill",
dependencies=["grundlagen_der_programmierung_und_datenhaltung"],
dependents=["data_scientist"],
skills=["mongodb", "postgresql", "mysql", "fortgeschrittene_datenbankmodelle"],
Expand Down Expand Up @@ -45,6 +47,7 @@ class UpdateRootTree(BaseModel):
class CreateRootSkill(BaseModel):
id: str = Field(max_length=256, description="ID of the skill")
name: str = Field(max_length=256, description="Name of the skill")
description: str | None = Field(description="Description of the skill")
dependencies: set[str] = Field(description="List of skill dependencies")
row: int = Field(ge=0, lt=1 << 31, description="Row of the skill in the skill tree")
column: int = Field(ge=0, lt=1 << 31, description="Column of the skill in the skill tree")
Expand All @@ -55,6 +58,7 @@ class CreateRootSkill(BaseModel):

class UpdateRootSkill(BaseModel):
name: str | None = Field(max_length=256, description="Name of the skill")
description: str | None = Field(description="Description of the skill")
dependencies: set[str] | None = Field(description="List of skill dependencies")
row: int | None = Field(ge=0, lt=1 << 31, description="Row of the skill in the skill tree")
column: int | None = Field(ge=0, lt=1 << 31, description="Column of the skill in the skill tree")
Expand All @@ -67,6 +71,7 @@ class SubSkill(BaseModel):
id: str = Field(description="ID of the skill")
parent_id: str = Field(description="ID of the parent skill")
name: str = Field(description="Name of the skill")
description: str | None = Field(description="Description of the skill")
dependencies: list[str] = Field(description="List of skill dependencies")
dependents: list[str] = Field(description="List of skills that depend on this skill")
courses: list[str] = Field(description="List of course ids")
Expand All @@ -78,6 +83,7 @@ class SubSkill(BaseModel):
id="datenanalyse_mit_python",
parent_id="datenanalyse",
name="Datenanalyse mit Python",
description="Introduction to the skill",
dependencies=["algorithmen_zur_datenanalyse"],
dependents=["datenvisualisierung_mit_python"],
courses=["datenanalyse_mit_python"],
Expand All @@ -98,6 +104,7 @@ class SubSkillTree(BaseModel):
class CreateSubSkill(BaseModel):
id: str = Field(max_length=256, description="ID of the skill")
name: str = Field(max_length=256, description="Name of the skill")
description: str | None = Field(description="Description of the skill")
dependencies: set[str] = Field(description="List of skill dependencies")
courses: set[str] = Field(description="List of course ids")
row: int = Field(ge=0, lt=1 << 31, description="Row of the skill in the skill tree")
Expand All @@ -107,6 +114,7 @@ class CreateSubSkill(BaseModel):

class UpdateSubSkill(BaseModel):
name: str | None = Field(max_length=256, description="Name of the skill")
description: str | None = Field(description="Description of the skill")
dependencies: set[str] | None = Field(description="List of skill dependencies")
courses: set[str] | None = Field(description="List of course ids")
row: int | None = Field(ge=0, lt=1 << 31, description="Row of the skill in the skill tree")
Expand Down
Loading