Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More text editor work #34

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
11 changes: 11 additions & 0 deletions hippoclient/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from . import helper
from .core import ClientSettings, MultiCache
from .textedit import edit_product

CLIENT: sc.Client
CACHE: MultiCache
Expand Down Expand Up @@ -105,6 +106,16 @@ def product_uncache(id: str):
CONSOLE.print(f"Uncached product {id}")


@product_app.command("edit")
def product_edit(id: str):
"""
Edit a product by its ID.
"""
global CLIENT

edit_product(client=CLIENT, id=id)


@collection_app.command("read")
def collection_read(id: str):
"""
Expand Down
49 changes: 48 additions & 1 deletion hippoclient/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from hippometa.simple import SimpleMetadata
from hipposerve.api.models.product import ReadProductResponse
from hipposerve.database import ProductMetadata
from hipposerve.service.product import PostUploadFile
from hipposerve.service.product import PostUploadFile, PreUploadFile

from .core import Client, MultiCache, console

Expand Down Expand Up @@ -195,6 +195,53 @@ def read(client: Client, id: str) -> ProductMetadata:
return model


def update(
client: Client,
id: str,
name: str | None,
description: str | None,
level: int,
metadata: ALL_METADATA_TYPE | None,
new_sources: list[PreUploadFile] = [],
replace_sources: list[PreUploadFile] = [],
drop_sources: list[str] = [],
) -> bool:
"""
Update a product in hippo.

Arguments
----------
client: Client
The client to use for interacting with the hippo API.
id : str
The ID of the product to update.
name : str
The new name of the product.
description : str
The new description of the product.
"""

response = client.post(
f"/product/{id}/update",
json={
"name": name,
"description": description,
"level": level,
"metadata": metadata,
"new_sources": new_sources,
"replace_sources": replace_sources,
"drop_sources": drop_sources,
},
)

response.raise_for_status()

if client.verbose:
console.print(f"Successfully updated product {id}.", style="bold green")

return


def delete(client: Client, id: str) -> bool:
"""
Delete a product from hippo.
Expand Down
Loading