def image_id_image_get(id_):  # noqa: E501
    """Fetch the image file belonging to the image object identified by the ID in the path.

     # noqa: E501

    :param id_: ID number of the image to fetch.
    :type id_: int

    :rtype: bytearray
    """
    engine = QueryEngine()
    i = engine.query_image(id_)
    if not i:
        return Error('404', f'Image {id_} not found'), 404
    try:
        fname = os.path.join(IMG_DIR, i.file)
        with open(fname, 'rb') as f:
            data = f.read()
    except FileNotFoundError:
        return Error('404', f'Image file not found'), 404
    except PermissionError:
        return Error('404', f'Permission denied'), 403
    response = ConnexionResponse(status_code=200,
                                 mimetype=i.mime,
                                 content_type=f'{i.mime}; charset=binary',
                                 body=data,
                                 headers={})
    return response
def image_put(body):  # noqa: E501
    """Add a new image

     # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: Image
    """
    if connexion.request.is_json:
        body = Image.from_dict(connexion.request.get_json())  # noqa: E501
    engine = QueryEngine()
    result = engine.put_image(body)
    if result:
        return Image(id=result.id), 200
    return Error('400', f'Bad Request'), 400
Example #3
0
def place_pid_image_iid_put(pid, iid):  # noqa: E501
    """Add a link between a place identified by pid and an image indicated by iid.

     # noqa: E501

    :param pid: ID number of the place
    :type pid: int
    :param iid: ID number of the image
    :type iid: int

    :rtype: None
    """
    engine = QueryEngine()
    result = engine.create_place_image_link(pid, iid)
    if result:
        return None, 204
    return Error('400', f'Place {pid} or image {iid} not found'), 400
def document_put(body):  # noqa: E501
    """Add a new document

     # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: Document
    """
    if connexion.request.is_json:
        body = Document.from_dict(connexion.request.get_json())  # noqa: E501
    engine = QueryEngine()
    result = engine.put_document(body)
    if result:
        return Document(id=result.id), 200
    return Error('400', f'Bad Request'), 400
def image_id_patch(body, id_):  # noqa: E501
    """Update the image identified by the ID in the path.

     # noqa: E501

    :param body:
    :type body: dict | bytes
    :param id_: ID number of the image to update.
    :type id_: int

    :rtype: None
    """
    if connexion.request.is_json:
        body = Image.from_dict(connexion.request.get_json())  # noqa: E501
    engine = QueryEngine()
    result = engine.patch_image(id_, body)
    if result:
        return None, 204
    return Error('404', f'Image {id_} not found'), 404
Example #6
0
def place_pid_document_did_put(pid, did, position_in_text):  # noqa: E501
    """Add a link between a place identified by pid and a document indicated by did.

     # noqa: E501

    :param pid: ID number of the place
    :type pid: int
    :param did: ID number of the document
    :type did: int
    :param position_in_text: Position of the reference to a place in the document text.
    :type position_in_text: int

    :rtype: None
    """
    engine = QueryEngine()
    result = engine.create_place_document_link(pid, did, position_in_text)
    if result:
        return None, 204
    return Error('400', f'Place {pid} or document {did} does not exist'), 400
def place_id_get(id_):  # noqa: E501
    """Fetch the place identified by the ID in the path.

     # noqa: E501

    :param id_: ID number of the place to fetch.
    :type id_: int

    :rtype: Place
    """
    engine = QueryEngine()
    p = engine.query_place(id_)
    if not p:
        return Error('404', f'Place {id_} not found'), 404
    return Place(id=p.id,
                 name=p.name,
                 latitude=p.latitude,
                 longitude=p.longitude,
                 wikidata_id=p.wikidata_id)
def document_id_get(id_):  # noqa: E501
    """Fetch the document identified by the ID in the path.

     # noqa: E501

    :param id_: ID number of the document to fetch.
    :type id_: int

    :rtype: Document
    """
    engine = QueryEngine()
    d = engine.query_document(id_)
    if not d:
        return Error('404', f'Document {id_} not found'), 404
    return Document(id=d.id,
                    text=d.text,
                    title=d.title,
                    year=d.year,
                    author=d.author,
                    source=d.source)
def image_id_get(id_):  # noqa: E501
    """Fetch the image identified by the ID in the path.

     # noqa: E501

    :param id_: ID number of the image to fetch.
    :type id_: int

    :rtype: Image
    """
    engine = QueryEngine()
    i = engine.query_image(id_)
    if not i:
        return Error('404', f'Image {id_} not found'), 404
    url = os.path.join(connexion.request.base_url, 'image')
    return Image(id=i.id,
                 url=url,
                 mime=i.mime,
                 caption=i.caption,
                 author=i.author,
                 source=i.source)