Files
KCGL/inventory-backend/app/api/v1/inbound/product.py

50 lines
1.9 KiB
Python

from flask import Blueprint, request, jsonify
# 引用更名后的服务
from app.services.inbound.product_service import ProductInboundService
import traceback
# 蓝图命名改为 inbound_product_bp
inbound_product_bp = Blueprint('inbound_product', __name__)
@inbound_product_bp.route('/search-base', methods=['GET'])
def search_base():
try:
data = ProductInboundService.search_base_material(request.args.get('keyword', ''))
return jsonify({"code": 200, "msg": "success", "data": data})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500
@inbound_product_bp.route('/list', methods=['GET'])
def get_list():
try:
page = request.args.get('page', 1, type=int)
limit = request.args.get('pageSize', 15, type=int)
keyword = request.args.get('keyword', '')
result = ProductInboundService.get_list(page, limit, keyword)
return jsonify({"code": 200, "msg": "success", "data": result})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500
@inbound_product_bp.route('/submit', methods=['POST'])
def submit():
try:
ProductInboundService.handle_inbound(request.get_json())
return jsonify({"code": 200, "msg": "入库成功"})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500
@inbound_product_bp.route('/<int:id>', methods=['PUT'])
def update(id):
try:
ProductInboundService.update_inbound(id, request.get_json())
return jsonify({"code": 200, "msg": "更新成功"})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500
@inbound_product_bp.route('/<int:id>', methods=['DELETE'])
def delete(id):
try:
ProductInboundService.delete_inbound(id)
return jsonify({"code": 200, "msg": "删除成功"})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500