38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
from apps.shop.models import Product as ProductModel
|
|
from rest_framework import exceptions
|
|
|
|
|
|
def retrieve_product(product_id: int, workspace_uuid: str) -> ProductModel:
|
|
try:
|
|
product_obj = ProductModel.objects.get(id=product_id, sys_ws__uuid=workspace_uuid)
|
|
return product_obj
|
|
except Exception as exp:
|
|
message = f'Error Retrieve Product: {exp}'
|
|
raise exceptions.ValidationError({'error': message})
|
|
|
|
|
|
def list_product(workspace_uuid: str) -> ProductModel:
|
|
try:
|
|
product_category_obj = ProductModel.objects.filter(sys_ws__uuid=workspace_uuid)
|
|
return product_category_obj
|
|
except Exception as exp:
|
|
message = f'Error Fetching List Product: {exp}'
|
|
raise exceptions.ValidationError({'error': message})
|
|
|
|
|
|
def list_product_by_category(workspace_uuid: str, category_id: int) -> ProductModel:
|
|
try:
|
|
product_category_obj = ProductModel.objects.filter(sys_ws__uuid=workspace_uuid, category_id=category_id)
|
|
return product_category_obj
|
|
except Exception as exp:
|
|
message = f'Error Fetching List Product by category: {exp}'
|
|
raise exceptions.ValidationError({'error': message})
|
|
|
|
|
|
def count_product_in_category(workspace_uuid: str, category_id: int) -> int:
|
|
try:
|
|
count_product = ProductModel.objects.filter(sys_ws__uuid=workspace_uuid, category_id=category_id).count()
|
|
return count_product
|
|
except Exception as exp:
|
|
message = f'Error Couting Product in category: {exp}'
|
|
raise exceptions.ValidationError({'error': message}) |