示例#1
0
def delete_geocache_by_id():
    if not request.json:
        return Response(json.dumps({'error': f'Bad request.'}), mimetype=mimetype, status=400)
    geo_id = request.json['id']
    geo = Geocache.search_by_id(geo_id)
    status = 200
    if geo is None:
        status = 404
        result = {'error': f'Error 404. Not found. Can not found a geocache with id: {id}'}
    else:
        Geocache.delete_geocache(geo_id)
        result = {'result': f'Status 200. The geocache: {geo_id} was deleted.'}
    return Response(json.dumps(result), mimetype=mimetype, status=status)
示例#2
0
def update_geocache():
    if not request.json:
        return Response(json.dumps({'error': f'Bad request.'}), mimetype=mimetype, status=400)
    geo_id = request.json['id']
    entry = request.json['entry']
    value = request.json['value']
    status = 200
    geo = Geocache.get_geocache(geo_id)
    if geo is None:
        status = 404
        result = {'error': f'Error 404. Geocache with id: {geo_id} not found.'}
    else:
        Geocache.update_geo_value(geo_id, entry, value)
        result = {'result': f'Status 200. The geocache: {geo_id} was updated.'}
    return Response(json.dumps(result), mimetype=mimetype, status=status)
示例#3
0
def get_geocache_by_hint(hint: str):
    result = Geocache.geocache_by_hint(hint)
    status = 200
    if result is None:
        status = 404
        result = f'Error 404. Geocache with hint: {hint} not found.'
    return Response(json.dumps(result), mimetype=mimetype, status=status)
示例#4
0
def get_geocache_by_id(geo_id: int):
    result = Geocache.get_geocache(geo_id)
    status = 200
    if result is None:
        status = 404
        result = f'Error 404. Geocache with id: {geo_id} not found.'
    return Response(json.dumps(result), mimetype=mimetype, status=status)
示例#5
0
def create_user():
    if not request.json:
        return Response(json.dumps({'error': f'Bad Request.'}), mimetype=mimetype, status=400)
    geo_id = request.json['id']
    lat = request.json['lat']
    lon = request.json['lon']
    image = request.json['image']
    hint = request.json['hint']
    geocache = Geocache.get_geocache(geo_id)
    status = 200
    if geocache is None:
        Geocache.create_geocache(geo_id, lat, lon, image, hint)
        result = {'result': f'Status 200. The geocache was created.'}
    else:
        status = 400
        result = {'error': f'Error 400. The geocache with id: {geo_id} is already in the database'}
    return Response(json.dumps(result), mimetype=mimetype, status=status)
示例#6
0
def get_all_users():
    result = Geocache.get_all_geocaches()
    print(result)
    status = 200
    if result is None:
        status = 400
        result = f'Error 400. There are no geocaches.'
    return Response(json.dumps(result), mimetype=mimetype, status=status)
示例#7
0
def delete_logbook_by_id():
    if not request.json:
        return Response(json.dumps({'error': f'Bad request.'}), mimetype=mimetype, status=400)
    log_id = request.json['id']
    log = Geocache.search_by_id(log_id)
    status = 200
    if log is None:
        status = 404
        result = {'error': f'Error 404. Not found. Can not found a logbook with id: {id}'}
    else:
        Logbook.delete_logbook(log_id)
        result = {'result': f'Status 200. The logbook: {log_id} was deleted.'}
    return Response(json.dumps(result), mimetype=mimetype, status=status)