def batch_update_status(request): if request.method != CommonData.Method.GET.value: response = Response(RequestMethodError, 'Method is invalid', {}) return HttpResponse(response.toJson(), content_type='application/json') if 'api_ids[]' not in request.GET.keys(): response = Response(MissingParametersError, 'Missing Parameters', {}) return HttpResponse(response.toJson(), content_type='application/json') if ('status' not in request.GET.keys()): response = Response(MissingParametersError, 'Has no param "status"', {}) return HttpResponse(response.toJson(), content_type='application/json') status = int(request.GET['status']) enum_list = [e.value for e in Api.Status] if status not in enum_list: response = Response(MissingParametersError, 'status 参数错误', {}) return HttpResponse(response.toJson(), content_type='application/json') api_ids = request.GET.getlist('api_ids[]') for api_id in api_ids: api = ApiDao.get_api_with_id(api_id) if api is not None: api.status = status ApiDao.update(api) response = Response(Success, 'Success', {}) return HttpResponse(response.toJson(), content_type='application/json')
def update_status(request, project_id, api_id): if request.method != CommonData.Method.GET.value: data = CommonData.response_data(RequetMethodError, "Method is invalid") return HttpResponse(json.dumps(data), content_type="application/json") if ('status' not in request.GET.keys()): data = CommonData.response_data(MissingParametersError, "缺少参数") return HttpResponse(json.dumps(data), content_type="application/json") status = request.GET['status'] api = ApiDao.get_api_with_id(api_id) if api is not None: api.status = status result = ApiDao.update(api) if result is False: data = CommonData.response_data(DaoOperationError, "Update API Faild") return HttpResponse(json.dumps(data), content_type="application/json") else: data = CommonData.response_data(Success, "Success") return HttpResponse(json.dumps(data), content_type="application/json") else: data = CommonData.response_data(DaoOperationError, "API is not exist") return HttpResponse(json.dumps(data), content_type="application/json")
def star(request, project_id, api_id): if request.method != CommonData.Method.GET.value: data = CommonData.response_data(RequetMethodError, "Method is invalid") return HttpResponse(json.dumps(data), content_type="application/json") api = ApiDao.get_api_with_id(api_id) if api is not None: api.star = not api.star print(api.star) result = ApiDao.update(api) if result is False: data = CommonData.response_data(DaoOperationError, "Update API Faild") return HttpResponse(json.dumps(data), content_type="application/json") else: data = CommonData.response_data(Success, "Success") return HttpResponse(json.dumps(data), content_type="application/json") else: data = CommonData.response_data(DaoOperationError, "API is not exist") return HttpResponse(json.dumps(data), content_type="application/json")
def update(request, project_id, api_id): if request.method != CommonData.Method.POST.value: data = CommonData.response_data(RequetMethodError, "Method is invalid") return HttpResponse(json.dumps(data), content_type="application/json") form = ApiUpdateForm(data=request.POST) if form.is_valid(): model = ApiDao.get_api_with_id(api_id) model.path = form.clean().get('path') if model.path.startswith('/', ): model.path = model.path[1:] model.method = form.clean().get('method') model.name = form.clean().get('name') model.note = form.clean().get('note') model.status = form.clean().get('status') model.responseJson = form.clean().get('responseJson') result = ApiDao.update(model) if result is False: data = CommonData.response_data(DaoOperationError, "API update faild") return HttpResponse(json.dumps(data), content_type="application/json") else: data = CommonData.response_data(Success, "Sucsses") return HttpResponse(json.dumps(data), content_type="application/json") else: data = CommonData.response_data(FormParseError, "Form parse faild") return HttpResponse(json.dumps(data), content_type="application/json")
def update_status(request, project_id, api_id): if request.method != CommonData.Method.GET.value: return HttpResponse(Response.methodInvalidResponse().toJson(), content_type='application/json') if ('status' not in request.GET.keys()): response = Response(MissingParametersError, 'Has no param "status"', {}) return HttpResponse(response.toJson(), content_type='application/json') status = request.GET['status'] api = ApiDao.get_api_with_id(api_id) if api is not None: api.status = status result = ApiDao.update(api) if result is False: response = Response(DaoOperationError, 'Update API Failed', {}) return HttpResponse(response.toJson(), content_type='application/json') else: response = Response(Success, 'Success', {}) return HttpResponse(response.toJson(), content_type='application/json') else: response = Response(DaoOperationError, 'API is not exist', {}) return HttpResponse(response.toJson(), content_type='application/json')
def star(request, project_id, api_id): if request.method != CommonData.Method.GET.value: return HttpResponse(Response.methodInvalidResponse().toJson(), content_type='application/json') api = ApiDao.get_api_with_id(api_id) if api is not None: api.star = not api.star result = ApiDao.update(api) if result is False: response = Response(DaoOperationError, 'Update API Failed', {}) return HttpResponse(response.toJson(), content_type='application/json') else: response = Response(Success, 'Success', {}) return HttpResponse(response.toJson(), content_type='application/json') else: response = Response(DaoOperationError, 'API is not exist', {}) return HttpResponse(response.toJson(), content_type='application/json')
def update(request, project_id, api_id): if request.method != CommonData.Method.POST.value: return HttpResponse(Response.methodInvalidResponse().toJson(), content_type='application/json') form = ApiUpdateForm(data=request.POST) if form.is_valid(): model = ApiDao.get_api_with_id(api_id) model.path = form.clean().get('path') if model.path.startswith('/', ): model.path = model.path[1:] model.method = form.clean().get('method') model.name = form.clean().get('name') model.note = form.clean().get('note') model.status = form.clean().get('status') res = ResTemplateDao.get_private_res_template_with_api_id(api_id) res.responseJson = form.clean().get('responseJson') ResTemplateDao.update(res) result = ApiDao.update(model) if result is False: response = Response(DaoOperationError, 'API update failed', {}) return HttpResponse(response.toJson(), content_type='application/json') else: response = Response(Success, 'Success', {}) return HttpResponse(response.toJson(), content_type='application/json') else: response = Response(FormParseError, 'Form parse failed', {}) return HttpResponse(response.toJson(), content_type='application/json')