Refine
This commit is contained in:
@@ -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")
|
|
||||||
|
|
||||||
30
api/s40_schema.py
Normal file
30
api/s40_schema.py
Normal file
@@ -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")
|
||||||
|
|
||||||
Reference in New Issue
Block a user