service_engine_delete.py 1.4 KB
# coding=utf-8
#author:        4N
#createtime:    2021/9/14
#email:         nheweijun@sina.com

from app.util.component.ApiTemplate import ApiTemplate
from app.modules.service.models import ServiceEngine,db,Service
class Api(ApiTemplate):
    api_name = "注销服务引擎"
    def process(self):
        res = {}
        try:
            guid = self.para.get("guid")
            service_engine:ServiceEngine = ServiceEngine.query.filter_by(guid=guid).one_or_none()

            if not service_engine:
                raise Exception("服务不存在!")
            if service_engine.type=="AddServer":
                add_service = Service.query.filter_by(url=service_engine.url).one_or_none()
                if add_service:
                    db.session.delete(add_service)
            db.session.delete(service_engine)
            db.session.commit()
            res["result"] = True
        except Exception as e:
            raise e
        return res

    api_doc = {
        "tags": ["引擎接口"],
        "parameters": [
            {"name": "guid",
             "in": "formData",
             "type": "string",
             "description": "guid"},
        ],
        "responses": {
            200: {
                "schema": {
                    "properties": {
                    }
                }
            }
        }
    }