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:
|
async def delete_zone(zone_id: str) -> None:
|
||||||
|
# todo: add user_id
|
||||||
await db.execute("DELETE FROM nostrmarket.zones WHERE id = ?", (zone_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),
|
(user_id, stall_id),
|
||||||
)
|
)
|
||||||
return [Product.from_row(row) for row in rows]
|
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"
|
size="sm"
|
||||||
color="pink"
|
color="pink"
|
||||||
dense
|
dense
|
||||||
@click="props.row.expanded= !props.row.expanded"
|
@click="deleteProduct(props.row.id)"
|
||||||
icon="delete"
|
icon="delete"
|
||||||
/>
|
/>
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ async function stallDetails(path) {
|
||||||
],
|
],
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
tab: 'info',
|
tab: 'products',
|
||||||
stall: null,
|
stall: null,
|
||||||
products: [],
|
products: [],
|
||||||
productDialog: {
|
productDialog: {
|
||||||
|
|
@ -271,6 +271,30 @@ async function stallDetails(path) {
|
||||||
LNbits.utils.notifyApiError(error)
|
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 () {
|
showNewProductDialog: async function () {
|
||||||
this.productDialog.showDialog = true
|
this.productDialog.showDialog = true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
views_api.py
31
views_api.py
|
|
@ -20,6 +20,7 @@ from .crud import (
|
||||||
create_product,
|
create_product,
|
||||||
create_stall,
|
create_stall,
|
||||||
create_zone,
|
create_zone,
|
||||||
|
delete_product,
|
||||||
delete_stall,
|
delete_stall,
|
||||||
delete_zone,
|
delete_zone,
|
||||||
get_merchant_for_user,
|
get_merchant_for_user,
|
||||||
|
|
@ -338,23 +339,19 @@ async def api_get_product(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# @market_ext.delete("/api/v1/products/{product_id}")
|
@nostrmarket_ext.delete("/api/v1/product/{product_id}")
|
||||||
# async def api_market_products_delete(
|
async def api_delete_product(
|
||||||
# product_id, wallet: WalletTypeInfo = Depends(require_admin_key)
|
product_id: str,
|
||||||
# ):
|
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||||
# product = await get_market_product(product_id)
|
):
|
||||||
|
try:
|
||||||
# if not product:
|
await delete_product(wallet.wallet.user, product_id)
|
||||||
# return {"message": "Product does not exist."}
|
except Exception as ex:
|
||||||
|
logger.warning(ex)
|
||||||
# stall = await get_market_stall(product.stall)
|
raise HTTPException(
|
||||||
# assert stall
|
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
detail="Cannot delete product",
|
||||||
# if stall.wallet != wallet.wallet.id:
|
)
|
||||||
# return {"message": "Not your Market."}
|
|
||||||
|
|
||||||
# await delete_market_product(product_id)
|
|
||||||
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
|
||||||
|
|
||||||
|
|
||||||
######################################## OTHER ########################################
|
######################################## OTHER ########################################
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue