feat(handlers): Add handler for get all products by id

This commit is contained in:
Black_Raven committed 2026-04-13 14:20:00 +03:00
1 parent 8204bbf9bd
commit 78c5fc39b0
1 file changed
+27
+27
View File
@@ -1,6 +1,7 @@
import sqlite3
from typing import List, Dict, Any, Optional, Tuple
from loguru import logger as log
from db.DBDataUtils import get_products_by_page, get_total_products_pages
def get_products_with_filters(
category_id: int,
@@ -268,3 +269,29 @@ def generate_full_description(row: sqlite3.Row) -> str:
parts.append(f"Цвет: {row['color']}")
return " ".join(parts)
def get_product_list(page=1, limit=100, category_id=None):
"""
Получить список товаров с пагинацией.
Возвращает список словарей с полями id, full_name, description.
"""
conn = None
try:
import sqlite3
conn = sqlite3.connect('pipe_store.db')
conn.row_factory = sqlite3.Row
offset = (page - 1) * limit
rows = get_products_by_page(conn, page, limit, category_id)
products = []
for row in rows:
products.append({
'id': row['id'],
'full_name': row['full_name'],
'description': row['description']
})
return products
finally:
if conn:
conn.close()