修正git管理关系
This commit is contained in:
0
inventory-backend/app/api/__init__.py
Normal file
0
inventory-backend/app/api/__init__.py
Normal file
0
inventory-backend/app/api/errors.py
Normal file
0
inventory-backend/app/api/errors.py
Normal file
0
inventory-backend/app/api/v1/__init__.py
Normal file
0
inventory-backend/app/api/v1/__init__.py
Normal file
0
inventory-backend/app/api/v1/auth.py
Normal file
0
inventory-backend/app/api/v1/auth.py
Normal file
0
inventory-backend/app/api/v1/materials.py
Normal file
0
inventory-backend/app/api/v1/materials.py
Normal file
0
inventory-backend/app/api/v1/reports.py
Normal file
0
inventory-backend/app/api/v1/reports.py
Normal file
34
inventory-backend/app/api/v1/stocks.py
Normal file
34
inventory-backend/app/api/v1/stocks.py
Normal file
@ -0,0 +1,34 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
from app.services.stock_service import create_inbound_stock
|
||||
from app.schemas.stock_schema import StockBuySchema
|
||||
|
||||
stock_bp = Blueprint('stocks', __name__)
|
||||
|
||||
@stock_bp.route('/buy-inbound', methods=['POST'])
|
||||
def buy_inbound():
|
||||
"""
|
||||
采购入库接口
|
||||
POST /api/v1/buy-inbound
|
||||
Body: { "material_id": 1, "qty_inbound": 100, "price_unit": 10.5 ... }
|
||||
"""
|
||||
# 1. 接收 JSON 数据
|
||||
json_data = request.get_json()
|
||||
if not json_data:
|
||||
return jsonify({"message": "No input data provided"}), 400
|
||||
|
||||
# 2. 数据校验
|
||||
schema = StockBuySchema()
|
||||
try:
|
||||
# 这一步只做校验,不直接生成对象,因为我们要在 Service 里手动处理逻辑
|
||||
data = schema.load(json_data, partial=True)
|
||||
except Exception as e:
|
||||
return jsonify({"message": "Validation error", "errors": e.messages}), 422
|
||||
|
||||
# 3. 调用业务逻辑
|
||||
try:
|
||||
new_stock = create_inbound_stock(data)
|
||||
# 4. 返回成功结果
|
||||
result = schema.dump(new_stock)
|
||||
return jsonify({"message": "Inbound successful", "data": result}), 201
|
||||
except Exception as e:
|
||||
return jsonify({"message": "Internal Server Error", "error": str(e)}), 500
|
||||
0
inventory-backend/app/api/v1/transactions.py
Normal file
0
inventory-backend/app/api/v1/transactions.py
Normal file
Reference in New Issue
Block a user