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 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 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 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 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 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 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 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 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 post(self) -> jsonify: parse = MyParse() parse.add(name="name", required=True) parse.add(name="solutions", type=list) parse.add(name="platforms", type=list) parse.add(name="builds", type=list) parse.add(name="errorTypes", type=list) parse.add(name="projectId", type=int) parse.add(name='module', type=list) name = parse.parse_args().get("name") solutions = parse.parse_args().get("solutions") platforms = parse.parse_args().get("platforms") builds = parse.parse_args().get("builds") errorTypes = parse.parse_args().get("errorTypes") projectId = parse.parse_args().get(("projectId")) modules = parse.parse_args().get("module") Project.get(projectId, 'projectId') Product.verify_name(name) pro = Product(name, projectId) pro.save() try: if solutions: for s in solutions: Solution.verify_name(s) Solution(name=s, productId=pro.id).save() if platforms: for p in platforms: Platform.verify_name(p) Platform(name=p, productId=pro.id).save() if builds: for b in builds: Build.verify_name(b) Build(name=b, productId=pro.id, builder=g.user.name).save() if errorTypes: for e in errorTypes: ErrorType.verify_name(e) ErrorType(name=e, productId=pro.id).save() if modules: for m in modules: Module.verify_name(m) Module(name=m, productId=pro.id).save() 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 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: 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 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 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) -> 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): """ 全局搜索 :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: """ 创建部门 :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 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 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))