feat: support only trigger webhook

This commit is contained in:
arkohut 2024-07-12 00:43:48 +08:00
parent d3d1157a4e
commit 7212a2f65b
3 changed files with 12 additions and 5 deletions

View File

@ -12,8 +12,10 @@ from tqdm import tqdm
from magika import Magika from magika import Magika
app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]}) app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]})
lib_app = typer.Typer() lib_app = typer.Typer()
plugin_app = typer.Typer() plugin_app = typer.Typer()
app.add_typer(plugin_app, name="plugin") app.add_typer(plugin_app, name="plugin")
app.add_typer(lib_app, name="lib") app.add_typer(lib_app, name="lib")

View File

@ -146,8 +146,11 @@ def add_plugin_to_library(library_id: int, plugin_id: int, db: Session):
db.refresh(library_plugin) db.refresh(library_plugin)
def get_entity_by_id(entity_id: int, db: Session) -> Entity | None: def find_entity_by_id(entity_id: int, db: Session) -> Entity | None:
return db.query(EntityModel).filter(EntityModel.id == entity_id).first() db_entity = db.query(EntityModel).filter(EntityModel.id == entity_id).first()
if db_entity is None:
return None
return Entity(**db_entity.__dict__)
def update_entity( def update_entity(

View File

@ -270,20 +270,22 @@ def get_entity_by_id_in_library(
@app.put("/entities/{entity_id}", response_model=Entity, tags=["entity"]) @app.put("/entities/{entity_id}", response_model=Entity, tags=["entity"])
async def update_entity( async def update_entity(
entity_id: int, entity_id: int,
updated_entity: UpdateEntityParam,
request: Request, request: Request,
updated_entity: UpdateEntityParam = None,
db: Session = Depends(get_db), db: Session = Depends(get_db),
trigger_webhooks_flag: bool = False, trigger_webhooks_flag: bool = False,
plugins: Annotated[List[int] | None, Query()] = None, plugins: Annotated[List[int] | None, Query()] = None,
): ):
entity = crud.get_entity_by_id(entity_id, db) entity = crud.find_entity_by_id(entity_id, db)
if entity is None: if entity is None:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, status_code=status.HTTP_404_NOT_FOUND,
detail="Entity not found", detail="Entity not found",
) )
entity = crud.update_entity(entity_id, updated_entity, db) if updated_entity:
entity = crud.update_entity(entity_id, updated_entity, db)
if trigger_webhooks_flag: if trigger_webhooks_flag:
library = crud.get_library_by_id(entity.library_id, db) library = crud.get_library_by_id(entity.library_id, db)
if library is None: if library is None: