From 5376b150e9414d8854d3c069bf9e122f4dbb4f33 Mon Sep 17 00:00:00 2001 From: DingZQ Date: Fri, 28 Mar 2025 20:39:59 +0800 Subject: [PATCH] Refine --- api/s39_user.py | 37 ------------------------------------- api/s40_schema.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 37 deletions(-) delete mode 100644 api/s39_user.py create mode 100644 api/s40_schema.py diff --git a/api/s39_user.py b/api/s39_user.py deleted file mode 100644 index 3b4c37d..0000000 --- a/api/s39_user.py +++ /dev/null @@ -1,37 +0,0 @@ -from .database import * -from .s0_base import * - -class User(object): - def __init__(self, input: dict[str, Any]) -> None: - self.type = 'user' - self.id = str(input['user_id']) - self.name = str(input['username']) - self.password = str(input['password']) - - def as_dict(self) -> dict[str, Any]: - return { 'type': self.type, 'id': self.id, 'name': self.name, 'password': self.password } - - def as_id_dict(self) -> dict[str, Any]: - return { 'type': self.type, 'id': self.id } - - -def get_user_schema(name: str) -> dict[str, dict[Any, Any]]: - return { 'id' : {'type': 'str' , 'optional': False , 'readonly': True }, - 'name' : {'type': 'str' , 'optional': False , 'readonly': False}, - 'password' : {'type': 'str' , 'optional': False , 'readonly': False} } - -def get_user(name: str, user_name: str) -> dict[Any, Any]: - t = try_read(name, f"select * from users where username = '{user_name}'") - if t == None: - return {} - - d = {} - d['id'] = str(t['user_id']) - d['name'] = str(t['username']) - # d['password'] = str(t['password']) - - return d - -def get_all_users(name: str) -> list[dict[Any, Any]]: - return read_all(name, "select * from users") - diff --git a/api/s40_schema.py b/api/s40_schema.py new file mode 100644 index 0000000..be21ffb --- /dev/null +++ b/api/s40_schema.py @@ -0,0 +1,30 @@ +from .database import * +from .s0_base import * + +def get_scheme_schema(name: str) -> dict[str, dict[Any, Any]]: + return { 'id' : {'type': 'str' , 'optional': False , 'readonly': True }, + 'name' : {'type': 'str' , 'optional': False , 'readonly': False}, + 'type' : {'type': 'str' , 'optional': False , 'readonly': False}, + "create_time": {'type': 'str' , 'optional': False , 'readonly': True }, + "start_time" : {'type': 'str' , 'optional': False , 'readonly': True }, + "detail" : {'type': 'str' , 'optional': False , 'readonly': True } } + + +def get_scheme(name: str, schema_name: str) -> dict[Any, Any]: + t = try_read(name, f"select * from scheme_list where scheme_name = '{schema_name}'") + if t == None: + return {} + + d = {} + d['id'] = str(t['scheme_id']) + d['name'] = str(t['scheme_name']) + d['type'] = str(t['scheme_type']) + d['create_time'] = str(t['create_time']) + d['start_time'] = str(t['start_time']) + d['detail'] = str(t['detail']) + + return d + +def get_all_schemes(name: str) -> list[dict[Any, Any]]: + return read_all(name, "select * from scheme_list") +