mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-21 02:50:15 -04:00
Update entities and models for resource/service tagging
This commit is contained in:
parent
68f07b8c53
commit
21167f7a6b
|
@ -64,4 +64,5 @@ class ResourceEntity(EntityBase):
|
||||||
summary=self.summary,
|
summary=self.summary,
|
||||||
link=self.link,
|
link=self.link,
|
||||||
program=self.program,
|
program=self.program,
|
||||||
|
tags=[tag.tag.to_model() for tag in self.resourceTags],
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,6 +15,8 @@ from datetime import datetime
|
||||||
# Import self for to model
|
# Import self for to model
|
||||||
from typing import Self
|
from typing import Self
|
||||||
|
|
||||||
|
from ..models import ResourceTag
|
||||||
|
|
||||||
|
|
||||||
class ResourceTagEntity(EntityBase):
|
class ResourceTagEntity(EntityBase):
|
||||||
|
|
||||||
|
@ -30,13 +32,13 @@ class ResourceTagEntity(EntityBase):
|
||||||
resource: Mapped["ResourceEntity"] = relationship(back_populates="resourceTags")
|
resource: Mapped["ResourceEntity"] = relationship(back_populates="resourceTags")
|
||||||
tag: Mapped["TagEntity"] = relationship(back_populates="resourceTags")
|
tag: Mapped["TagEntity"] = relationship(back_populates="resourceTags")
|
||||||
|
|
||||||
# @classmethod
|
@classmethod
|
||||||
# def from_model (cls, model: resource_tag_model) -> Self:
|
def from_model(cls, model: ResourceTag) -> Self:
|
||||||
# return cls (
|
return cls(
|
||||||
# id = model.id,
|
id=model.id,
|
||||||
# resourceId = model.resourceId,
|
resourceId=model.resource_id,
|
||||||
# tagId = model.tagId,
|
tagId=model.tag_id,
|
||||||
# )
|
)
|
||||||
|
|
||||||
# def to_model (self) -> resource_tag_model:
|
# def to_model (self) -> resource_tag_model:
|
||||||
# return user_model(
|
# return user_model(
|
||||||
|
|
|
@ -16,21 +16,24 @@ from ..models.tag_model import Tag
|
||||||
|
|
||||||
from typing import Self
|
from typing import Self
|
||||||
|
|
||||||
|
|
||||||
class TagEntity(EntityBase):
|
class TagEntity(EntityBase):
|
||||||
|
|
||||||
#set table name
|
# set table name
|
||||||
__tablename__ = "tag"
|
__tablename__ = "tag"
|
||||||
|
|
||||||
#set fields
|
# set fields
|
||||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now)
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now)
|
||||||
content: Mapped[str] = mapped_column(String(100), nullable=False)
|
content: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||||
|
|
||||||
#relationships
|
# relationships
|
||||||
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(back_populates="tag", cascade="all,delete")
|
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(
|
||||||
serviceTags: Mapped[list["ServiceTagEntity"]] = relationship(back_populates="tag", cascade="all,delete")
|
back_populates="tag", cascade="all,delete"
|
||||||
|
)
|
||||||
|
serviceTags: Mapped[list["ServiceTagEntity"]] = relationship(
|
||||||
|
back_populates="tag", cascade="all,delete"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_model(cls, model: Tag) -> Self:
|
def from_model(cls, model: Tag) -> Self:
|
||||||
|
@ -45,7 +48,7 @@ class TagEntity(EntityBase):
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
id=model.id,
|
id=model.id,
|
||||||
content=model.id,
|
content=model.content,
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_model(self) -> Tag:
|
def to_model(self) -> Tag:
|
||||||
|
@ -60,6 +63,3 @@ class TagEntity(EntityBase):
|
||||||
id=self.id,
|
id=self.id,
|
||||||
content=self.content,
|
content=self.content,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ from typing import List
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from .enum_for_models import ProgramTypeEnum
|
from .enum_for_models import ProgramTypeEnum
|
||||||
|
from .tag_model import Tag
|
||||||
|
|
||||||
|
|
||||||
class Resource(BaseModel):
|
class Resource(BaseModel):
|
||||||
|
@ -13,3 +14,4 @@ class Resource(BaseModel):
|
||||||
link: str = Field(..., max_length=150, description="link to the resource")
|
link: str = Field(..., max_length=150, description="link to the resource")
|
||||||
program: ProgramTypeEnum
|
program: ProgramTypeEnum
|
||||||
created_at: Optional[datetime]
|
created_at: Optional[datetime]
|
||||||
|
tags: List[Tag] = []
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel
|
||||||
from enum import Enum
|
|
||||||
from typing import List
|
|
||||||
from datetime import datetime
|
|
||||||
from typing import Optional
|
|
||||||
from .tag_model import Tag
|
|
||||||
from .resource_model import Resource
|
|
||||||
|
|
||||||
|
|
||||||
class ResourceTag(Resource, BaseModel):
|
class ResourceTag(BaseModel):
|
||||||
id: int | None = None
|
id: int | None = None
|
||||||
resourceid: int | None = None
|
tag_id: int
|
||||||
tagid: List[Tag]
|
resource_id: int
|
||||||
|
|
Loading…
Reference in New Issue
Block a user