コード例 #1
0
async def get_full_address_by_one_house(request: web.Request):
    """
    ---
    description: Get full address by house.
    method: GET
    tags:
        - Houses
    produces:
        - application/json
    parameters:
        - in: path
          name: house_id
          description: House id.
          type: int
          required: true
    responses:
        "200":
            description: Full address object by house.
            content:
                application/json:
                    schema:
                        $ref: "#/components/schemas/FullAddress"
    """

    house_id = int(request.match_info.get("house_id"))

    async with request.app["db"].acquire() as conn:

        full_address = await get_full_address_by_house(conn, house_id=house_id)

    return web.json_response(text=to_json(full_address))
コード例 #2
0
ファイル: district.py プロジェクト: shidenko97/address_api
async def get_one_district(request: web.Request):
    """
    ---
    description: Get district by id.
    method: GET
    tags:
        - Districts
    produces:
        - application/json
    parameters:
        - in: path
          name: district_id
          description: District id.
          type: int
          required: true
    responses:
        "200":
            description: District object.
            content:
                application/json:
                    schema:
                        $ref: "#/components/schemas/District"
    """

    district_id = int(request.match_info.get("district_id"))

    async with request.app["db"].acquire() as conn:

        district_object = await get_district(conn, district_id=district_id)

    return web.json_response(text=to_json(district_object))
コード例 #3
0
ファイル: country.py プロジェクト: shidenko97/address_api
async def get_one_country(request: web.Request):
    """
    ---
    description: Get country by id.
    method: GET
    tags:
        - Countries
    produces:
        - application/json
    parameters:
        - in: path
          name: country_id
          description: Country id.
          type: int
          required: true
    responses:
        "200":
            description: Country object.
            content:
                application/json:
                    schema:
                        $ref: "#/components/schemas/Country"
    """

    country_id = int(request.match_info.get("country_id"))

    async with request.app["db"].acquire() as conn:

        country_object = await get_country(conn, country_id=country_id)

    return web.json_response(text=to_json(country_object))
コード例 #4
0
async def get_one_area(request: web.Request):
    """
    ---
    description: Get area by id.
    method: GET
    tags:
        - Areas
    produces:
        - application/json
    parameters:
        - in: path
          name: area_id
          description: Area id.
          type: int
          required: true
    responses:
        "200":
            description: Area object.
            content:
                application/json:
                    schema:
                        $ref: "#/components/schemas/Area"
    """

    area_id = int(request.match_info.get("area_id"))

    async with request.app["db"].acquire() as conn:

        area_object = await get_area(conn, area_id=area_id)

    return web.json_response(text=to_json(area_object))
コード例 #5
0
async def get_one_region(request: web.Request):
    """
    ---
    description: Get region by id.
    method: GET
    tags:
        - Regions
    produces:
        - application/json
    parameters:
        - in: path
          name: region_id
          description: Region id.
          type: int
          required: true
    responses:
        "200":
            description: Region object.
            content:
                application/json:
                    schema:
                        $ref: "#/components/schemas/Region"
    """

    region_id = int(request.match_info.get("region_id"))

    async with request.app["db"].acquire() as conn:

        region_object = await get_region(conn, region_id=region_id)

    return web.json_response(text=to_json(region_object))
コード例 #6
0
async def all_areas_in_region(request: web.Request):
    """
    ---
    description: Get list of areas by region id.
    tags:
        - Areas
    produces:
        - application/json
    parameters:
        - in: path
          name: region_id
          description: Region for area.
          type: int
          required: true
        - in: query
          name: q
          description: Substring to filter results.
          type: str
          requires: false
        - in: query
          name: limit
          description: Max count of areas in list. Maximum is 200.
          default: 200
          type: int
          requires: false
    responses:
        "200":
            description: List of areas.
            content:
                application/json:
                    schema:
                        type: array
                        items:
                            $ref: "#/components/schemas/Area"
    """

    region_id = int(request.match_info.get("region_id", "0"))

    q = request.rel_url.query.get("q")
    limit = int(request.rel_url.query.get("limit", "0"))

    async with request.app["db"].acquire() as conn:

        if q:
            areas_objects = await get_areas_in_region_by_substring(
                conn, region_id=region_id, substring=q, limit=limit
            )
        else:
            areas_objects = await get_all_areas_in_region(
                conn, region_id=region_id, limit=limit
            )

    return web.json_response(text=to_json(areas_objects))
コード例 #7
0
ファイル: country.py プロジェクト: shidenko97/address_api
async def all_countries(request: web.Request):
    """
    ---
    description: Get list of countries.
    tags:
        - Countries
    produces:
        - application/json
    parameters:
        - in: query
          name: q
          description: Substring to filter results.
          type: str
          requires: false
        - in: query
          name: limit
          description: Max count of countries in list. Maximum is 200.
          default: 200
          type: int
          requires: false
    responses:
        "200":
            description: Country object.
            content:
                application/json:
                    schema:
                        type: array
                        items:
                            $ref: "#/components/schemas/Country"
    """

    q = request.match_info.get("q")
    limit = int(request.match_info.get("limit", "0"))

    async with request.app["db"].acquire() as conn:

        if q:
            countries_objects = await get_countries_by_substring(conn,
                                                                 substring=q,
                                                                 limit=limit)
        else:
            countries_objects = await get_all_countries(conn, limit=limit)

    return web.json_response(text=to_json(countries_objects))