Refine
This commit is contained in:
@@ -162,4 +162,6 @@ from .s35_vd_gen import generate_virtual_district
|
||||
|
||||
from .s36_wda_cal import calculate_demand_to_nodes, calculate_demand_to_region, calculate_demand_to_network
|
||||
|
||||
from .s38_scada_info import get_scada_info_schema, get_scada_info, get_all_scada_info
|
||||
from .s38_scada_info import get_scada_info_schema, get_scada_info, get_all_scada_info
|
||||
|
||||
from .s39_user import get_user_schema, get_user, get_all_users
|
||||
|
||||
@@ -1,3 +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['id'])
|
||||
self.name = float(input['name'])
|
||||
self.password = float(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[str, 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[str, Any]:
|
||||
t = try_read(name, f"select * from users where name = '{user_name}'")
|
||||
if t == None:
|
||||
return {}
|
||||
|
||||
d = {}
|
||||
d['id'] = str(t['id'])
|
||||
d['name'] = str(t['name'])
|
||||
# d['password'] = str(t['password'])
|
||||
|
||||
return d
|
||||
|
||||
def get_all_users(name: str) -> list[dict[str, Any]]:
|
||||
return read_all(name, "select * from users")
|
||||
|
||||
|
||||
31
main.py
31
main.py
@@ -2041,6 +2041,37 @@ async def fastapi_get_all_scada_info(network: str) -> list[dict[str, float]]:
|
||||
return get_all_scada_info(network)
|
||||
|
||||
|
||||
###########################################################
|
||||
# user 39
|
||||
###########################################################
|
||||
@app.get('/getuserschema/')
|
||||
async def fastapi_get_user_schema(network: str) -> dict[str, dict[str, Any]]:
|
||||
return get_user_schema(network)
|
||||
|
||||
@app.get('/getuser/')
|
||||
async def fastapi_get_user(network: str, user_name: str) -> dict[str, float]:
|
||||
return get_user(network, user_name)
|
||||
|
||||
@app.get('/getallusers/')
|
||||
async def fastapi_get_all_users(network: str) -> list[dict[str, float]]:
|
||||
return get_all_users(network)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# inp file
|
||||
@app.post("/uploadinp/", status_code=status.HTTP_200_OK)
|
||||
async def fastapi_upload_inp(afile: bytes, name: str ):
|
||||
|
||||
@@ -1269,4 +1269,11 @@ def get_all_scada_info(name: str) -> list[dict[str, Any]]:
|
||||
############################################################
|
||||
# 39 users
|
||||
############################################################
|
||||
def get_user_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
return api.get_user_schema(name)
|
||||
|
||||
def get_user(name: str, user_name: str) -> dict[str, Any]:
|
||||
return api.get_user(name, user_name=user_name)
|
||||
|
||||
def get_all_users(name: str) -> list[dict[str, Any]]:
|
||||
return api.get_all_users(name)
|
||||
|
||||
Reference in New Issue
Block a user