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 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): """ 条件查询 :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 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 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 post(self) -> jsonify: """ 增加一个bug信息 :return: jsonify """ parse = MyParse() parse.add(name="productId", type=int, required=True) parse.add(name="projectId", type=int, required=True) parse.add(name="platformId", type=int) parse.add(name="buildId", type=int) parse.add(name="errorTypeId", type=int) parse.add(name="title", required=True) parse.add(name="level", choices=['p1', 'p2', 'p3', 'p4'], required=True) parse.add(name="priority", choices=['p1', 'p2', 'p3', 'p4'], required=True) parse.add(name="assignedTo", type=int, required=True) parse.add(name="mailTo", type=int) parse.add(name="stepsBody") productId = parse.parse_args().get("productId") projectId = parse.parse_args().get("projectId") platformId = parse.parse_args().get("platformId") buildId = parse.parse_args().get("buildId") title = parse.parse_args().get("title") level = parse.parse_args().get("level") priority = parse.parse_args().get("priority") assignedTo = parse.parse_args().get("assignedTo") mailTo = parse.parse_args().get("mailTo") stepsBody = parse.parse_args().get("stepsBody") project = Project.get(projectId, "projectId") product = Product.get(productId, "productId") if mailTo: User.get(mailTo, "mailTo") if assignedTo: User.get(assignedTo, "assignedTo") if product not in project.product_records: return jsonify( myResponse(ResponseCode.Error_Relation, None, f"Project: Not included productId {productId}")) if platformId not in [i.id for i in product.platforms_records]: return jsonify( myResponse(ResponseCode.Error_Relation, None, f"Product: Not included platformId {platformId}")) if buildId not in [i.id for i in product.builds_records]: return jsonify(myResponse(ResponseCode.Error_Relation, None, f"Product: Not included buildId {buildId}")) try: u = Bugs(title=title, creater=g.user.id, stepsBody=stepsBody, product=productId, build=buildId) u.priority = priority u.level = level u.createrName = g.user.name u.save() return jsonify(myResponse(ResponseCode.SUCCESS, u.id, ResponseError.OK)) except ErrorType as e: log.error(e) return jsonify(myResponse(ResponseCode.ERROR, None, str(e)))
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: """ 注册 post请求 :return: jsonify """ parse = MyParse() parse.add(name="account", required=True) parse.add(name="name", required=True) parse.add(name="password", required=True) parse.add(name="departmentId", type=int, required=False) parse.add(name="admin", type=bool, required=False, default=False) parse.add(name="gender", type=bool, required=False, default=True) parse.add(name="email", required=False) parse.add(name="phone", required=False) departmentId = parse.parse_args().get("departmentId") account = parse.parse_args().get("account") name = parse.parse_args().get("name") password = parse.parse_args().get("password") admin = parse.parse_args().get("admin") gender = parse.parse_args().get('gender') email = parse.parse_args().get("email") phone = parse.parse_args().get("phone") if departmentId: # departmentId验证 Department.get(departmentId, 'departmentId') # name 验证 User.verify_account(account.lower()) u = User(account=account, name=name, password=password, gender=gender, department=departmentId, admin=admin, email=email, phone=phone) u.save() return jsonify(myResponse(ResponseCode.SUCCESS, u.id, 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="errorType", type=int, required=True) parse.add(name="priority") parse.add(name="mailTo") parse.add(name="note") bugID = parse.parse_args().get("bugID") bug = Bugs.get(bugID, "bugID") bug.update(parse.parse_args()) return jsonify(myResponse(ResponseCode.SUCCESS, bug.id, 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 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 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 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 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 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 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 put(self) -> jsonify: parse = MyParse() parse.add(name="bugID", type=int, required=True) parse.add(name="productId", type=int) parse.add(name="projectId", type=int) parse.add(name="platformId", type=int) parse.add(name="buildId", type=int) parse.add(name="errorTypeId", type=int) parse.add(name="title") parse.add(name="level", choices=['p1', 'p2', 'p3', 'p4']) parse.add(name="priority", choices=['p1', 'p2', 'p3', 'p4']) parse.add(name="assignedTo", type=int) parse.add(name="mailTo", type=int) parse.add(name="stepsBody") parse.add(name="confirmed", type=bool) parse.add(name="status", choices=["ACTIVE", "RESOLVED", "CLOSED"]) bugID = parse.parse_args().get("bugID") projectId = parse.parse_args().get("projectId") productId = parse.parse_args().get("productId") mailTo = parse.parse_args().get("mailTo") assignedTo = parse.parse_args().get("assignedTo") platformId = parse.parse_args().get("platformId") buildId = parse.parse_args().get("buildId") if projectId or productId: if not productId: return jsonify(myResponse(ResponseCode.ERROR, None, cantEmpty("productId"))) if not projectId: return jsonify(myResponse(ResponseCode.ERROR, None, cantEmpty("projectId"))) project = Project.get(projectId, "projectId") product = Product.get(productId, "productId") if product not in project.product_records: return jsonify( myResponse(ResponseCode.Error_Relation, None, f"Project: Not included productId {productId}")) if product not in project.product_records: return jsonify( myResponse(ResponseCode.Error_Relation, None, f"Project: Not included productId {productId}")) if platformId not in [i.id for i in product.platforms_records]: return jsonify( myResponse(ResponseCode.Error_Relation, None, f"Product: Not included platformId {platformId}")) if buildId not in [i.id for i in product.builds_records]: return jsonify( myResponse(ResponseCode.Error_Relation, None, f"Product: Not included buildId {buildId}")) if mailTo: User.get(mailTo, "mailTo") if assignedTo: User.get(assignedTo, "assignedTo") bug = Bugs.get(bugID, "bugID") bug.updater = g.user.id bug.updaterName = g.user.name bug.updateBug(parse.parse_args()) return jsonify(myResponse(ResponseCode.SUCCESS, bug.id, ResponseError.OK))
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 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))
def put(self) -> jsonify: parse = MyParse() parse.add(name="productId", req_type=int, required=True) parse.add(name="buildId", req_type=int, required=True) parse.add(name="name") pid = parse.parse_args().get("productId") bid = parse.parse_args().get("buildId") name = parse.parse_args().get("name") p = Product.get(pid, 'productId') b = Build.get(bid, "buildId") if b not in p.builds_records: return jsonify( myResponse(ResponseCode.Error_Relation, None, f"Product:{pid} Not included {bid}")) # 验证同一 product name唯一 if name in [i.name for i in p.builds_records]: return jsonify( myResponse(ResponseCode.UNIQUE, None, alreadyExists(name))) b.name = name b.save() return jsonify( myResponse(ResponseCode.SUCCESS, b.id, ResponseError.ResponseError.OK))
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 put(self) -> jsonify: parse = MyParse() parse.add(name="productId", req_type=int, required=True) parse.add(name="platformId", req_type=int, required=True) parse.add(name="name") pid = parse.parse_args().get("productId") pld = parse.parse_args().get("platformId") name = parse.parse_args().get("name") p = Product.get(pid, 'productId') pl = Platform.get(pld, 'platformId') if pl not in p.platforms_records: return jsonify( myResponse(ResponseCode.Error_Relation, None, f"Product:{pid} Not included {pld}")) # 验证同一 product name唯一 if name in [i.name for i in p.platforms_records]: return jsonify( myResponse(ResponseCode.UNIQUE, None, alreadyExists(name))) pl.name = name pl.save() return jsonify( myResponse(ResponseCode.SUCCESS, pl.id, ResponseError.ResponseError.OK))
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 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: """ 解决bug :return: """ parse = MyParse() parse.add(name='bugID', type=int, required=True) parse.add(name="confirm", type=int, required=True) parse.add(name="errorType", type=int) parse.add(name="mailTo", type=int) parse.add(name="priority", type=int, required=True) parse.add(name="note") bugID = parse.parse_args().get('bugID') note = parse.parse_args().get("note") 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 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 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 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))