当代数据库管理系统课程实验二
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

64 lignes
2.2 KiB

  1. from flask import Blueprint
  2. from flask import request
  3. from flask import jsonify
  4. from be.model.buyer import Buyer
  5. bp_buyer = Blueprint("buyer",__name__,url_prefix="/buyer")
  6. @bp_buyer.route("/new_order", methods=["POST"])
  7. def new_order():
  8. user_id: str = request.json.get("user_id")
  9. store_id: str = request.json.get("store_id")
  10. books: [] = request.json.get("books")
  11. id_and_count = []
  12. for book in books:
  13. book_id = book.get("id")
  14. count = book.get("count")
  15. id_and_count.append((book_id, count))
  16. b = Buyer()
  17. code, message, order_id = b.new_order(user_id, store_id, id_and_count)
  18. return jsonify({"message": message, "order_id": order_id}), code
  19. @bp_buyer.route("/payment", methods=["POST"])
  20. def payment():
  21. user_id: str = request.json.get("user_id")
  22. order_id: str = request.json.get("order_id")
  23. password: str = request.json.get("password")
  24. b = Buyer()
  25. code, message = b.payment(user_id, password, order_id)
  26. return jsonify({"message": message}), code
  27. @bp_buyer.route("/add_funds", methods=["POST"])
  28. def add_funds():
  29. user_id = request.json.get("user_id")
  30. password = request.json.get("password")
  31. add_value = request.json.get("add_value")
  32. b = Buyer()
  33. code, message = b.add_funds(user_id, password, add_value)
  34. return jsonify({"message": message}), code
  35. @bp_buyer.route("/take_over", methods=["POST"])
  36. def take_over():
  37. user_id = request.json.get("user_id")
  38. order_id = request.json.get("order_id")
  39. b = Buyer()
  40. code, message = b.take_over(user_id, order_id)
  41. return jsonify({"message": message}), code
  42. @bp_buyer.route("/order_cancel", methods=["POST"])
  43. def order_cancel():
  44. user_id = request.json.get("user_id")
  45. order_id = request.json.get("order_id")
  46. b = Buyer()
  47. code, message = b.order_cancel(user_id, order_id)
  48. return jsonify({"message": message}), code
  49. @bp_buyer.route("/history_order", methods=["POST"])
  50. def history_order():
  51. user_id = request.json.get("user_id")
  52. b = Buyer()
  53. code, message, order_ids = b.history_order(user_id)
  54. return jsonify({"message": message,"order_id": order_ids}), code