From dfb247231f3a6cdb9fa7ad40b2e96d23a82a5f6c Mon Sep 17 00:00:00 2001 From: DingZQ Date: Fri, 28 Mar 2025 20:41:18 +0800 Subject: [PATCH] Refine --- api/s39_user.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 api/s39_user.py diff --git a/api/s39_user.py b/api/s39_user.py new file mode 100644 index 0000000..3b4c37d --- /dev/null +++ b/api/s39_user.py @@ -0,0 +1,37 @@ +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") +