mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-09 14:00:15 -04:00
Implement create, delete, get_by_id, and get by resource and service.
This commit is contained in:
parent
a43fb7429a
commit
68f07b8c53
|
@ -3,6 +3,12 @@ from ..database import db_session
|
|||
from sqlalchemy.orm import Session
|
||||
from ..models.tag_model import Tag
|
||||
from ..entities.tag_entity import TagEntity
|
||||
from ..entities.resource_tag_entity import ResourceTagEntity
|
||||
from ..entities.service_tag_entity import ServiceTagEntity
|
||||
from .exceptions import ResourceNotFoundException
|
||||
from ..models.user_model import User
|
||||
from ..models.resource_model import Resource
|
||||
from ..models.service_model import Service
|
||||
from sqlalchemy import select
|
||||
|
||||
|
||||
|
@ -18,3 +24,99 @@ class TagService:
|
|||
entities = self._session.scalars(query).all()
|
||||
|
||||
return [entity.to_model() for entity in entities]
|
||||
|
||||
def get_tag_by_id(self, id:int) -> Tag:
|
||||
"""Returns tag based on it's id."""
|
||||
|
||||
tag = self._session.query(TagEntity).filter(TagEntity.id == id).one_or_none()
|
||||
return tag.to_model()
|
||||
|
||||
def create(self, user: User, tag: Tag) -> Tag:
|
||||
"""Creates a tag in the database with id and content."""
|
||||
|
||||
# Add user permission check here if needed
|
||||
|
||||
tag_entity = TagEntity.from_model(tag)
|
||||
self._session.add(tag_entity)
|
||||
self._session.commit
|
||||
|
||||
return tag_entity.to_model()
|
||||
|
||||
def delete(self, user: User, id:int) -> None:
|
||||
"""Method to delete a tag from the database, along with all connections."""
|
||||
|
||||
tag = (
|
||||
self._session.query(TagEntity)
|
||||
.filter(
|
||||
TagEntity.id == id
|
||||
)
|
||||
.one_or_none()
|
||||
)
|
||||
|
||||
if tag is None:
|
||||
raise ResourceNotFoundException(f"No tag found with matching id: {id}")
|
||||
|
||||
self._session.delete(tag)
|
||||
|
||||
resource_tags = (
|
||||
self._session.query(ResourceTagEntity)
|
||||
.filter(
|
||||
ResourceTagEntity.tagId == id
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
||||
for tag in resource_tags:
|
||||
self._session.delete(tag)
|
||||
|
||||
service_tags = (
|
||||
self._session.query(ServiceTagEntity)
|
||||
.filter(
|
||||
ServiceTagEntity.tagId == id
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
||||
for tag in service_tags:
|
||||
self._session.delete(tag)
|
||||
|
||||
self._session.commit()
|
||||
|
||||
def get_tags_for_resource(self, user: User, resource: Resource) -> list[Tag]:
|
||||
"""Get tags based on a resource."""
|
||||
tags: list[Tag]
|
||||
resource_tags = (
|
||||
self._session.query(ResourceTagEntity)
|
||||
.filter(
|
||||
ResourceTagEntity.tagId == resource.id
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
||||
if resource_tags is None:
|
||||
raise ResourceNotFoundException(f"No tags found for resource with id: {resource.id}")
|
||||
|
||||
for tag in resource_tags:
|
||||
tags.append(self.get_tag_by_id(tag.id))
|
||||
|
||||
return tags
|
||||
|
||||
def get_tags_for_service(self, user: User, service: Service) -> list[Tag]:
|
||||
"""Get tags based on a resource."""
|
||||
tags: list[Tag]
|
||||
service_tags = (
|
||||
self._session.query(ServiceTagEntity)
|
||||
.filter(
|
||||
ServiceTagEntity.tagId == service.id
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
||||
if service_tags is None:
|
||||
raise ResourceNotFoundException(f"No tags found for service with id: {service.id}")
|
||||
|
||||
for tag in service_tags:
|
||||
tags.append(self.get_tag_by_id(tag.id))
|
||||
|
||||
return tags
|
||||
|
||||
|
|
140
compass/package-lock.json
generated
140
compass/package-lock.json
generated
|
@ -14,7 +14,7 @@
|
|||
"@tanstack/match-sorter-utils": "^8.15.1",
|
||||
"@tanstack/react-table": "^8.15.0",
|
||||
"bufferutil": "^4.0.8",
|
||||
"next": "13.5.6",
|
||||
"next": "^14.2.13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
"utf-8-validate": "^6.0.3",
|
||||
|
@ -296,7 +296,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@next/env": {
|
||||
"version": "13.5.6",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.13.tgz",
|
||||
"integrity": "sha512-s3lh6K8cbW1h5Nga7NNeXrbe0+2jIIYK9YaA9T7IufDWnZpozdFUp6Hf0d5rNWUKu4fEuSX2rCKlGjCrtylfDw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@next/eslint-plugin-next": {
|
||||
|
@ -328,7 +330,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@next/swc-darwin-arm64": {
|
||||
"version": "13.5.6",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.13.tgz",
|
||||
"integrity": "sha512-IkAmQEa2Htq+wHACBxOsslt+jMoV3msvxCn0WFSfJSkv/scy+i/EukBKNad36grRxywaXUYJc9mxEGkeIs8Bzg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
@ -342,12 +346,13 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@next/swc-darwin-x64": {
|
||||
"version": "13.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.5.6.tgz",
|
||||
"integrity": "sha512-6cgBfxg98oOCSr4BckWjLLgiVwlL3vlLj8hXg2b+nDgm4bC/qVXXLfpLB9FHdoDu4057hzywbxKvmYGmi7yUzA==",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.13.tgz",
|
||||
"integrity": "sha512-Dv1RBGs2TTjkwEnFMVL5XIfJEavnLqqwYSD6LXgTPdEy/u6FlSrLBSSfe1pcfqhFEXRAgVL3Wpjibe5wXJzWog==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
|
@ -357,7 +362,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-arm64-gnu": {
|
||||
"version": "13.5.6",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.13.tgz",
|
||||
"integrity": "sha512-yB1tYEFFqo4ZNWkwrJultbsw7NPAAxlPXURXioRl9SdW6aIefOLS+0TEsKrWBtbJ9moTDgU3HRILL6QBQnMevg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
@ -371,7 +378,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-arm64-musl": {
|
||||
"version": "13.5.6",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.13.tgz",
|
||||
"integrity": "sha512-v5jZ/FV/eHGoWhMKYrsAweQ7CWb8xsWGM/8m1mwwZQ/sutJjoFaXchwK4pX8NqwImILEvQmZWyb8pPTcP7htWg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
@ -385,12 +394,13 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-x64-gnu": {
|
||||
"version": "13.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.5.6.tgz",
|
||||
"integrity": "sha512-Mc2b4xiIWKXIhBy2NBTwOxGD3nHLmq4keFk+d4/WL5fMsB8XdJRdtUlL87SqVCTSaf1BRuQQf1HvXZcy+rq3Nw==",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.13.tgz",
|
||||
"integrity": "sha512-aVc7m4YL7ViiRv7SOXK3RplXzOEe/qQzRA5R2vpXboHABs3w8vtFslGTz+5tKiQzWUmTmBNVW0UQdhkKRORmGA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
|
@ -400,12 +410,13 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-x64-musl": {
|
||||
"version": "13.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.5.6.tgz",
|
||||
"integrity": "sha512-CFHvP9Qz98NruJiUnCe61O6GveKKHpJLloXbDSWRhqhkJdZD2zU5hG+gtVJR//tyW897izuHpM6Gtf6+sNgJPQ==",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.13.tgz",
|
||||
"integrity": "sha512-4wWY7/OsSaJOOKvMsu1Teylku7vKyTuocvDLTZQq0TYv9OjiYYWt63PiE1nTuZnqQ4RPvME7Xai+9enoiN0Wrg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
|
@ -415,12 +426,13 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@next/swc-win32-arm64-msvc": {
|
||||
"version": "13.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.5.6.tgz",
|
||||
"integrity": "sha512-aFv1ejfkbS7PUa1qVPwzDHjQWQtknzAZWGTKYIAaS4NMtBlk3VyA6AYn593pqNanlicewqyl2jUhQAaFV/qXsg==",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.13.tgz",
|
||||
"integrity": "sha512-uP1XkqCqV2NVH9+g2sC7qIw+w2tRbcMiXFEbMihkQ8B1+V6m28sshBwAB0SDmOe0u44ne1vFU66+gx/28RsBVQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
|
@ -430,12 +442,13 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@next/swc-win32-ia32-msvc": {
|
||||
"version": "13.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.5.6.tgz",
|
||||
"integrity": "sha512-XqqpHgEIlBHvzwG8sp/JXMFkLAfGLqkbVsyN+/Ih1mR8INb6YCc2x/Mbwi6hsAgUnqQztz8cvEbHJUbSl7RHDg==",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.13.tgz",
|
||||
"integrity": "sha512-V26ezyjPqQpDBV4lcWIh8B/QICQ4v+M5Bo9ykLN+sqeKKBxJVDpEc6biDVyluTXTC40f5IqCU0ttth7Es2ZuMw==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
|
@ -445,12 +458,13 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@next/swc-win32-x64-msvc": {
|
||||
"version": "13.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.5.6.tgz",
|
||||
"integrity": "sha512-Cqfe1YmOS7k+5mGu92nl5ULkzpKuxJrP3+4AEuPmrpFZ3BHxTY3TnHmU1On3bFmFFs6FbTcdF58CCUProGpIGQ==",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.13.tgz",
|
||||
"integrity": "sha512-WwzOEAFBGhlDHE5Z73mNU8CO8mqMNLqaG+AO9ETmzdCQlJhVtWZnOl2+rqgVQS+YHunjOWptdFmNfbpwcUuEsw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
|
@ -614,18 +628,22 @@
|
|||
"@supabase/storage-js": "2.5.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@swc/counter": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz",
|
||||
"integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@swc/helpers": {
|
||||
"version": "0.5.2",
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.5.tgz",
|
||||
"integrity": "sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@swc/counter": "^0.1.3",
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@swc/helpers/node_modules/tslib": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
|
||||
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q=="
|
||||
},
|
||||
"node_modules/@tanstack/match-sorter-utils": {
|
||||
"version": "8.15.1",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/match-sorter-utils/-/match-sorter-utils-8.15.1.tgz",
|
||||
|
@ -6067,11 +6085,6 @@
|
|||
"node": ">=10.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/glob-to-regexp": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz",
|
||||
"integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw=="
|
||||
},
|
||||
"node_modules/glob/node_modules/balanced-match": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||
|
@ -6955,37 +6968,39 @@
|
|||
"dev": true
|
||||
},
|
||||
"node_modules/next": {
|
||||
"version": "13.5.6",
|
||||
"resolved": "https://registry.npmjs.org/next/-/next-13.5.6.tgz",
|
||||
"integrity": "sha512-Y2wTcTbO4WwEsVb4A8VSnOsG1I9ok+h74q0ZdxkwM3EODqrs4pasq7O0iUxbcS9VtWMicG7f3+HAj0r1+NtKSw==",
|
||||
"version": "14.2.13",
|
||||
"resolved": "https://registry.npmjs.org/next/-/next-14.2.13.tgz",
|
||||
"integrity": "sha512-BseY9YNw8QJSwLYD7hlZzl6QVDoSFHL/URN5K64kVEVpCsSOWeyjbIGK+dZUaRViHTaMQX8aqmnn0PHBbGZezg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@next/env": "13.5.6",
|
||||
"@swc/helpers": "0.5.2",
|
||||
"@next/env": "14.2.13",
|
||||
"@swc/helpers": "0.5.5",
|
||||
"busboy": "1.6.0",
|
||||
"caniuse-lite": "^1.0.30001406",
|
||||
"caniuse-lite": "^1.0.30001579",
|
||||
"graceful-fs": "^4.2.11",
|
||||
"postcss": "8.4.31",
|
||||
"styled-jsx": "5.1.1",
|
||||
"watchpack": "2.4.0"
|
||||
"styled-jsx": "5.1.1"
|
||||
},
|
||||
"bin": {
|
||||
"next": "dist/bin/next"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.14.0"
|
||||
"node": ">=18.17.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@next/swc-darwin-arm64": "13.5.6",
|
||||
"@next/swc-darwin-x64": "13.5.6",
|
||||
"@next/swc-linux-arm64-gnu": "13.5.6",
|
||||
"@next/swc-linux-arm64-musl": "13.5.6",
|
||||
"@next/swc-linux-x64-gnu": "13.5.6",
|
||||
"@next/swc-linux-x64-musl": "13.5.6",
|
||||
"@next/swc-win32-arm64-msvc": "13.5.6",
|
||||
"@next/swc-win32-ia32-msvc": "13.5.6",
|
||||
"@next/swc-win32-x64-msvc": "13.5.6"
|
||||
"@next/swc-darwin-arm64": "14.2.13",
|
||||
"@next/swc-darwin-x64": "14.2.13",
|
||||
"@next/swc-linux-arm64-gnu": "14.2.13",
|
||||
"@next/swc-linux-arm64-musl": "14.2.13",
|
||||
"@next/swc-linux-x64-gnu": "14.2.13",
|
||||
"@next/swc-linux-x64-musl": "14.2.13",
|
||||
"@next/swc-win32-arm64-msvc": "14.2.13",
|
||||
"@next/swc-win32-ia32-msvc": "14.2.13",
|
||||
"@next/swc-win32-x64-msvc": "14.2.13"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.1.0",
|
||||
"@playwright/test": "^1.41.2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"sass": "^1.3.0"
|
||||
|
@ -6994,6 +7009,9 @@
|
|||
"@opentelemetry/api": {
|
||||
"optional": true
|
||||
},
|
||||
"@playwright/test": {
|
||||
"optional": true
|
||||
},
|
||||
"sass": {
|
||||
"optional": true
|
||||
}
|
||||
|
@ -8174,6 +8192,12 @@
|
|||
"node": ">=8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz",
|
||||
"integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==",
|
||||
"license": "0BSD"
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.4.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz",
|
||||
|
@ -8199,18 +8223,6 @@
|
|||
"node": ">=6.14.2"
|
||||
}
|
||||
},
|
||||
"node_modules/watchpack": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz",
|
||||
"integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==",
|
||||
"dependencies": {
|
||||
"glob-to-regexp": "^0.4.1",
|
||||
"graceful-fs": "^4.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/wrap-ansi": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.0.tgz",
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
"@tanstack/match-sorter-utils": "^8.15.1",
|
||||
"@tanstack/react-table": "^8.15.0",
|
||||
"bufferutil": "^4.0.8",
|
||||
"next": "13.5.6",
|
||||
"next": "^14.2.13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
"utf-8-validate": "^6.0.3",
|
||||
|
|
Loading…
Reference in New Issue
Block a user