def getfile() -> jsonify: from flask import send_file parse = MyParse() parse.add(name="fileID", required=True, location="args") fileID = parse.parse_args().get("fileID") file = BugFile.get(fileID, "fileID") return send_file(file.filePath)
def get(self) -> jsonify: parse = MyParse() parse.add(name="bugID", location="args") bugID = parse.parse_args().get("bugID") bug = Bugs.get(bugID, "bugID", obj=False) return jsonify(myResponse(ResponseCode.SUCCESS, bug, ResponseError.OK))
def put(self) -> jsonify: parse = MyParse() parse.add(name="productName", required=True) parse.add(name="productId", required=True) name = parse.parse_args().get("productName") Id = parse.parse_args().get('productId') pro = Product.get(Id, 'productId') Product.verify_name(name) if not pro: return jsonify(myResponse(ResponseCode.ERROR, None, cantEmpty(Id))) else: try: pro.name = name db.session.commit() return jsonify( myResponse(ResponseCode.SUCCESS, name, ResponseError.OK)) except ErrorType as e: log.error(f"{__class__} {e}") db.session.rollback() return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def post(self) -> jsonify: parse = MyParse() parse.add(name="productId") parse.add(name="name") pid = parse.parse_args().get("productId") name = parse.parse_args().get("name") p = Product.get(pid, "productId") # 验证同一 product name唯一 if name in [i.name for i in p.solutions_records]: return jsonify( myResponse(ResponseCode.UNIQUE, None, alreadyExists(name))) try: s = Solution(name, pid) s.save() return jsonify( myResponse(ResponseCode.SUCCESS, s.id, ResponseError.OK)) except Exception as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def delete(self) -> jsonify: parse = MyParse() parse.add(name="bugID", type=int, required=True) bugID = parse.parse_args().get("bugID") bug = Bugs.get(bugID, "bugID") bug.delete() return jsonify(myResponse(ResponseCode.SUCCESS, None, ResponseError.OK))
def delFile() -> jsonify: parse = MyParse() parse.add(name="fileID", required=True, type=int) fileID = parse.parse_args().get("fileID") bug = BugFile.get(fileID, "fileID") filePath = bug.filePath import os os.remove(filePath) bug.delete() return jsonify(myResponse(ResponseCode.SUCCESS, None, ResponseError.OK))
def post(self): """ 条件查询 :title 包含 不包含 = != :id = != :assignedTo = != :creater = != :resolvedBy = != :solution = != :platform = != :level = != :priority = != :status = != :confirmed = != :errorType = != :createTime = != :return: """ requestBody = { "option": "and", "searchBody": [ { "key": "id", "condition": ">", "val": 1 }, { "key": "level", "condition": "=", "val": "p1" } ] } parse = MyParse() parse.add(name="option", choices=['and', 'or'], required=True) parse.add(name="searchBody", type=list, required=True) bugInfos = [{ "bugID": info[0], "createTime": info[1], "title": info[3], "level": info[4], "priority": info[5], "status": info[6], "confirmed": info[7], "creater": info[8], "updater": info[1], "solutionID": info[14] } for info in SearchParamsParse(parse.parse_args().get("searchBody"), parse.parse_args().get("option")).filter()] return jsonify(myResponse(ResponseCode.SUCCESS, bugInfos, ResponseError.OK))
def post(self): """ 复制bug接口 :return: """ parse = MyParse() parse.add(name="bugID", type=int, required=True) bugID = parse.parse_args().get("bugID") bug = Bugs.get(bugID, "bugID", obj=False) return jsonify(myResponse(ResponseCode.SUCCESS, bug, ResponseError.OK))
def delete(self) -> jsonify: parse = MyParse() parse.add(name="projectId", type=int, required=True) id = parse.parse_args().get("projectId") try: Project.get(id, 'projectId').delete() return jsonify( myResponse(ResponseCode.SUCCESS, None, ResponseError.OK)) except Exception as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def delete(self) -> jsonify: parse = MyParse() parse.add(name="moduleId", type=int, required=True) e = Module.get(parse.parse_args().get("moduleId"), 'moduleId') try: e.delete() return jsonify( myResponse(ResponseCode.SUCCESS, None, ResponseError.OK)) except Exception as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def get(self) -> jsonify: parse = MyParse() parse.add(name="productId", location="args", required=True) pid = parse.parse_args().get("productId") p = Product.get(pid, 'productId') try: b = [{"build_name": i.name, "id": i.id} for i in p.builds_records] return jsonify( myResponse(ResponseCode.SUCCESS, b, ResponseError.OK)) except Exception as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def get(self) -> jsonify: parse = MyParse() parse.add(name="productId", location='args', required=True) pid = parse.parse_args().get("productId") p = Product.get(pid, 'productId') try: e = [i.name for i in p.modules_records] return jsonify( myResponse(ResponseCode.SUCCESS, e, ResponseError.OK)) except Exception as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def delete(self): parse = MyParse() parse.add(name="platformId", required=True) id = parse.parse_args().get("platformId") p = Platform.get(id, 'platformId') try: p.delete() return jsonify( myResponse(ResponseCode.SUCCESS, None, ResponseError.OK)) except Exception as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def post(self) -> jsonify: parse = MyParse() parse.add(name="name", required=True) name = parse.parse_args().get("name") Project.verify_name(name) try: p = Project(name) p.save() return jsonify( myResponse(ResponseCode.SUCCESS, p.id, ResponseError.OK)) except Exception as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def delete(self) -> jsonify: parse = MyParse() parse.add(name="solutionId") id = parse.parse_args().get("solutionId") s = Solution.get(id, "solutionId") try: s.delete() return jsonify( myResponse(ResponseCode.SUCCESS, None, ResponseError.OK)) except ErrorType as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def delete(self) -> jsonify: """ 删除部门 :return: jsonify """ parse = MyParse() parse.add(name="id", required=True) d = Department.get(parse.parse_args().get("id"), 'departmentId') try: d.delete() return jsonify(myResponse(ResponseCode.SUCCESS, None, ResponseError.OK)) except Exception as e: log.error(e) db.session.rollback() return jsonify(myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def post(self): """ 全局搜索 :return: """ parse = MyParse() parse.add(name="opt", choices=range(1, 6), type=int, required=True) parse.add(name="searchID", type=int, required=True) opt = parse.parse_args().get("opt") id = parse.parse_args().get("searchID") return jsonify( myResponse(ResponseCode.SUCCESS, SearchOpt[opt].get(id, "searchID", obj=False), ResponseError.OK))
def post(self) -> jsonify: parse = MyParse() parse.add(name="account", required=True) parse.add(name="password", required=True) account = parse.parse_args().get("account") password = parse.parse_args().get("password") user = User.query.filter(User.account == account).first() if user: res = user.verify_password(password) if res: token = user.generate_auth_token().decode("ascii") # 发送信号 login_signal.send(username=account) return jsonify(myResponse(ResponseCode.SUCCESS, token, ResponseError.OK)) else: return jsonify(myResponse(ResponseCode.ERROR, None, ResponseError.ERROR_PASSWORD)) return jsonify(myResponse(ResponseCode.ERROR, None, ResponseError.ERROR_ACCOUNT))
def post(self) -> jsonify: """ 创建部门 :return: jsonify """ parse = MyParse() parse.add(name="name", required=True) name = parse.parse_args().get("name") Department.verify_name(name=name) try: d = Department(name=name) d.save() return jsonify(myResponse(ResponseCode.SUCCESS, d.id, ResponseError.OK)) except Exception as e: log.error(e) db.session.rollback() return jsonify(myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def put(self) -> jsonify: """ 修改部门信息 :return: jsonify """ parse = MyParse() parse.add(name="departmentId", required=True) parse.add(name="name", required=True) did = parse.parse_args().get("departmentId") name = parse.parse_args().get("name") d = Department.get(did, 'departmentId') try: d.name = name d.save() return jsonify(myResponse(ResponseCode.SUCCESS, d.id, ResponseError.OK)) except Exception as e: log.error(e) db.session.rollback() return jsonify(myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def get(self) -> jsonify: parse = MyParse() parse.add(name="productId", required=False, location='args') pid = parse.parse_args().get("productId") try: if pid: ps = [Product.get(pid, "productId")] else: ps = Product.all() productInfo = [{ "id": i.id, "name": i.name, "solutions": [{ "solution_name": s.name, "id": s.id } for s in i.solutions_records], "platforms": [{ "platform_name": p.name, "id": p.id } for p in i.platforms_records], "builds": [{ "build_name": b.name, "id": b.id } for b in i.builds_records], "errorTypes": [{ "error_name": e.name, "id": e.id } for e in i.errorTypes_records], "modules": [{ 'module_name': m.name, "id": m.id } for m in i.modules_records] } for i in ps] return jsonify( myResponse(ResponseCode.SUCCESS, productInfo, ResponseError.OK)) except Exception as e: log.exception(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def putFile() -> jsonify: parse = MyParse() parse.add(name="fileID", required=True, type=int) parse.add(name="fileName", required=True) fileID = parse.parse_args().get("fileID") fileNewName = parse.parse_args().get('fileName') # 没有后缀 file = BugFile.get(fileID, "fileID") fileOldName = file.fileName fileOldPath = file.filePath import os try: fileNewName = fileNewName + "." + fileOldName.split(".")[1] fileNewPath = fileOldPath.replace(fileOldName, fileNewName) file.fileName = fileNewName file.filePath = fileNewPath os.rename(fileOldPath, fileNewPath) return jsonify(myResponse(ResponseCode.SUCCESS, file.id, ResponseError.OK)) except Exception as e: log.error(e) return jsonify(myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def get(self) -> jsonify: parse = MyParse() parse.add(name='projectId', required=False, location="args") pid = parse.parse_args().get("projectId") try: if pid: p = [Project.get(pid, "projectId")] else: p = Project.all() info = [{ "id": i.id, "name": i.name, "product": [j.name for j in i.product_records] } for i in p] return jsonify( myResponse(ResponseCode.SUCCESS, info, ResponseError.OK)) except Exception as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def post(self) -> jsonify: parse = MyParse() parse.add(name="productId", req_type=int, required=True) parse.add(name="name", required=True) pid = parse.parse_args().get("productId") name = parse.parse_args().get("name") p = Product.get(pid, 'productId') if name in [i.name for i in p.modules_records]: return jsonify( myResponse(ResponseCode.UNIQUE, None, alreadyExists(name))) try: m = Module(name, pid) m.save() return jsonify( myResponse(ResponseCode.SUCCESS, m.id, ResponseError.OK)) except Exception as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))
def put(self) -> jsonify: parse = MyParse() parse.add(name="productId", req_type=int, location="args") parse.add(name="solutionId", req_type=int, location="args") parse.add(name="name", location="args") pid = parse.args.get("productId") sid = parse.args.get("solutionId") name = parse.args.get("name") p = Product.get(pid, "productId") s = Solution.get(sid, "solutionId") if s not in p.solutions_records: return jsonify( myResponse(ResponseCode.Error_Relation, None, f"Product:{pid} Not included {sid}")) # 验证同一 product name唯一 if name in [i.name for i in p.solutions_records]: return jsonify( myResponse(ResponseCode.Error_Relation, None, alreadyExists(name))) s.name = name s.save() return jsonify(ResponseCode.SUCCESS, s.id, ResponseError.OK)
def post(self) -> jsonify: from COMMENT.sqlOpt import SqlOpt """ 按组搜索 group:[{"key":"","val":"","condition":"<|>|=|like||!=","opt":"and|or"}] :return: """ parse = MyParse() parse.add(name="group", required=True, type=list) bugInfos = [{ "bugID": info[0], "createTime": info[1], "title": info[3], "level": info[4], "priority": info[5], "status": info[6], "confirmed": info[7], "creater": info[8], "updater": info[1], "solutionID": info[14] } for info in SqlOpt("bugs").select(parse.parse_args().get("group"))] return jsonify(myResponse(ResponseCode.SUCCESS, bugInfos, ResponseCode.OK))
def get(self) -> jsonify: """ 一些固定搜索哦 :return: """ parse = MyParse() parse.add(name="opt", choices=['all', 'unClose', 'createByMe', 'assignedToMe', 'resolvedByMe'], location="args", required=True) infos = [{ "bugID": bug.id, "createTime": bug.create_time, "title": bug.title, "level": bug.level, "priority": bug.priority, "status": bug.status, "confirmed": bug.confirmed, "creater": bug.creater, "updater": bug.updater, "solutionID": bug.solution } for bug in Bugs.optGetBugInfos(parse.parse_args().get("opt"))] return jsonify(myResponse(ResponseCode.SUCCESS, infos, ResponseError.OK))
def post(self) -> jsonify: """ 指派bug :return: """ parse = MyParse() parse.add(name="bugID", type=int, required=True) parse.add(name="assignedTo", type=int, required=True) parse.add(name="mailTo") parse.add(name="note") bugID = parse.parse_args().get("bugID") assTo = parse.parse_args().get("assignedTo") note = parse.parse_args().get("note") User.get(assTo, "assignedTo") bug = Bugs.get(bugID, "bugID") bug.update(parse.parse_args()) if note: no = Note(bugID, note, g.user.id) no.save() return jsonify(myResponse(ResponseCode.SUCCESS, bug.id, ResponseError.OK))
def put(self) -> jsonify: parse = MyParse() parse.add(name="productId", req_type=int, required=True) parse.add(name="moduleId", req_type=int, required=True) parse.add(name="name") pid = parse.parse_args().get("productId") mid = parse.parse_args().get("moduleId") name = parse.parse_args().get("name") p = Product.get(pid, 'productId') e = Module.get(mid, 'moduleId') if e not in p.modules_records: return jsonify( myResponse(ResponseCode.Error_Relation, None, f"Product:{pid} Not included {mid}")) if name in [i.name for i in p.modules_records]: return jsonify( myResponse(ResponseCode.UNIQUE, None, alreadyExists(name))) e.name = name e.save() return jsonify( myResponse(ResponseCode.SUCCESS, e.id, ResponseError.ResponseError.OK))
def post(self) -> jsonify: parse = MyParse() parse.add(name="productId", type=int, required=True) parse.add(name="name", required=True) parse.add(name="desc", type=str) pid = parse.parse_args().get("productId") name = parse.parse_args().get("name") desc = parse.parse_args().get("desc") p = Product.get(pid, 'productId') # 验证同一 product name唯一 if name in [i.name for i in p.builds_records]: return jsonify( myResponse(ResponseCode.UNIQUE, None, alreadyExists(name))) try: b = Build(name, pid, g.user.name, desc) b.save() return jsonify( myResponse(ResponseCode.SUCCESS, b.id, ResponseError.OK)) except Exception as e: log.error(e) return jsonify( myResponse(ResponseCode.ERROR, None, ResponseError.SOME_ERROR_TRY_AGAIN))