Files
copp/server/api-data-base/router.py
2025-05-25 23:38:58 +05:00

75 lines
2.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from fastapi import APIRouter, Query, HTTPException
from data_base.requests import Request
from fastapi.responses import FileResponse
import model_messege as mm
import bcrypt
import asyncio
router = APIRouter(prefix="/api-data-base")
#table_name: mm.TableName = Query(...)
def check_password(input_password, hashed_password) -> bool:
"""Проверка пароля"""
return bcrypt.checkpw(input_password.encode('utf-8'), hashed_password.encode('utf-8'))
@router.get("/load_preset")
async def load_preset():
"""Загрузка пресета"""
await Request.load_preset()
return {"messege":"пресет загружен"}
@router.get("/start")
async def create_tables():
"""Создание таблиц"""
await Request.craete_all_table()
return {"message": f"все таблицы созданы"}
@router.post("/login")
async def login(auth_request: mm.Login):#auth_request: mm.Login
"""Авторизация"""
user = await Request.login(auth_request=auth_request)
if user == None:#если пользователь не найден
return {
"id":0,
"name_poo":"",
"inn":"",
"mail":"",
"drop_table":""
}
if check_password(input_password=auth_request.password, hashed_password=user.password):#если пароль верный
#data = await Request.select_drop_down_list()
return {
"id":user.id,
"name_poo":user.name_poo,
"inn":user.inn,
"mail":user.mail
#"drop_table": data
}
@router.post("/add_column")
async def add_column(new_column: mm.column_table):
"""Добавление колонки"""
await Request.add_column(table_name=new_column.table_name.name, column_name=new_column.column_name, data_type=new_column.data_type.name)
return {"message":"колонка добавлена"}
@router.post("/drop_column")
async def drop_column(new_column: mm.column_table):
"""Удаление колонки"""
await Request.drop_column(table_name=new_column.table_name.name, column_name=new_column.column_name)
return {"message":"колонка удалена"}
@router.post("/get_name_column")
async def get_name_column(table_name: mm.TableName):
"""Получение имен колонок"""
return await Request.get_table_columns(table_name=table_name.name)
@router.post("/insert_table")
async def insert_table(data:dict):
"""Добавление записи"""
return await Request.insert_table(data=data)
@router.post("/select_rows_with_filter")
async def select_rows_with_filter(value:str):
"""Выборка с фильтром"""
return await Request.select_rows_with_filter(value=value)