64 lines
1.5 KiB
Python
64 lines
1.5 KiB
Python
from flask import jsonify, abort, request
|
|
|
|
from app.api import bp_product
|
|
|
|
from app.services.product_service import ProductService
|
|
|
|
@bp_product.route('/<int:id>', methods=['GET'])
|
|
def all_product_info(id: int):
|
|
result = ProductService.get_all_info(id)
|
|
|
|
if result is not None:
|
|
return jsonify(result)
|
|
else:
|
|
abort(404)
|
|
|
|
@bp_product.route('/<int:id>/name', methods=['GET'])
|
|
def get_name(id: int):
|
|
result = ProductService.get_name(id)
|
|
|
|
if result is not None:
|
|
return jsonify({"name": result})
|
|
else:
|
|
return abort(404)
|
|
|
|
@bp_product.route('/<int:id>/manufacturer', methods=['GET'])
|
|
def get_manufacturer(id: int):
|
|
result = ProductService.get_manufacturer(id)
|
|
|
|
if result is not None:
|
|
return jsonify({"name": result})
|
|
else:
|
|
return abort(404)
|
|
|
|
@bp_product.route('/<int:id>/price', methods=['GET'])
|
|
def get_price(id: int):
|
|
result = ProductService.get_price(id)
|
|
|
|
if result is not None:
|
|
return jsonify({"price": result})
|
|
else:
|
|
return abort(404)
|
|
|
|
@bp_product.route('/<int:id>/image', methods=['GET'])
|
|
def get_image(id: int):
|
|
result = ProductService.get_image(id)
|
|
|
|
if result is not None:
|
|
return jsonify({"image": result})
|
|
else:
|
|
return abort(404)
|
|
|
|
@bp_product.route('/<int:id>/image_name', methods=['GET'])
|
|
def get_image_name(id: int):
|
|
result = ProductService.get_image_name(id)
|
|
|
|
if result is not None:
|
|
return jsonify({"image_name": result})
|
|
else:
|
|
return abort(404)
|
|
|
|
@bp_product.route('/create', methods=['POST'])
|
|
def create_product_listing():
|
|
name = request.json.get('name')
|
|
|