-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
81 lines (56 loc) · 2.09 KB
/
app.py
File metadata and controls
81 lines (56 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
from dotenv import load_dotenv
from route import RoutePlan
load_dotenv() # reads .env into environment
from flask import Flask, request, jsonify
from topographic import TopographicPlan
from cadastral import CadastralPlan
from layout import LayoutPlan
app = Flask(__name__)
app.config["SECRET_KEY"] = "secret"
@app.get("/")
def home():
return "<h1>Hello, Flask 👋</h1><p>You're up and running!</p>"
@app.route("/cadastral/plan", methods=["POST"])
def generate_cadastral_plan():
data = request.get_json()
plan = CadastralPlan(**data)
plan.draw()
url = plan.save()
return jsonify({"message": "Cadastral plan generated", "filename": plan.name, "url": url}), 200
@app.route("/topographic/plan", methods=["POST"])
def generate_topographic_plan():
data = request.get_json()
plan = TopographicPlan(**data)
plan.draw()
url = plan.save()
return jsonify({"message": "Topographic plan generated", "filename": plan.name, "url": url}), 200
@app.route("/layout/plan", methods=["POST"])
def generate_layout_plan():
data = request.get_json()
plan = LayoutPlan(**data)
plan.draw()
url = plan.save()
return jsonify({"message": "Layout plan generated", "filename": plan.name, "url": url}), 200
@app.route("/route/plan", methods=["POST"])
def generate_route_plan():
data = request.get_json()
plan = RoutePlan(**data)
plan.draw()
url = plan.save()
return jsonify({"message": "Route plan generated", "filename": plan.name, "url": url}), 200
@app.errorhandler(404)
def not_found(e):
return jsonify({"error": "Resource not found"}), 404
@app.errorhandler(500)
def internal_error(e):
return jsonify({"error": "Something went wrong on our side"}), 500
@app.errorhandler(Exception)
def handle_exception(e):
# You can log the exception here
app.logger.error(f"Unhandled Exception: {e}", exc_info=True)
# Return JSON response instead of crashing
return jsonify({"error": "An unexpected error occurred"}), 500
if __name__ == '__main__':
port = int(os.environ.get("PORT", 8080))
app.run(host="0.0.0.0", port=port)