mirror of
https://github.com/tcsenpai/pensieve.git
synced 2025-06-07 03:35:24 +00:00
feat(library): get library by id
This commit is contained in:
parent
54091c94d4
commit
abf04fe74e
@ -52,5 +52,16 @@ def add(name: str, folders: List[str]):
|
|||||||
print(f"Failed to create library: {response.status_code} - {response.text}")
|
print(f"Failed to create library: {response.status_code} - {response.text}")
|
||||||
|
|
||||||
|
|
||||||
|
@lib_app.command("show")
|
||||||
|
def show(library_id: int):
|
||||||
|
response = httpx.get(f"http://localhost:8080/libraries/{library_id}")
|
||||||
|
if response.status_code == 200:
|
||||||
|
library = response.json()
|
||||||
|
display_libraries([library])
|
||||||
|
else:
|
||||||
|
print(f"Failed to retrieve library: {response.status_code} - {response.text}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app()
|
app()
|
||||||
|
@ -51,6 +51,14 @@ def list_libraries(db: Session = Depends(get_db)):
|
|||||||
return libraries
|
return libraries
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/libraries/{library_id}", response_model=Library)
|
||||||
|
def get_library_by_id(library_id: int, db: Session = Depends(get_db)):
|
||||||
|
library = crud.get_library_by_id(library_id, db)
|
||||||
|
if library is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Library not found")
|
||||||
|
return library
|
||||||
|
|
||||||
|
|
||||||
@app.post("/libraries/{library_id}/folders", response_model=Folder)
|
@app.post("/libraries/{library_id}/folders", response_model=Folder)
|
||||||
def new_folder(
|
def new_folder(
|
||||||
library_id: int,
|
library_id: int,
|
||||||
@ -75,7 +83,7 @@ def new_entity(
|
|||||||
library = crud.get_library_by_id(library_id, db)
|
library = crud.get_library_by_id(library_id, db)
|
||||||
if library is None:
|
if library is None:
|
||||||
raise HTTPException(status_code=404, detail="Library not found")
|
raise HTTPException(status_code=404, detail="Library not found")
|
||||||
|
|
||||||
entity = crud.create_entity(library_id, new_entity, db)
|
entity = crud.create_entity(library_id, new_entity, db)
|
||||||
return entity
|
return entity
|
||||||
|
|
||||||
@ -89,7 +97,9 @@ def get_entity_by_id(library_id: int, entity_id: int, db: Session = Depends(get_
|
|||||||
|
|
||||||
|
|
||||||
@app.get("/libraries/{library_id}/entities", response_model=Entity)
|
@app.get("/libraries/{library_id}/entities", response_model=Entity)
|
||||||
def get_entity_by_filepath(library_id: int, filepath: str, db: Session = Depends(get_db)):
|
def get_entity_by_filepath(
|
||||||
|
library_id: int, filepath: str, db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
entity = crud.get_entity_by_filepath(filepath, db)
|
entity = crud.get_entity_by_filepath(filepath, db)
|
||||||
if entity is None or entity.library_id != library_id:
|
if entity is None or entity.library_id != library_id:
|
||||||
raise HTTPException(status_code=404, detail="Entity not found")
|
raise HTTPException(status_code=404, detail="Entity not found")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user