def wrapper(*args, **kwargs): if request.method == 'GET': try: wdpa_id = request.view_args.get('id') geojson, area_ha = GeostoreService.get_wdpa(wdpa_id) except GeostoreNotFound: return error(status=404, detail='Geostore not found') kwargs["geojson"] = geojson kwargs["area_ha"] = area_ha return func(*args, **kwargs)
def wrapper(*args, **kwargs): if request.method == 'GET': try: iso = request.view_args.get('iso') id1 = request.view_args.get('id1') geojson, area_ha = GeostoreService.get_subnational(iso, id1) except GeostoreNotFound: return error(status=404, detail='Geostore not found') kwargs["geojson"] = geojson kwargs["area_ha"] = area_ha return func(*args, **kwargs)
def wrapper(*args, **kwargs): if request.method == 'GET': geostore = request.args.get('geostore') if not geostore: return error(status=400, detail='Geostore is required') try: geojson, area_ha = GeostoreService.get(geostore) except GeostoreNotFound: return error(status=404, detail='Geostore not found') elif request.method == 'POST': geojson = request.get_json().get( 'geojson', None) if request.get_json() else None try: area_ha = AreaService.tabulate_area(geojson) except Exception as e: logging.info(f"[middleware geo hash] Exception") return error(status=500, detail=str(e)) kwargs["geojson"] = geojson kwargs["area_ha"] = area_ha return func(*args, **kwargs)