Esempio n. 1
0
    async def get(self, request, parcel_type, storage_id):
        """ Select parcels from database with pre-defined parameters:
        param parcel_type (str): name of parcel type
        param storage_id (str): UUID of storage received the parcel
        param request: request.json:
        "date" (optional) is date of request. Can be: empty - returns all parcels, single - returns parcels for one day,
                                    date range - returns parcels for the period
        return: list of parcels (if there are more than 1 parcels otherwise dict) and total cost of parcels.
        """
        _, err = ParcelSchema().dump({'id': storage_id})
        if err:
            return json({'Errors': err}, status=404)
        date = request.args.get('date', None)

        parcels, total_cost = await get_parcel_by_type_and_storage(parcel_type, storage_id, date)

        return json({'parcels': map_response(parcels), 'total_cost': map_response(total_cost[0])}, status=200)
Esempio n. 2
0
    async def get(self, request, client_id):
        _, err = ClientSchema().dump({'id': client_id})
        if err:
            return json({'Errors': err}, status=404)

        client = await get_client_by_id(client_id)
        if client:
            return json({"Client": map_response(client)})
        return json({'msg': 'Client with id {} does not exist'.format(client_id)}, status=404)
Esempio n. 3
0
    async def get(self, request, parcel_id):
        _, err = ParcelSchema().dump({'id': parcel_id})
        if err:
            return json({'Errors': err}, status=404)

        parcel = await get_parcel_by_id(parcel_id)
        if parcel:
            return json({"Parcel": map_response(parcel)})
        return json({'msg': 'Parcel with id {} does not exist'.format(parcel_id)}, status=404)
Esempio n. 4
0
    async def get(self, request, storage_id):
        _, err = StorageSchema().dump({'id': storage_id})
        if err:
            return json({'Errors': err}, status=404)

        storage = await get_storage_by_id(storage_id)
        if storage:
            return json({"Storage": map_response(storage)})
        return json({'msg': 'Storage with id {} does not exist'.format(storage_id)}, status=404)
Esempio n. 5
0
    async def get(self, request, type_id):
        _, err = ParceltypeSchema().dump({'id': type_id})
        if err:
            return json({'Errors': err}, status=404)

        pars_type = await get_type_by_id(type_id)
        if pars_type:
            return json({"Parcel_type": map_response(pars_type)})
        return json({'msg': 'Parcel type with id {} does not exist'.format(type_id)}, status=404)
Esempio n. 6
0
    async def get(self, request, supply_id):
        _, err = SupplySchema().dump({'id': supply_id})
        if err:
            return json({'Errors': err}, status=404)

        supply = await get_supply_by_id(supply_id)
        if supply:
            return json({"Supply": map_response(supply)})
        return json(
            {'msg': 'Supply with id {} does not exist'.format(supply_id)},
            status=404)
Esempio n. 7
0
 async def get(self, request):
     all_clients = await get_all_clients()
     return json({"Clients": map_response(all_clients)})
Esempio n. 8
0
    async def post(self, request):
        reports_client = RESTClientRegistry.get('reports')
        report_data, _ = await get_parcel_by_type_and_storage(request.json.get('parcel_type'),
                                                              request.json.get('storage_id'),
                                                              request.json.get('date', None))
        head = list(report_data[0].keys())

        response, status_code = await reports_client().generate_report(url_path='report',
                                                                       json_data={'report_type': 'parcels',
                                                                                  'headers': head,
                                                                                  'data': map_response(report_data)})
        print(response, status_code)
        return json({'result': response}, status=status_code)
Esempio n. 9
0
 async def get(self, request):
     all_parcel = await get_all_parcels()
     return json({"Parcels": map_response(all_parcel)})
Esempio n. 10
0
 async def get(self, request):
     all_supply = await get_all_supply()
     return json({"Supply": map_response(all_supply)})
Esempio n. 11
0
 async def get(self, request):
     all_storage = await get_all_storage()
     return json({"Storages": map_response(all_storage)})
Esempio n. 12
0
 async def get(self, request):
     all_types = await get_all_types()
     return json({"Types": map_response(all_types)})