Skip to content

Commit

Permalink
Merge pull request #81 from licenseware/suggest-pagination-reports
Browse files Browse the repository at this point in the history
feat: added skip and limit in swagger params on reports get_data func…
  • Loading branch information
alincmt authored Mar 16, 2022
2 parents f2833da + 566adb1 commit 1ba37de
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,95 +12,84 @@
from licenseware.download import download_as





def create_individual_report_component_resource(component: BaseReportComponent):


class ComponentRes(Resource):

@failsafe(fail_code=500)
@authorization_check
@authorization_check
def post(self):
return component.get_data(request)

@failsafe(fail_code=500)
@authorization_check
@authorization_check
def get(self):

file_type = request.args.get('download_as')
tenant_id = request.headers.get('Tenantid')
data = component.get_data(request)
if file_type is None:

if file_type is None:
return data

return download_as(
file_type,
data,
tenant_id,
file_type,
data,
tenant_id,
filename=component.component_id
)

return ComponentRes



return ComponentRes


def get_report_components_namespace(ns: Namespace, reports:List[ReportBuilder]):

def get_report_components_namespace(ns: Namespace, reports: List[ReportBuilder]):
restx_model = ns.model('ComponentFilter', dict(
column = fields.String,
filter_type = fields.String,
filter_value = fields.List(fields.String)
)
)


column=fields.String,
filter_type=fields.String,
filter_value=fields.List(fields.String)
)
)

for report in reports:
for comp in report.components:

ComponentRes = create_individual_report_component_resource(comp)

docs = {
'get': {
'description': 'Get component data',
'params': {'download_as':
{
'description': 'Download table component as file type: csv, xlsx, json'
}
'description': 'Get component data',
'params': {
'limit': {'description': 'Limit the number of results'},
'skip': {'description': 'Skip the first n results'},
'download_as': {'description': 'Download table component as file type: csv, xlsx, json'}
},
'responses': {
200: 'Success',
403: 'Missing `Tenantid` or `Authorization` information',
'responses': {
200: 'Success',
403: 'Missing `Tenantid` or `Authorization` information',
500: 'Something went wrong while handling the request'
}
},
'post': {
'description': 'Get component data with an optional filter payload',
'validate': None,
'expect': [restx_model],
'responses': {
200: 'Success',
403: 'Missing `Tenantid` or `Authorization` information',
'description': 'Get component data with an optional filter payload',
'params': {
'limit': {'description': 'Limit the number of results'},
'skip': {'description': 'Skip the first n results'}
},
'validate': None,
'expect': [restx_model],
'responses': {
200: 'Success',
403: 'Missing `Tenantid` or `Authorization` information',
500: 'Something went wrong while handling the request'
}
}
}

ComponentRes.__apidoc__ = docs

IRCResource = type(
comp.component_id.replace("_", "").capitalize() + 'individual_component',
(ComponentRes, ),
(ComponentRes,),
{}
)

ns.add_resource(IRCResource, report.report_path + comp.component_path)

return ns



ns.add_resource(IRCResource, report.report_path + comp.component_path)

return ns
6 changes: 6 additions & 0 deletions licenseware/resources/_report_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ def __init__(


def get_data(self, flask_request):

limit = flask_request.args.get("limit")
skip = flask_request.args.get("skip")

if skip and not limit or limit and not skip:
return "Limit and skip must be set together", 400

match_filters = self.get_mongo_match_filters(flask_request)

Expand Down
Binary file modified wheel_sdk/licenseware-2.0.2-py3-none-any.whl
Binary file not shown.
Binary file modified wheel_sdk/licenseware-2.0.2.tar.gz
Binary file not shown.

0 comments on commit 1ba37de

Please sign in to comment.