def starList(request): if request.method != CommonData.Method.GET.value: data = CommonData.response_data(RequetMethodError, "Method is invalid") return HttpResponse(json.dumps(data), content_type="application/json") limit = 10 page = 1 if 'limit' in request.GET.keys(): limit = int(request.GET['limit']) if 'current_page' in request.GET.keys(): page = int(request.GET['current_page']) offset = (page - 1) * limit apis = ApiDao.get_all_stared_apis(offset, limit) apis_dict = [] for api in apis: api_dic = api.as_dict() project_dic = ProjectDao.get_project_with_api_id(api.api_id) if project_dic is not None: api_dic['project'] = project_dic apis_dict.append(api_dic) count = ApiDao.get_stared_apis_count() data = CommonData.response_data(Success, "Success") data["apis_data"] = { "apis": apis_dict, "current_page": page, "total": count, "limit": limit } return HttpResponse(json.dumps(data, default=datetime2string), content_type="application/json")
def starList(request): if request.method != CommonData.Method.GET.value: return HttpResponse(Response.methodInvalidResponse().toJson(), content_type='application/json') limit = 10 page = 1 if 'limit' in request.GET.keys(): limit = int(request.GET['limit']) if 'current_page' in request.GET.keys(): page = int(request.GET['current_page']) offset = (page - 1) * limit apis = ApiDao.get_all_stared_apis(offset, limit) apis_dict = [] for api in apis: api_dic = api.as_dict() project_dic = ProjectDao.get_project_with_api_id(api.api_id) if project_dic is not None: api_dic['project'] = project_dic apis_dict.append(api_dic) count = ApiDao.get_stared_apis_count() response = Response(Success, 'Success', {'apis': apis_dict, 'current_page': page, 'total': count, 'limit': limit}) return HttpResponse(response.toJson(), content_type='application/json')