feat: delete product
This commit is contained in:
parent
4bad9655be
commit
1e6aaf8436
4 changed files with 51 additions and 19 deletions
11
crud.py
11
crud.py
|
|
@ -106,6 +106,7 @@ async def get_zones(user_id: str) -> List[Zone]:
|
|||
|
||||
|
||||
async def delete_zone(zone_id: str) -> None:
|
||||
# todo: add user_id
|
||||
await db.execute("DELETE FROM nostrmarket.zones WHERE id = ?", (zone_id,))
|
||||
|
||||
|
||||
|
|
@ -236,3 +237,13 @@ async def get_products(user_id: str, stall_id: str) -> List[Product]:
|
|||
(user_id, stall_id),
|
||||
)
|
||||
return [Product.from_row(row) for row in rows]
|
||||
|
||||
|
||||
async def delete_product(user_id: str, product_id: str) -> None:
|
||||
await db.execute(
|
||||
"DELETE FROM nostrmarket.products WHERE user_id =? AND id = ?",
|
||||
(
|
||||
user_id,
|
||||
product_id,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@
|
|||
size="sm"
|
||||
color="pink"
|
||||
dense
|
||||
@click="props.row.expanded= !props.row.expanded"
|
||||
@click="deleteProduct(props.row.id)"
|
||||
icon="delete"
|
||||
/>
|
||||
</q-td>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ async function stallDetails(path) {
|
|||
],
|
||||
data: function () {
|
||||
return {
|
||||
tab: 'info',
|
||||
tab: 'products',
|
||||
stall: null,
|
||||
products: [],
|
||||
productDialog: {
|
||||
|
|
@ -271,6 +271,30 @@ async function stallDetails(path) {
|
|||
LNbits.utils.notifyApiError(error)
|
||||
}
|
||||
},
|
||||
deleteProduct: async function (productId) {
|
||||
LNbits.utils
|
||||
.confirmDialog('Are you sure you want to delete this product?')
|
||||
.onOk(async () => {
|
||||
try {
|
||||
await LNbits.api.request(
|
||||
'DELETE',
|
||||
'/nostrmarket/api/v1/product/' + productId,
|
||||
this.adminkey
|
||||
)
|
||||
this.products = _.reject(this.products, function (obj) {
|
||||
return obj.id === productId
|
||||
})
|
||||
this.$q.notify({
|
||||
type: 'positive',
|
||||
message: 'Product deleted',
|
||||
timeout: 5000
|
||||
})
|
||||
} catch (error) {
|
||||
console.warn(error)
|
||||
LNbits.utils.notifyApiError(error)
|
||||
}
|
||||
})
|
||||
},
|
||||
showNewProductDialog: async function () {
|
||||
this.productDialog.showDialog = true
|
||||
}
|
||||
|
|
|
|||
31
views_api.py
31
views_api.py
|
|
@ -20,6 +20,7 @@ from .crud import (
|
|||
create_product,
|
||||
create_stall,
|
||||
create_zone,
|
||||
delete_product,
|
||||
delete_stall,
|
||||
delete_zone,
|
||||
get_merchant_for_user,
|
||||
|
|
@ -338,23 +339,19 @@ async def api_get_product(
|
|||
)
|
||||
|
||||
|
||||
# @market_ext.delete("/api/v1/products/{product_id}")
|
||||
# async def api_market_products_delete(
|
||||
# product_id, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||
# ):
|
||||
# product = await get_market_product(product_id)
|
||||
|
||||
# if not product:
|
||||
# return {"message": "Product does not exist."}
|
||||
|
||||
# stall = await get_market_stall(product.stall)
|
||||
# assert stall
|
||||
|
||||
# if stall.wallet != wallet.wallet.id:
|
||||
# return {"message": "Not your Market."}
|
||||
|
||||
# await delete_market_product(product_id)
|
||||
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
@nostrmarket_ext.delete("/api/v1/product/{product_id}")
|
||||
async def api_delete_product(
|
||||
product_id: str,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
):
|
||||
try:
|
||||
await delete_product(wallet.wallet.user, product_id)
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail="Cannot delete product",
|
||||
)
|
||||
|
||||
|
||||
######################################## OTHER ########################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue