2024-03-05 16:01:26 +01:00
|
|
|
from flask import jsonify, abort, request
|
|
|
|
|
|
|
|
from app.api import bp_product
|
|
|
|
|
|
|
|
from app.services.product_service import ProductService
|
|
|
|
|
2024-03-10 17:11:26 +01:00
|
|
|
@bp_product.route('/get', methods=['GET'])
|
|
|
|
def get_products():
|
|
|
|
page = request.args.get('page', default=0, type=int)
|
|
|
|
|
|
|
|
if page < 0:
|
|
|
|
return abort(400)
|
|
|
|
|
|
|
|
result, status_code = ProductService.get_products(page)
|
|
|
|
|
|
|
|
return result, status_code
|
|
|
|
|
2024-03-05 16:01:26 +01:00
|
|
|
@bp_product.route('/<int:id>', methods=['GET'])
|
2024-03-08 14:05:22 +01:00
|
|
|
def get_product_info(id: int):
|
|
|
|
fields = ['name', 'price', 'image', 'image_name', 'seller']
|
2024-03-05 16:01:26 +01:00
|
|
|
|
2024-03-08 14:05:22 +01:00
|
|
|
fields_param = request.args.get('fields')
|
2024-03-10 21:19:34 +01:00
|
|
|
|
|
|
|
fields_param_list = fields_param.split(',') if fields_param else fields
|
|
|
|
|
|
|
|
common_fields = list(set(fields) & set(fields_param_list))
|
2024-03-08 14:05:22 +01:00
|
|
|
|
2024-03-10 21:19:34 +01:00
|
|
|
result, status_code = ProductService.get_product_info(common_fields, id)
|
2024-03-05 16:01:26 +01:00
|
|
|
|
2024-03-10 21:19:34 +01:00
|
|
|
return result, status_code
|
2024-03-05 16:01:26 +01:00
|
|
|
|
|
|
|
@bp_product.route('/create', methods=['POST'])
|
|
|
|
def create_product_listing():
|
2024-03-07 22:16:29 +01:00
|
|
|
name = request.json.get('name')
|
|
|
|
|