Skip to content

Commit 6a1f76e

Browse files
committed
Initial commit
0 parents  commit 6a1f76e

27 files changed

Lines changed: 1735 additions & 0 deletions
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Update version and create release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- master
8+
9+
jobs:
10+
11+
fetch-version:
12+
if: github.event.pull_request.merged
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Fetch latest release version
17+
id: fetch-latest-release
18+
uses: reloc8/action-latest-release-version@1.0.0
19+
- uses: actions/setup-python@v2
20+
with:
21+
python-version: 3.7
22+
- name: Choose new release version
23+
id: choose-release-version
24+
uses: reloc8/action-choose-release-version@1.0.0
25+
with:
26+
source-branch: ${{ github.event.pull_request.head.ref }}
27+
latest-version: ${{ steps.fetch-latest-release.outputs.latest-release }}
28+
outputs:
29+
new-version: ${{ steps.choose-release-version.outputs.new-version }}
30+
31+
update-version:
32+
needs: fetch-version
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v2
36+
- run: git pull --ff-only
37+
- name: Update version file
38+
run: echo ${{ needs.fetch-version.outputs.new-version }} > version
39+
- name: Push local repository changes
40+
id: push-local-repository-changes
41+
uses: reloc8/action-push-local-changes@1.0.0
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
with:
45+
commit-message: "Version ${{ needs.fetch-version.outputs.new-version }}"
46+
outputs:
47+
commit-hash: ${{ steps.push-local-repository-changes.outputs.commit-hash }}
48+
49+
create-release:
50+
needs: [fetch-version, update-version]
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v2
54+
- run: git pull --ff-only
55+
- name: Create new release
56+
uses: actions/create-release@v1
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
with:
60+
tag_name: ${{ needs.fetch-version.outputs.new-version }}
61+
release_name: ${{ needs.fetch-version.outputs.new-version }}
62+
draft: false
63+
prerelease: false
64+
commitish: ${{ needs.update-version.outputs.commit-hash }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.idea
3+
.venv
4+
*.egg-info

LICENSE.txt

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Development
2+
3+
1. Create a virtual environment:
4+
5+
`$ python3 -m venv .venv`
6+
7+
2. Activate the created environment:
8+
9+
`$ source .venv/bin/activate`
10+
11+
3. Upgrade `pip`:
12+
13+
`$ python3 -m pip install --upgrade pip`
14+
15+
4. Install the requirements:
16+
17+
`$ pip install --upgrade -r requirements.txt`
18+
19+
5. Mark the main package as Sources Root.
20+
21+
## Test
22+
23+
1. Install the testing requirements:
24+
25+
`$ pip install --upgrade -r requirements-test.txt`
26+
27+
2. Run all tests in package `tests`

fetch_properties/__init__.py

Whitespace-only changes.

fetch_properties/core/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import graphene
2+
import logging
3+
from dataclasses import dataclass
4+
from typing import Any, AnyStr, Dict
5+
6+
from .mongodb import MongoDBConnection
7+
from .schema.query import MongoDBQuery
8+
9+
10+
@dataclass
11+
class FetchPropertiesLambdaCore:
12+
13+
logger: logging.Logger
14+
mongodb_connection: MongoDBConnection
15+
16+
@staticmethod
17+
def query(query: AnyStr) -> Dict[AnyStr, Any]:
18+
19+
graphql_schema = graphene.Schema(query=MongoDBQuery)
20+
result = graphql_schema.execute(query)
21+
return result.to_dict()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import json
2+
import logging
3+
from dataclasses import dataclass
4+
from typing import Any, AnyStr, Dict
5+
6+
from lambda_handler import LambdaHandler
7+
from .. import FetchPropertiesLambdaCore
8+
from ..mongodb import MongoDBConnection, MONGODB_CONNECTION
9+
10+
11+
@dataclass(init=False)
12+
class FetchPropertiesLambda(LambdaHandler):
13+
14+
logger: logging.Logger
15+
mongodb_connection: MongoDBConnection
16+
17+
def __init__(self, logger, mongodb_connection):
18+
19+
super().__init__(logger=logger)
20+
self.mongodb_connection = mongodb_connection
21+
self.core = FetchPropertiesLambdaCore(
22+
logger=self.logger,
23+
mongodb_connection=mongodb_connection
24+
)
25+
26+
def run(self, event: Any, context: Any) -> Dict[AnyStr, Any]:
27+
28+
query = event['queryStringParameters'].get('query')
29+
response_body = self.core.query(query=query)
30+
31+
return dict(
32+
statusCode=200,
33+
body=json.dumps(response_body),
34+
isBase64Encoded=False
35+
)
36+
37+
38+
LAMBDA_HANDLER = FetchPropertiesLambda(
39+
logger=logging.getLogger(),
40+
mongodb_connection=MONGODB_CONNECTION
41+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from typing import Any, AnyStr, Dict, List
2+
3+
from ..schema import Property, PropertyLocation, PropertiesPage
4+
5+
6+
class PropertyMapper:
7+
8+
@staticmethod
9+
def map(property: Dict[AnyStr, Any]) -> Property:
10+
11+
cursor = property.get('cursor')
12+
price = property.get('price')
13+
location = property.get('location')
14+
15+
property_location = PropertyLocation()
16+
property_location.latitude = location.get('point').get('coordinates')[1]
17+
property_location.longitude = location.get('point').get('coordinates')[0]
18+
property_location.geohash = location.get('geohash')
19+
20+
mapped = Property()
21+
mapped.id = cursor
22+
mapped.price = price
23+
mapped.location = property_location
24+
25+
return mapped
26+
27+
28+
class PropertiesPageMapper:
29+
30+
@staticmethod
31+
def map(properties: List[Property]) -> PropertiesPage:
32+
33+
properties_page = PropertiesPage()
34+
properties_page.properties = properties
35+
properties_page.page = properties[-1].id
36+
37+
return properties_page
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os
2+
from dataclasses import dataclass
3+
from typing import AnyStr
4+
5+
6+
MONGODB_URI = os.getenv('MONGODB_URI')
7+
MONGODB_DATABASE = 'timeSeriesDB'
8+
MONGODB_COLLECTION = 'properties'
9+
10+
11+
@dataclass
12+
class MongoDBConnection:
13+
14+
uri: AnyStr
15+
database: AnyStr
16+
collection: AnyStr
17+
18+
19+
MONGODB_CONNECTION = MongoDBConnection(
20+
uri=MONGODB_URI,
21+
database=MONGODB_DATABASE,
22+
collection=MONGODB_COLLECTION
23+
)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import graphene
2+
3+
4+
class PropertyLocation(graphene.ObjectType):
5+
6+
latitude = graphene.Float()
7+
longitude = graphene.Float()
8+
geohash = graphene.String()
9+
10+
11+
class Property(graphene.ObjectType):
12+
13+
id = graphene.String()
14+
price = graphene.Int()
15+
location = graphene.Field(PropertyLocation)
16+
17+
18+
class PropertiesPage(graphene.ObjectType):
19+
20+
properties = graphene.List(Property)
21+
page = graphene.String()
22+
23+
24+
class Point(graphene.InputObjectType):
25+
26+
latitude = graphene.Float()
27+
longitude = graphene.Float()
28+
29+
30+
class BoundingBox(graphene.InputObjectType):
31+
32+
bottom_left = graphene.InputField(Point)
33+
top_right = graphene.InputField(Point)
34+
35+
36+
class IntRange(graphene.InputObjectType):
37+
38+
min = graphene.Int()
39+
max = graphene.Int()
40+
41+
42+
class PropertyFilter(graphene.InputObjectType):
43+
44+
n_rooms = graphene.InputField(IntRange)
45+
surface = graphene.InputField(IntRange)
46+
condition = graphene.String()

0 commit comments

Comments
 (0)