feat(api): added controllers for api
This commit is contained in:
1 parent
b9c1a1c018
commit
90630d393f
3 files changed
+127
-23
No files matched your search
+30
-5
@@ -1,7 +1,32 @@
|
||||
from flask import Blueprint, request
|
||||
from flask import jsonify
|
||||
from db.handlers.catigory_handler import get_all_categories_with_attributes, get_category_by_id
|
||||
from flask import Blueprint
|
||||
|
||||
type = Blueprint("type", __name__)
|
||||
# Создаем blueprint для API
|
||||
api_category = Blueprint('api_category', __name__, url_prefix='/api/categories')
|
||||
|
||||
@product.route('/types', method = ['GET'])
|
||||
def GetTypes():
|
||||
return
|
||||
@api_category.route('/categories', methods=['GET'])
|
||||
def get_categories():
|
||||
"""
|
||||
Получение всех категорий с атрибутами
|
||||
GET /api/categories
|
||||
"""
|
||||
try:
|
||||
categories = get_all_categories_with_attributes()
|
||||
return jsonify(categories), 200
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@api_category.route('/categories/<int:category_id>', methods=['GET'])
|
||||
def get_category(category_id):
|
||||
"""
|
||||
Получение категории по ID
|
||||
GET /api/categories/{id}
|
||||
"""
|
||||
try:
|
||||
category = get_category_by_id(category_id)
|
||||
if category:
|
||||
return jsonify(category), 200
|
||||
return jsonify({"error": "Category not found"}), 404
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
Reference in new issue
Block a user