mirror of
https://github.com/tcsenpai/pensieve.git
synced 2025-06-07 03:35:24 +00:00
feat: create and bind plugin to library
This commit is contained in:
parent
121c8c51b1
commit
ec03b818f3
@ -1,6 +1,6 @@
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from .schemas import Library, NewLibraryParam, Folder, NewEntityParam, Entity
|
from .schemas import Library, NewLibraryParam, Folder, NewEntityParam, Entity, Plugin, NewPluginParam
|
||||||
from .models import LibraryModel, FolderModel, EntityModel, EntityModel
|
from .models import LibraryModel, FolderModel, EntityModel, EntityModel, PluginModel, LibraryPluginModel
|
||||||
|
|
||||||
|
|
||||||
def get_library_by_id(library_id: int, db: Session) -> Library | None:
|
def get_library_by_id(library_id: int, db: Session) -> Library | None:
|
||||||
@ -35,3 +35,18 @@ def create_entity(library_id: int, entity: NewEntityParam, db: Session) -> Entit
|
|||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(db_entity)
|
db.refresh(db_entity)
|
||||||
return db_entity
|
return db_entity
|
||||||
|
|
||||||
|
|
||||||
|
def create_plugin(newPlugin: NewPluginParam, db: Session) -> Plugin:
|
||||||
|
db_plugin = PluginModel(**newPlugin.model_dump(mode='json'))
|
||||||
|
db.add(db_plugin)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(db_plugin)
|
||||||
|
return db_plugin
|
||||||
|
|
||||||
|
|
||||||
|
def add_plugin_to_library(library_id: int, plugin_id: int, db: Session):
|
||||||
|
library_plugin = LibraryPluginModel(library_id=library_id, plugin_id=plugin_id)
|
||||||
|
db.add(library_plugin)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(library_plugin)
|
||||||
|
@ -6,7 +6,7 @@ from sqlalchemy.orm import sessionmaker
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from .config import get_database_path
|
from .config import get_database_path
|
||||||
from .crud import get_library_by_id, create_library, create_entity
|
from .crud import get_library_by_id, create_library, create_entity, create_plugin, add_plugin_to_library
|
||||||
from .schemas import (
|
from .schemas import (
|
||||||
Library,
|
Library,
|
||||||
Folder,
|
Folder,
|
||||||
@ -64,22 +64,16 @@ def new_entity(
|
|||||||
|
|
||||||
|
|
||||||
@app.post("/plugins", response_model=Plugin)
|
@app.post("/plugins", response_model=Plugin)
|
||||||
def new_plugin(plugin: NewPluginParam, db: Session = Depends(get_db)):
|
def new_plugin(new_plugin: NewPluginParam, db: Session = Depends(get_db)):
|
||||||
db_plugin = Plugin(**plugin.model_dump())
|
plugin = create_plugin(new_plugin, db)
|
||||||
db.add(db_plugin)
|
return plugin
|
||||||
db.commit()
|
|
||||||
db.refresh(db_plugin)
|
|
||||||
return db_plugin
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/libraries/{library_id}/plugins", status_code=status.HTTP_204_NO_CONTENT)
|
@app.post("/libraries/{library_id}/plugins", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
def add_library_plugin(
|
def add_library_plugin(
|
||||||
library_id: int, plugin: NewLibraryPluginParam, db: Session = Depends(get_db)
|
library_id: int, new_plugin: NewLibraryPluginParam, db: Session = Depends(get_db)
|
||||||
):
|
):
|
||||||
db_library_plugin = LibrayPlugin(library_id=library_id, plugin_id=plugin.plugin_id)
|
add_plugin_to_library(library_id, new_plugin.plugin_id, db)
|
||||||
db.add(db_library_plugin)
|
|
||||||
db.commit()
|
|
||||||
db.refresh(db_library_plugin)
|
|
||||||
|
|
||||||
|
|
||||||
def run_server():
|
def run_server():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user