mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-20 10:30:16 -04:00
Updated main.py for API routes to include tags and rolled entities back.
This commit is contained in:
parent
4c3d49004a
commit
a563ca2bfa
|
@ -23,22 +23,22 @@ openapi_tags = {
|
||||||
def create(
|
def create(
|
||||||
subject: User,
|
subject: User,
|
||||||
tag: Tag,
|
tag: Tag,
|
||||||
tag_service: TagService
|
tag_service: TagService=Depends()
|
||||||
):
|
):
|
||||||
return tag_service.create(subject, tag)
|
return tag_service.create(subject, tag)
|
||||||
|
|
||||||
@api.get("", response_model=List[Tag], tags=["Tag"])
|
@api.get("", response_model=List[Tag], tags=["Tag"])
|
||||||
def get_all(
|
def get_all(
|
||||||
subject: User,
|
subject: User,
|
||||||
tag_svc: TagService
|
tag_svc: TagService=Depends()
|
||||||
):
|
):
|
||||||
return tag_svc.get_all()
|
return tag_svc.get_all()
|
||||||
|
|
||||||
@api.put("", response_model=Tag, tags=["Tag"])
|
@api.put("", response_model=Tag, tags=["Tag"])
|
||||||
def delete(
|
def update(
|
||||||
subject: User,
|
subject: User,
|
||||||
tag: Tag,
|
tag: Tag,
|
||||||
tag_svc: TagService
|
tag_svc: TagService=Depends()
|
||||||
):
|
):
|
||||||
return tag_svc.delete(subject, tag)
|
return tag_svc.delete(subject, tag)
|
||||||
|
|
||||||
|
@ -46,6 +46,6 @@ def delete(
|
||||||
def delete(
|
def delete(
|
||||||
subject: User,
|
subject: User,
|
||||||
tag: Tag,
|
tag: Tag,
|
||||||
tag_svc: TagService
|
tag_svc: TagService=Depends()
|
||||||
):
|
):
|
||||||
tag_svc.delete(subject, tag)
|
tag_svc.delete(subject, tag)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
""" Defines the table for storing resources """
|
""" Defines the table for storing resources """
|
||||||
|
|
||||||
# Import our mapped SQL types from SQLAlchemy
|
# Import our mapped SQL types from SQLAlchemy
|
||||||
from sqlalchemy import ForeignKey, Integer, String, DateTime, Enum
|
from sqlalchemy import Integer, String, DateTime, Enum
|
||||||
|
|
||||||
# Import mapping capabilities from the SQLAlchemy ORM
|
# Import mapping capabilities from the SQLAlchemy ORM
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
|
@ -31,7 +31,9 @@ class ResourceEntity(EntityBase):
|
||||||
link: Mapped[str] = mapped_column(String, nullable=False)
|
link: Mapped[str] = mapped_column(String, nullable=False)
|
||||||
program: Mapped[Program_Enum] = mapped_column(Enum(Program_Enum), nullable=False)
|
program: Mapped[Program_Enum] = mapped_column(Enum(Program_Enum), nullable=False)
|
||||||
# relationships
|
# relationships
|
||||||
tags: Mapped[list["ResourceTagEntity"]] = relationship(back_populates="resource")
|
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(
|
||||||
|
back_populates="resource", cascade="all,delete"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_model(cls, model: Resource) -> Self:
|
def from_model(cls, model: Resource) -> Self:
|
||||||
|
|
|
@ -23,10 +23,12 @@ class ResourceTagEntity(EntityBase):
|
||||||
|
|
||||||
# set fields or 'columns' for the user table
|
# set fields or 'columns' for the user table
|
||||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||||
resource_id: Mapped[int] = mapped_column(ForeignKey("resource.id"), primary_key=True)
|
resourceId: Mapped[int] = mapped_column(ForeignKey("resource.id"))
|
||||||
tag_id: Mapped[int] = mapped_column(ForeignKey("tag.id", primary_key=True))
|
tagId: Mapped[int] = mapped_column(ForeignKey("tag.id"))
|
||||||
resource: Mapped["ResourceEntity"] = mapped_column(backpopulates="tags")
|
|
||||||
tag: Mapped["TagEntity"] = mapped_column(backpopulates="resource_tags")
|
# relationships
|
||||||
|
resource: Mapped["ResourceEntity"] = 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: resource_tag_model) -> Self:
|
||||||
|
|
|
@ -20,7 +20,6 @@ from backend.models.service_model import Service
|
||||||
from typing import Self
|
from typing import Self
|
||||||
from backend.models.enum_for_models import ProgramTypeEnum
|
from backend.models.enum_for_models import ProgramTypeEnum
|
||||||
|
|
||||||
|
|
||||||
class ServiceEntity(EntityBase):
|
class ServiceEntity(EntityBase):
|
||||||
|
|
||||||
# set table name
|
# set table name
|
||||||
|
@ -33,32 +32,16 @@ class ServiceEntity(EntityBase):
|
||||||
status: Mapped[str] = mapped_column(String(32), nullable=False)
|
status: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||||
summary: Mapped[str] = mapped_column(String(100), nullable=False)
|
summary: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||||
requirements: Mapped[list[str]] = mapped_column(ARRAY(String))
|
requirements: Mapped[list[str]] = mapped_column(ARRAY(String))
|
||||||
program: Mapped[ProgramTypeEnum] = mapped_column(
|
program: Mapped[ProgramTypeEnum] = mapped_column(Enum(ProgramTypeEnum), nullable=False)
|
||||||
Enum(ProgramTypeEnum), nullable=False
|
|
||||||
)
|
|
||||||
|
|
||||||
# relationships
|
# relationships
|
||||||
tags: Mapped[list["ServiceTagEntity"]] = relationship(
|
serviceTags: Mapped[list["ServiceTagEntity"]] = relationship(
|
||||||
back_populates="service", cascade="all,delete"
|
back_populates="service", cascade="all,delete"
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_model(self) -> Service:
|
def to_model(self) -> Service:
|
||||||
return Service(
|
return Service(id=self.id, name=self.name, status=self.status, summary=self.summary, requirements=self.requirements, program=self.program)
|
||||||
id=self.id,
|
|
||||||
name=self.name,
|
|
||||||
status=self.status,
|
|
||||||
summary=self.summary,
|
|
||||||
requirements=self.requirements,
|
|
||||||
program=self.program,
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_model(cls, model: Service) -> Self:
|
def from_model(cls, model:Service) -> Self:
|
||||||
return cls(
|
return cls(id=model.id, name=model.name, status=model.status, summary=model.summary, requirements=model.requirements, program=model.program)
|
||||||
id=model.id,
|
|
||||||
name=model.name,
|
|
||||||
status=model.status,
|
|
||||||
summary=model.summary,
|
|
||||||
requirements=model.requirements,
|
|
||||||
program=model.program,
|
|
||||||
)
|
|
|
@ -17,7 +17,10 @@ class ServiceTagEntity(EntityBase):
|
||||||
|
|
||||||
# set fields or 'columns' for the user table
|
# set fields or 'columns' for the user table
|
||||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||||
resource_id: Mapped[int] = mapped_column(ForeignKey("service.id"), primary_key=True)
|
serviceId: Mapped[int] = mapped_column(ForeignKey("service.id"))
|
||||||
tag_id: Mapped[int] = mapped_column(ForeignKey("tag.id", primary_key=True))
|
tagId: Mapped[int] = mapped_column(ForeignKey("tag.id"))
|
||||||
service: Mapped["ServiceEntity"] = mapped_column(backpopulates="tags")
|
|
||||||
tag: Mapped["TagEntity"] = mapped_column(backpopulates="service_tags")
|
# relationships
|
||||||
|
service: Mapped["ServiceEntity"] = relationship(back_populates="serviceTags")
|
||||||
|
tag: Mapped["TagEntity"] = relationship(back_populates="serviceTags")
|
||||||
|
|
|
@ -16,20 +16,21 @@ 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)
|
||||||
resource_tags: Mapped[list["ResourceTagEntity"]] = relationship(
|
|
||||||
back_populates="tag"
|
#relationships
|
||||||
)
|
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(back_populates="tag", cascade="all,delete")
|
||||||
service_tags: Mapped[list["ServiceTagEntity"]] = relationship(back_populates="tag")
|
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:
|
||||||
|
@ -44,8 +45,8 @@ class TagEntity(EntityBase):
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
id=model.id,
|
id=model.id,
|
||||||
|
created_at=model.created_at,
|
||||||
content=model.id,
|
content=model.id,
|
||||||
created_at=model.created_at
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_model(self) -> Tag:
|
def to_model(self) -> Tag:
|
||||||
|
@ -58,6 +59,6 @@ class TagEntity(EntityBase):
|
||||||
|
|
||||||
return Tag(
|
return Tag(
|
||||||
id=self.id,
|
id=self.id,
|
||||||
|
create_at=self.created_at,
|
||||||
content=self.content,
|
content=self.content,
|
||||||
created_at=self.created_at
|
|
||||||
)
|
)
|
|
@ -2,7 +2,9 @@ from fastapi import FastAPI, Request
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from fastapi.middleware.gzip import GZipMiddleware
|
from fastapi.middleware.gzip import GZipMiddleware
|
||||||
|
|
||||||
from .api import user, health, service, resource
|
|
||||||
|
|
||||||
|
from .api import user, health, service, resource, tag
|
||||||
|
|
||||||
description = """
|
description = """
|
||||||
Welcome to the **COMPASS** RESTful Application Programming Interface.
|
Welcome to the **COMPASS** RESTful Application Programming Interface.
|
||||||
|
@ -17,12 +19,13 @@ app = FastAPI(
|
||||||
health.openapi_tags,
|
health.openapi_tags,
|
||||||
service.openapi_tags,
|
service.openapi_tags,
|
||||||
resource.openapi_tags,
|
resource.openapi_tags,
|
||||||
|
tag.openapi_tags
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
app.add_middleware(GZipMiddleware)
|
app.add_middleware(GZipMiddleware)
|
||||||
|
|
||||||
feature_apis = [user, health, service, resource]
|
feature_apis = [user, health, service, resource, tag]
|
||||||
|
|
||||||
for feature_api in feature_apis:
|
for feature_api in feature_apis:
|
||||||
app.include_router(feature_api.api)
|
app.include_router(feature_api.api)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user