From 43ec8ec01e65202bbf946d638bf002f47725d50e Mon Sep 17 00:00:00 2001 From: dongli Date: Sun, 18 May 2025 23:09:39 -0700 Subject: [PATCH] Clean up --- .../app/common/daos/hello_world/__init__.py | 6 ---- .../daos/hello_world/hello_world_dao.py | 30 ------------------- apps/devops/app/common/models/__init__.py | 3 +- .../common/models/deployment/deployment.py | 12 ++++++-- .../app/common/models/hello_world/__init__.py | 0 .../common/models/hello_world/hello_world.py | 17 ----------- apps/devops/app/routes/deployment/apis.py | 1 - 7 files changed, 11 insertions(+), 58 deletions(-) delete mode 100644 apps/devops/app/common/daos/hello_world/__init__.py delete mode 100644 apps/devops/app/common/daos/hello_world/hello_world_dao.py delete mode 100644 apps/devops/app/common/models/hello_world/__init__.py delete mode 100644 apps/devops/app/common/models/hello_world/hello_world.py diff --git a/apps/devops/app/common/daos/hello_world/__init__.py b/apps/devops/app/common/daos/hello_world/__init__.py deleted file mode 100644 index 463a9cb..0000000 --- a/apps/devops/app/common/daos/hello_world/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -from app.common.daos.hello_world.hello_world_dao import HelloWorldDao - -hello_world_dao = HelloWorldDao() - -def get_hello_world_dao() -> HelloWorldDao: - return hello_world_dao diff --git a/apps/devops/app/common/daos/hello_world/hello_world_dao.py b/apps/devops/app/common/daos/hello_world/hello_world_dao.py deleted file mode 100644 index 3b3a112..0000000 --- a/apps/devops/app/common/daos/hello_world/hello_world_dao.py +++ /dev/null @@ -1,30 +0,0 @@ -from app.common.models.hello_world.hello_world import HelloWorld - -class HelloWorldDao: - def __init__(self): - pass - - async def create_hello_world(self, message: str, count: int): - hello_world = HelloWorld(message=message, count=count) - await hello_world.insert() - return hello_world - - async def get_hello_world(self, id: str): - hello_world = await HelloWorld.get(id) - return hello_world - - async def update_hello_world(self, id: str, message: str, count: int): - hello_world = await HelloWorld.get(id) - if hello_world: - hello_world.message = message - hello_world.count = count - await hello_world.save() - return hello_world - return None - - async def delete_hello_world(self, id: str): - hello_world = await HelloWorld.get(id) - if hello_world: - await hello_world.delete() - return True - return False \ No newline at end of file diff --git a/apps/devops/app/common/models/__init__.py b/apps/devops/app/common/models/__init__.py index 35ed321..dd9cfe5 100644 --- a/apps/devops/app/common/models/__init__.py +++ b/apps/devops/app/common/models/__init__.py @@ -1,5 +1,4 @@ -from app.common.models.hello_world.hello_world import HelloWorld from app.common.models.deployment.deployment import Deployment # list of beanie document models -db_models = [HelloWorld, Deployment] \ No newline at end of file +db_models = [Deployment] \ No newline at end of file diff --git a/apps/devops/app/common/models/deployment/deployment.py b/apps/devops/app/common/models/deployment/deployment.py index 7abff26..c29feeb 100644 --- a/apps/devops/app/common/models/deployment/deployment.py +++ b/apps/devops/app/common/models/deployment/deployment.py @@ -2,12 +2,18 @@ from datetime import datetime from typing import Literal from beanie import Document -from pydantic import Field +from bson import ObjectId +from pydantic import Field, field_validator from pydantic import BaseModel class Deployment(Document): deployment_id: str = Field(alias="_id") + @field_validator("deployment_id", mode="before") + @classmethod + def convert_object_id(cls, v): + return str(v) + deployment_stage: str deployment_status: Literal["started", "failed", "succeeded", "aborted"] @@ -31,7 +37,9 @@ class Deployment(Document): indexes = [ [("deployment_product_id", 1), ("created_at", 1)], # Compound index [("deployment_id", 1), ("deployment_status", 1)], # Compound index - {"keys": [("deployment_id", 1), ("deployment_stage", 1)], "unique": True} # Unique compound index + + # somehow combo + unique errors out + # {"keys": [("deployment_id", 1), ("deployment_stage", 1)], "unique": True} # Unique compound index ] class InitDeploymentRequest(BaseModel): diff --git a/apps/devops/app/common/models/hello_world/__init__.py b/apps/devops/app/common/models/hello_world/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/devops/app/common/models/hello_world/hello_world.py b/apps/devops/app/common/models/hello_world/hello_world.py deleted file mode 100644 index 55000c7..0000000 --- a/apps/devops/app/common/models/hello_world/hello_world.py +++ /dev/null @@ -1,17 +0,0 @@ -from datetime import datetime - -from beanie import Document - - -class HelloWorld(Document): - message: str - count: int = 0 - created_time: datetime = datetime.now() - - class Settings: - name = "hello_world" - indexes = [ - [("message", 1), ("count", 1)] - ] - - diff --git a/apps/devops/app/routes/deployment/apis.py b/apps/devops/app/routes/deployment/apis.py index 50eff75..c6ebefc 100644 --- a/apps/devops/app/routes/deployment/apis.py +++ b/apps/devops/app/routes/deployment/apis.py @@ -4,7 +4,6 @@ from typing import List from fastapi import APIRouter, Depends from loguru import logger -from app.common.daos.hello_world import get_hello_world_dao, HelloWorldDao from app.common.models.deployment.deployment import Deployment, InitDeploymentRequest from app.routes.deployment.service import DeploymentService, get_deployment_service