fix filter
This commit is contained in:
@@ -227,7 +227,22 @@ class OfficeDashboardService(BaseService):
|
||||
|
||||
@staticmethod
|
||||
def get_office_product_templates(filters):
|
||||
templates = ProductsTemplates.get_template_for_office(filters)
|
||||
|
||||
# Extract filters
|
||||
product_id = filters.get('product_id')
|
||||
provision_name = filters.get('provision_name')
|
||||
|
||||
# Extract pagination parameters
|
||||
page = int(filters.get('page', 1))
|
||||
limit = int(filters.get('limit', 20))
|
||||
|
||||
# Ensure page and limit are valid
|
||||
if page < 1:
|
||||
page = 1
|
||||
if limit < 1 or limit > 100:
|
||||
limit = 20
|
||||
|
||||
templates = ProductsTemplates.get_template_for_office(product_id, provision_name, page, limit)
|
||||
templates_data = []
|
||||
if templates:
|
||||
for t in templates:
|
||||
@@ -236,10 +251,12 @@ class OfficeDashboardService(BaseService):
|
||||
'uid': t.uid,
|
||||
'product_id': t.product_id,
|
||||
'provision_name': t.provision_name,
|
||||
'status': t.status,
|
||||
'added': t.added.isoformat() if t.added else None,
|
||||
})
|
||||
templates_result = {
|
||||
"templates": templates_data,
|
||||
"product_options": []
|
||||
}
|
||||
|
||||
return templates_result
|
||||
|
||||
@@ -3,6 +3,10 @@ from app.extensions import db
|
||||
from app.models.charge import Charge
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
import logging
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProductsTemplates(db.Model):
|
||||
@@ -27,8 +31,24 @@ class ProductsTemplates(db.Model):
|
||||
return templates
|
||||
|
||||
@classmethod
|
||||
def get_template_for_office(cls, filters):
|
||||
templates = cls.query.all()
|
||||
def get_template_for_office(cls, product_id=None, provision_name=None, page=1, limit=20):
|
||||
|
||||
query = cls.query
|
||||
logger.info(f"Get Templates for Office Product")
|
||||
|
||||
if product_id:
|
||||
query = query.filter(cls.product_id == product_id)
|
||||
|
||||
if provision_name:
|
||||
query = query.filter(cls.provision_name == provision_name)
|
||||
|
||||
# Order by created_at descending (newest first)
|
||||
query = query.order_by(cls.added.desc())
|
||||
|
||||
# Get total count before pagination
|
||||
total_count = query.count()
|
||||
|
||||
templates = query.all()
|
||||
|
||||
if not templates:
|
||||
raise ValueError(f"Templates not found")
|
||||
|
||||
Reference in New Issue
Block a user