Browse Source

seller路由实现与测试

master
杨舜 1 year ago
parent
commit
62794dcb17
8 changed files with 121 additions and 2 deletions
  1. BIN
      figure_require/addbook_test.png
  2. BIN
      figure_require/addstocklevel_test.png
  3. BIN
      figure_require/creatstore_test.png
  4. BIN
      modified/be/model/__pycache__/seller.cpython-38.pyc
  5. +77
    -0
      modified/be/model/seller.py
  6. BIN
      modified/be/view/__pycache__/seller.cpython-38.pyc
  7. +37
    -0
      modified/be/view/seller.py
  8. +7
    -2
      report.md

BIN
figure_require/addbook_test.png View File

Before After
Width: 936  |  Height: 638  |  Size: 56 KiB

BIN
figure_require/addstocklevel_test.png View File

Before After
Width: 912  |  Height: 605  |  Size: 49 KiB

BIN
figure_require/creatstore_test.png View File

Before After
Width: 896  |  Height: 562  |  Size: 46 KiB

BIN
modified/be/model/__pycache__/seller.cpython-38.pyc View File


+ 77
- 0
modified/be/model/seller.py View File

@ -0,0 +1,77 @@
from sqlalchemy.exc import SQLAlchemyError
from model import error
from model import postgreSQLORM
from model import db_conn
from sqlalchemy import and_
class Seller(db_conn.DBConn):
def __init__(self):
db_conn.DBConn.__init__(self)
def add_book(self, user_id: str, store_id: str, book_id: str, book_json_str: str, stock_level: int):
try:
if not self.user_id_exist(user_id):
return error.error_non_exist_user_id(user_id)
if not self.store_id_exist(store_id):
return error.error_non_exist_store_id(store_id)
if self.book_id_exist(store_id, book_id):
return error.error_exist_book_id(book_id)
# self.session.query(postgreSQLORM.Store_Book).
new_book = postgreSQLORM.Store_Book(store_id=store_id,book_id=book_id,book_info=book_json_str,stock_level=stock_level)
self.session.add(new_book)
# self.conn.execute("INSERT into store(store_id, book_id, book_info, stock_level)"
# "VALUES (?, ?, ?, ?)", (store_id, book_id, book_json_str, stock_level))
# self.conn.commit()
self.session.query(postgreSQLORM.Store).filter_by(store_id=store_id).update({'stock_level':postgreSQLORM.Store.stock_level+1})
self.session.commit()
except SQLAlchemyError as e:
return 528, "{}".format(str(e))
except BaseException as e:
return 530, "{}".format(str(e))
return 200, "ok"
def add_stock_level(self, user_id: str, store_id: str, book_id: str, add_stock_level: int):
try:
if not self.user_id_exist(user_id):
return error.error_non_exist_user_id(user_id)
if not self.store_id_exist(store_id):
return error.error_non_exist_store_id(store_id)
if not self.book_id_exist(store_id, book_id):
return error.error_non_exist_book_id(book_id)
self.session.query(postgreSQLORM.Store).filter_by(store_id=store_id).update({'stock_level':add_stock_level})
self.session.query(postgreSQLORM.Store_Book).filter_by(store_id=store_id,book_id=book_id).update({'stock_level':add_stock_level})
# self.conn.execute("UPDATE store SET stock_level = stock_level + ? "
# "WHERE store_id = ? AND book_id = ?", (add_stock_level, store_id, book_id))
# self.conn.commit()
self.session.commit()
except SQLAlchemyError as e:
return 528, "{}".format(str(e))
except BaseException as e:
return 530, "{}".format(str(e))
return 200, "ok"
def create_store(self, user_id: str, store_id: str) -> (int, str):
try:
if not self.user_id_exist(user_id):
return error.error_non_exist_user_id(user_id)
if self.store_id_exist(store_id):
return error.error_exist_store_id(store_id)
new_store = postgreSQLORM.Store(store_id=store_id,stock_level=0)
new_user_store = postgreSQLORM.User_Store(fk_user_id=user_id,fk_store_id=store_id)
self.session.add(new_store)
# self.session.commit()
self.session.add(new_user_store)
# self.conn.execute("INSERT into user_store(store_id, user_id)"
# "VALUES (?, ?)", (store_id, user_id))
# self.conn.commit()
self.session.commit()
# print('touch1')
except SQLAlchemyError as e:
# print('touch2')
return 528, "{}".format(str(e))
except BaseException as e:
# print('touch3')
return 530, "{}".format(str(e))
return 200, "ok"

BIN
modified/be/view/__pycache__/seller.cpython-38.pyc View File


+ 37
- 0
modified/be/view/seller.py View File

@ -1,4 +1,41 @@
from flask import Blueprint
from flask import request
from flask import jsonify
from model import seller
import json
bp_seller = Blueprint("seller",__name__,url_prefix="/seller")
@bp_seller.route("/create_store", methods=["POST"])
def seller_create_store():
user_id: str = request.json.get("user_id")
store_id: str = request.json.get("store_id")
s = seller.Seller()
code, message = s.create_store(user_id, store_id)
return jsonify({"message": message}), code
@bp_seller.route("/add_book", methods=["POST"])
def seller_add_book():
user_id: str = request.json.get("user_id")
store_id: str = request.json.get("store_id")
book_info: str = request.json.get("book_info")
stock_level: str = request.json.get("stock_level", 0)
s = seller.Seller()
code, message = s.add_book(user_id, store_id, book_info.get("id"), json.dumps(book_info), stock_level)
return jsonify({"message": message}), code
@bp_seller.route("/add_stock_level", methods=["POST"])
def add_stock_level():
user_id: str = request.json.get("user_id")
store_id: str = request.json.get("store_id")
book_id: str = request.json.get("book_id")
add_num: str = request.json.get("add_stock_level", 0)
s = seller.Seller()
code, message = s.add_stock_level(user_id, store_id, book_id, add_num)
return jsonify({"message": message}), code

+ 7
- 2
report.md View File

@ -255,10 +255,15 @@
```
![avatar](./figure_require/register_test.png)
7. 另外对于auth路由中的其他功能接口(注销、登录、登出、更改密码)进行类似上述注册接口的修改,此处不在单独贴出代码,只是给出postman的测试截图,至此auth中的路由全部实现(2022.10.30 17:50 杨舜)
7. 另外对于auth路由中的其他功能接口(注销、登录、登出、更改密码)进行类似上述注册接口的修改,此处不在单独贴出代码,只是给出postman的测试截图,至此auth中的路由全部实现(2022.11.30 17:50 杨舜)
![avatar](./figure_require/unregister_test.png)
![avatar](./figure_require/login_test.png)
![avatar](./figure_require/logout_test.png)
![avatar](./figure_require/password_test.png)
8.
8. 利用上述类似的实现auth路由接口的方式完成seller路由接口,并利用postman测试实现(2022.12.01 19:20 杨舜)
![avatar](./figure_require/creatstore_test.png)
![avatar](./figure_require/addbook_test.png)
![avatar](./figure_require/addstocklevel_test.png)
9.

Loading…
Cancel
Save