Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
berlin-mapping-application
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Noah Jefferson Baumann
berlin-mapping-application
Commits
681814c8
Commit
681814c8
authored
5 months ago
by
Noah Jefferson Baumann
Browse files
Options
Downloads
Patches
Plain Diff
reverting flask to previous version which should work with new database
parent
230ba3d8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backend/app.py
+21
-41
21 additions, 41 deletions
backend/app.py
with
21 additions
and
41 deletions
backend/app.py
+
21
−
41
View file @
681814c8
from
flask
import
Flask
,
jsonify
,
request
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy
import
create_engine
from
backend.
models
import
Node
,
Edge
from
models
import
Node
,
Edge
from
dotenv
import
load_dotenv
import
os
from
flask_cors
import
CORS
# Load environment variables from .env file
load_dotenv
()
app
=
Flask
(
__name__
)
# Enable CORS for all routes and origins
CORS
(
app
)
# Get the database URL from the environment
DATABASE_URL
=
os
.
getenv
(
'
DATABASE_URL
'
)
if
not
DATABASE_URL
:
raise
ValueError
(
"
DATABASE_URL is not set in the environment variables
"
)
# Setup the engine and sessionmaker
engine
=
create_engine
(
DATABASE_URL
)
Session
=
sessionmaker
(
bind
=
engine
)
@app.route
(
'
/
graph
'
,
methods
=
[
'
GET
'
])
def
get_
graph
():
@app.route
(
'
/
nodes
'
,
methods
=
[
'
GET
'
])
def
get_
nodes
():
try
:
year
=
request
.
args
.
get
(
'
year
'
)
if
year
:
year
=
int
(
year
)
with
Session
()
as
session
:
# Fetch nodes
nodes
=
session
.
query
(
Node
).
filter
(
Node
.
year
==
year
).
all
()
query
=
session
.
query
(
Node
)
if
year
:
query
=
query
.
filter
(
Node
.
year
==
year
)
nodes
=
query
.
all
()
node_list
=
[
node
.
to_dict
()
for
node
in
nodes
]
# Fetch edges
edges
=
session
.
query
(
Edge
).
filter
(
Edge
.
year
==
year
).
all
()
edge_list
=
[]
for
edge
in
edges
:
source_node
=
session
.
query
(
Node
).
filter
(
Node
.
id
==
edge
.
source
).
one_or_none
()
target_node
=
session
.
query
(
Node
).
filter
(
Node
.
id
==
edge
.
target
).
one_or_none
()
if
source_node
and
target_node
:
edge_list
.
append
({
"
id
"
:
edge
.
id
,
"
label
"
:
edge
.
label
,
"
source
"
:
{
"
id
"
:
edge
.
source
,
"
x
"
:
source_node
.
x
,
"
y
"
:
source_node
.
y
},
"
target
"
:
{
"
id
"
:
edge
.
target
,
"
x
"
:
target_node
.
x
,
"
y
"
:
target_node
.
y
},
"
edge_type
"
:
edge
.
edge_type
,
"
distance
"
:
edge
.
distance
,
"
year
"
:
edge
.
year
})
return
jsonify
({
"
nodes
"
:
node_list
,
"
edges
"
:
edge_list
})
return
jsonify
(
node_list
)
except
Exception
as
e
:
return
jsonify
({
'
error
'
:
str
(
e
)}),
500
@app.route
(
'
/edges
'
,
methods
=
[
'
GET
'
])
def
get_edges
():
try
:
year
=
request
.
args
.
get
(
'
year
'
)
with
Session
()
as
session
:
query
=
session
.
query
(
Edge
)
if
year
:
query
=
query
.
filter
(
Edge
.
year
==
year
)
edges
=
query
.
all
()
edge_list
=
[
edge
.
to_dict
()
for
edge
in
edges
]
return
jsonify
(
edge_list
)
except
Exception
as
e
:
return
jsonify
({
'
error
'
:
str
(
e
)}),
500
if
__name__
==
'
__main__
'
:
app
.
run
(
debug
=
True
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment