Exemplo n.º 1
0
def place_id_images_get(id_):  # noqa: E501
    """Find images related to the place indicated by the ID in the path.

     # noqa: E501

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

    :rtype: ArrayOfImages
    """
    engine = QueryEngine()
    place = engine.query_place(id_)
    result = engine.query_images_for_place(place)
    results = []
    for r in result:
        if isinstance(r, str):
            i = Image(url=r)
        else:
            url = connexion.request.base_url.replace(f'/place/{id_}/images',
                                                     f'/image/{r.id}/image')
            i = Image(id=r.id,
                      url=url,
                      mime=r.mime,
                      caption=r.caption,
                      author=r.author,
                      source=r.source)
        results.append(i)
    return results
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
    def test_image_put(self):
        """Test case for image_put

        Add a new image
        """
        body = Image()
        response = self.client.open('/image',
                                    method='PUT',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_image_id_patch(self):
        """Test case for image_id_patch

        Update the image identified by the ID in the path.
        """
        body = Image()
        response = self.client.open('/image/{id}'.format(id=56),
                                    method='PATCH',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
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
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)