mirror of
https://github.com/creyD/apilog.git
synced 2026-04-15 12:50:31 +02:00
feat: added search for logs
This commit is contained in:
@@ -4,13 +4,14 @@ from creyPY.fastapi.crud import (
|
|||||||
from creyPY.fastapi.db.session import get_db
|
from creyPY.fastapi.db.session import get_db
|
||||||
from fastapi import APIRouter, Depends, Security, HTTPException
|
from fastapi import APIRouter, Depends, Security, HTTPException
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
from sqlalchemy import select
|
||||||
from app.services.auth import verify
|
from app.services.auth import verify
|
||||||
from app.schema.entry import LogIN, LogOUT
|
from app.schema.entry import LogIN, LogOUT
|
||||||
from app.models.entry import LogEntry
|
from app.models.entry import LogEntry
|
||||||
from fastapi_pagination.ext.sqlalchemy import paginate
|
from fastapi_pagination.ext.sqlalchemy import paginate
|
||||||
from creyPY.fastapi.pagination import Page
|
from creyPY.fastapi.pagination import Page
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
from pydantic.json_schema import SkipJsonSchema
|
||||||
|
|
||||||
router = APIRouter(prefix="/log", tags=["logging"])
|
router = APIRouter(prefix="/log", tags=["logging"])
|
||||||
|
|
||||||
@@ -58,11 +59,18 @@ async def get_log(
|
|||||||
|
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
async def get_logs(
|
async def get_logs(
|
||||||
|
search: str | SkipJsonSchema[None] = None,
|
||||||
sub: str = Security(verify),
|
sub: str = Security(verify),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
) -> Page[LogOUT]:
|
) -> Page[LogOUT]:
|
||||||
|
"""
|
||||||
|
Filter logs of your systems. Searching works only for author and message. Use filters for the rest.
|
||||||
|
"""
|
||||||
# add filters
|
# add filters
|
||||||
# add sorting
|
# add sorting
|
||||||
# add search
|
the_select = select(LogEntry).filter(LogEntry.created_by_id == sub)
|
||||||
the_select = db.query(LogEntry).filter_by(created_by_id=sub)
|
if search:
|
||||||
return paginate(the_select)
|
the_select = the_select.filter(
|
||||||
|
LogEntry.message.ilike(f"%{search}%") | LogEntry.author.ilike(f"%{search}%")
|
||||||
|
)
|
||||||
|
return paginate(db, the_select)
|
||||||
|
|||||||
Reference in New Issue
Block a user