Пример #1
0
 def post(self):
     args = parser.parse_args()
     name = args.get('name')
     location = args.get('location')
     if name is None or location is None:
         abort(400, message='Bad request data')
     lat = location['lat']
     lon = location['lon']
     record = Business()
     record.name = name
     record.location = {
         "type": "Point",
         "coordinates": [lon, lat]
     }
     record.save()
     return record, 201
Пример #2
0
 def get(self):
     args = parser.parse_args()
     distance = args.get('distance')
     location = args.get('location')
     filter_kwargs = {}
     if distance is not None and location is not None:
         filter_kwargs = {
             'location__near': [location['lon'], location['lat']],
             'location__max_distance': distance * METERS_PER_MILE
         }
     records = Business.objects(**filter_kwargs)
     return list(records)
Пример #3
0
 def delete(self, _id):
     get_record_by_id(_id)
     Business.objects(_id=_id).delete()
     return '', 204
Пример #4
0
def get_record_by_id(_id):
    record = Business.objects(_id=_id)
    if not record:
        abort(404, message="Business with id {} doesn't exist".format(_id))
    return record[0]