feat(api): Added functionality for finding by slug and api
This commit is contained in:
1 parent
5478ac8caa
commit
264b2dd6de
1 file changed
+13
-2
+13
-2
@@ -1,5 +1,5 @@
|
|||||||
from flask import jsonify, request
|
from flask import jsonify, request
|
||||||
from db.handlers.product_handler import get_products_with_filters, get_product_by_id
|
from db.handlers.product_handler import get_products_with_filters, get_product_by_id, get_product_by_slug
|
||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ def get_products():
|
|||||||
|
|
||||||
|
|
||||||
@api_product.route('/<int:product_id>', methods=['GET'], strict_slashes=False)
|
@api_product.route('/<int:product_id>', methods=['GET'], strict_slashes=False)
|
||||||
def get_product(product_id):
|
def get_product_by_id_route(product_id):
|
||||||
try:
|
try:
|
||||||
product = get_product_by_id(product_id)
|
product = get_product_by_id(product_id)
|
||||||
if product:
|
if product:
|
||||||
@@ -101,6 +101,17 @@ def get_product(product_id):
|
|||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@api_product.route('/<slug>', methods=['GET'], strict_slashes=False)
|
||||||
|
def get_product_by_slug_route(slug):
|
||||||
|
try:
|
||||||
|
product = get_product_by_slug(slug)
|
||||||
|
if product:
|
||||||
|
return jsonify(product), 200
|
||||||
|
return jsonify({"error": "Product not found"}), 404
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
@api_product.route('/fetchById', methods=['GET'], strict_slashes=False)
|
@api_product.route('/fetchById', methods=['GET'], strict_slashes=False)
|
||||||
def get_product_by_id_param():
|
def get_product_by_id_param():
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in new issue
Block a user