Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 15cc48cd40 |
28
backend/app/core/operation.py
Normal file
28
backend/app/core/operation.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
from app.db.crud import create_operationlog
|
||||||
|
from app.db.schemas import OperationCreate
|
||||||
|
from fastapi.encoders import jsonable_encoder
|
||||||
|
|
||||||
|
def log_operation(operation):
|
||||||
|
def decorator(func):
|
||||||
|
@wraps(func)
|
||||||
|
async def wrapper(*args,**kwargs):
|
||||||
|
db = kwargs.get('db')
|
||||||
|
request = kwargs.get('request')
|
||||||
|
result = await func(*args,**kwargs)
|
||||||
|
detial = f"Request: {request.method} {request.url}\
|
||||||
|
Request Headers: {request.headers}\
|
||||||
|
Request Body: {request.body()}\
|
||||||
|
Result: {jsonable_encoder(result,exclude_unset=True)}"
|
||||||
|
function = func.__name__
|
||||||
|
db_operation = OperationCreate(tenantid ="t",
|
||||||
|
domainurl="d",
|
||||||
|
userid=3,
|
||||||
|
operation=operation,
|
||||||
|
function=function,
|
||||||
|
detail=detial)
|
||||||
|
create_operationlog(db,db_operation)
|
||||||
|
return result
|
||||||
|
return wrapper
|
||||||
|
return decorator
|
||||||
@@ -364,4 +364,18 @@ def create_log(db: Session, error:schemas.ErrorCreate):
|
|||||||
|
|
||||||
def get_kintoneformat(db: Session):
|
def get_kintoneformat(db: Session):
|
||||||
formats = db.query(models.KintoneFormat).order_by(models.KintoneFormat.id).all()
|
formats = db.query(models.KintoneFormat).order_by(models.KintoneFormat.id).all()
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
|
def create_operationlog(db: Session, log: schemas.OperationCreate):
|
||||||
|
db_log = models.OperationLog(
|
||||||
|
tenantid=log.tenantid,
|
||||||
|
domainurl=log.domainurl,
|
||||||
|
userid = log.userid,
|
||||||
|
operation = log.operation,
|
||||||
|
function = log.function,
|
||||||
|
detail = log.detail
|
||||||
|
)
|
||||||
|
db.add(db_log)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(db_log)
|
||||||
|
return db_log
|
||||||
@@ -162,4 +162,12 @@ class Event(Base):
|
|||||||
class ErrorCreate(BaseModel):
|
class ErrorCreate(BaseModel):
|
||||||
title:str
|
title:str
|
||||||
location:str
|
location:str
|
||||||
content:str
|
content:str
|
||||||
|
|
||||||
|
class OperationCreate(BaseModel):
|
||||||
|
tenantid:str
|
||||||
|
domainurl:str
|
||||||
|
userid:int
|
||||||
|
operation:str
|
||||||
|
function:str
|
||||||
|
detail:str
|
||||||
|
|||||||
Reference in New Issue
Block a user