feat: ✨ implemented pwa capabillities and refactored lots of backend things
This commit is contained in:
55
app.py
55
app.py
@@ -1,20 +1,59 @@
|
||||
from gpxInterpreter import GPXHandler
|
||||
from dotenv import load_dotenv
|
||||
from flask import Flask, send_from_directory, jsonify, session, request
|
||||
from flask import Flask, send_from_directory, jsonify, request
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
print("load environment")
|
||||
load_dotenv()
|
||||
Session: Session
|
||||
app: any
|
||||
|
||||
print("create flask application")
|
||||
app = Flask(__name__, static_folder='web/dist')
|
||||
def entry():
|
||||
print("load environment")
|
||||
load_dotenv()
|
||||
|
||||
print("create flask application")
|
||||
app = Flask(__name__, static_folder='web/dist')
|
||||
|
||||
# TODO: all the sqlalchemy stuff should be moved out of app.py
|
||||
Base = declarative_base()
|
||||
|
||||
def db_connect(connectionPath):
|
||||
return create_engine(connectionPath, poolclass=NullPool)
|
||||
|
||||
Base.metadata.create_all(db_connect)
|
||||
session = sessionmaker(bind=db_connect())()
|
||||
|
||||
# handler class for all gpx files
|
||||
# handles parsing files and interacting with database
|
||||
gpxHandler = GPXHandler(session)
|
||||
|
||||
app.run(debug=True)
|
||||
|
||||
# TODO: move functional parts out to api package if not handled by other classes
|
||||
@app.route('/')
|
||||
def serve_vue_app():
|
||||
return send_from_directory(app.static_folder, 'index.html')
|
||||
|
||||
@app.route("/route", method=['GET'])
|
||||
def getRoute():
|
||||
# TODO: will contact gpx handler to get geoJSON from
|
||||
return "not implemented", 500
|
||||
|
||||
@app.route('/upload', methods=['POST'])
|
||||
def upload_file():
|
||||
file = request.files['file']
|
||||
def uploadFile():
|
||||
if 'file' not in request.files:
|
||||
return "no file provided", 400
|
||||
|
||||
file = request.files['file']
|
||||
if file.filename == '':
|
||||
return "no file selected", 400
|
||||
|
||||
try:
|
||||
gpx_handler = GPXHandler(file.stream)
|
||||
gpx_handler.parse()
|
||||
return "file stored succesfull", 200
|
||||
except Exception as e:
|
||||
return "error" + " " + str(e), 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
entry()
|
||||
Reference in New Issue
Block a user