]> git.xn--bdkaa.com Git - where-are-you.py.git/commitdiff
Set correct map boundaries
authorzharkovstas <zharkovstas@skbkontur.ru>
Sun, 19 May 2019 06:08:32 +0000 (11:08 +0500)
committerzharkovstas <zharkovstas@skbkontur.ru>
Sun, 19 May 2019 06:08:32 +0000 (11:08 +0500)
app.py
config/webpackDevServer.config.js
src/Game.js
src/GameController.js
src/api.js
src/createMap.js

diff --git a/app.py b/app.py
index 52cf996f26b17cf07010f778cdad12b410568b0e..a6dad3f8e566c13dfcad44290cb77c85dfa63daa 100644 (file)
--- a/app.py
+++ b/app.py
@@ -100,7 +100,8 @@ def add_tips(game):
         type = convert_sightseeing_type(s['type'])
         direction = get_direction(coordinate, (s['lat'], s['lon']))
         game.tips.append(
-            f'Кстати, неподалеку на {convert_direction(direction)}е есть ' + (type if type else 'интересный туристический объект') + ': ' + s["name"])
+            f'Кстати, неподалеку на {convert_direction(direction)}е есть ' + (
+                type if type else 'интересный туристический объект') + ': ' + s["name"])
 
     shuffle(game.tips)
 
@@ -228,8 +229,10 @@ def get_games():
     }
 
 
-def handle_post_game(city_id):
+@post('/api/games')
+def post_game():
     game_id = str(uuid.uuid4())
+    city_id = request.json['city'] or 'Екатеринбург'
     if city_id not in cities:
         return bottle.HTTPResponse(status=404, body='city not found')
 
@@ -253,18 +256,6 @@ def handle_post_game(city_id):
     }
 
 
-@post('/api/games')
-@enable_cors
-def post_game_without_city():
-    return handle_post_game('Екатеринбург')
-
-
-@post('/api/games/<city>')
-@enable_cors
-def post_game(city):
-    return handle_post_game(city)
-
-
 @get('/api/games/<game_id>')
 @enable_cors
 def get_game(game_id):
@@ -326,7 +317,6 @@ def move(game_id, direction):
 
     has_more = len([tip for tip in game.tips if tip not in game.shown_tips]) > 0
 
-
     return {'tips': game.shown_tips, 'hasMore': has_more}
 
 
@@ -392,10 +382,10 @@ def static_media(staticFile):
 def index(whatever):
     return static_file('index.html', "build")
 
+
 application = bottle.default_app()
 from paste import httpserver
 
-
 if os.environ.get('APP_LOCATION') == 'heroku':
     httpserver.serve(application, host='0.0.0.0', port=int(os.environ.get("PORT", 5000)))
 else:
index 33ab8d3a9d29007b852896bad3c03db1da8aa692..8afbb3118f0ff490bc9f4d981fc5e4376d455a67 100644 (file)
@@ -81,7 +81,9 @@ module.exports = function(proxy, allowedHost) {
       disableDotRule: true,
     },
     public: allowedHost,
-    proxy,
+    proxy: {
+        '/api': {target: 'http://localhost:8080/'}
+    },
     before(app, server) {
       if (fs.existsSync(paths.proxySetup)) {
         // This registers user provided middleware for proxy reasons
index 49f4a452611f60ce933878a815e274dc2bb8231b..e1eb68b59c1a1114c790c949c7a6dcc87b697c1c 100644 (file)
@@ -27,14 +27,14 @@ export class Game extends Component {
   }
 
   componentDidMount() {
-    this.gameController.createGame().then(() => this.gameController.loadTips()).then(() => {
+    this.gameController.createGame('Екатеринбург').then(() => this.gameController.loadTips()).then(() => {
       this.setState({
         tips: this.handleVarlamov(this.gameController.tips()),
         hasMoreTips: this.gameController.hasMoreTips(),
         loading: false,
         inProcess: false
       }, () => {
-        createMap('map', this.onMapClick);
+        createMap('map', this.onMapClick, this.gameController.getBoundaries());
       })
     }).catch(error => {
       this.notification.show(
index ad44d7538898e82d0902cda2f3ff4c936679d364..6452382db063ddede26af46b65784b7a3ac29571 100644 (file)
@@ -6,9 +6,13 @@ export class GameController {
     this.notification = notification;
   }
 
-  createGame() {
-    return api.post('/games').then(json => {
+  createGame(city) {
+    return api.post('/games', {city: city}).then(json => {
       this.gameId = json.data.game_id;
+      this.minLat = json.data.min_lat;
+      this.maxLat = json.data.max_lat;
+      this.minLon = json.data.min_lon;
+      this.maxLon = json.data.max_lon;
     });
   }
 
@@ -75,4 +79,8 @@ export class GameController {
   tryFinish(ltLng) {
     return api.post(`/games/${this.gameId}/finish/${ltLng}`);
   }
+
+  getBoundaries() {
+    return [[this.minLat, this.minLon], [this.maxLat, this.maxLon]];
+  }
 }
index 5c21ea78330c8df6c7ae30cef4caa933630c14e4..ba0ad0e067329ed4e3e4d9e17b539c621904aaeb 100644 (file)
@@ -1,6 +1,6 @@
 import * as axios from 'axios';
 
 export const api = axios.create({
-  baseURL: process.env.NODE_ENV === 'production' ? '/api/': 'http://localhost:8080/api/',
-  timeout: 30000
+  baseURL: process.env.NODE_ENV === 'production' ? '/api/': '/api/',
+  timeout: 60000
 });
\ No newline at end of file
index dac78e47b17d6a87b30d1d066b9f6470a7acaa54..5d8ca593630cf1c24013c2ab018bd6618170d3f0 100644 (file)
@@ -5,11 +5,11 @@ const ekb = {
   SW: ['56.768982', '60.491112']
 };
 
-export function createMap(elementId, onMapClick) {
-  const neLat = ekb.NE[0];
-  const neLng = ekb.NE[1];
-  const swLat = ekb.SW[0];
-  const swLng = ekb.SW[1];
+export function createMap(elementId, onMapClick, boundaries) {
+  const neLat = boundaries[0][0];
+  const neLng = boundaries[0][1];
+  const swLat = boundaries[1][0];
+  const swLng = boundaries[1][1];
 
   const map = new L.Map(elementId);