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
f5949869
Commit
f5949869
authored
5 months ago
by
Noah Jefferson Baumann
Browse files
Options
Downloads
Patches
Plain Diff
fixed models.py to remove edges id
parent
000b0512
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/app.py
+9
-2
9 additions, 2 deletions
backend/app.py
backend/models.py
+7
-4
7 additions, 4 deletions
backend/models.py
with
16 additions
and
6 deletions
backend/app.py
+
9
−
2
View file @
f5949869
from
flask
import
Flask
,
jsonify
,
request
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.orm
import
sessionmaker
,
scoped_session
from
sqlalchemy
import
create_engine
from
backend.models
import
Node
,
Edge
from
dotenv
import
load_dotenv
...
...
@@ -19,8 +19,10 @@ DATABASE_URL = os.getenv('DATABASE_URL')
if
not
DATABASE_URL
:
raise
ValueError
(
"
DATABASE_URL is not set in the environment variables
"
)
# Create engine and session factory
engine
=
create_engine
(
DATABASE_URL
)
Session
=
sessionmaker
(
bind
=
engine
)
session_factory
=
sessionmaker
(
bind
=
engine
)
Session
=
scoped_session
(
session_factory
)
@app.route
(
'
/nodes
'
,
methods
=
[
'
GET
'
])
def
get_nodes
():
...
...
@@ -50,5 +52,10 @@ def get_edges():
except
Exception
as
e
:
return
jsonify
({
'
error
'
:
str
(
e
)}),
500
# Ensure scoped_session is removed after each request
@app.teardown_appcontext
def
remove_session
(
exception
=
None
):
Session
.
remove
()
if
__name__
==
'
__main__
'
:
app
.
run
(
debug
=
True
)
This diff is collapsed.
Click to expand it.
backend/models.py
+
7
−
4
View file @
f5949869
from
sqlalchemy
import
Column
,
Integer
,
Float
,
String
from
sqlalchemy
import
Column
,
Integer
,
Float
,
String
,
PrimaryKeyConstraint
from
sqlalchemy.ext.declarative
import
declarative_base
Base
=
declarative_base
()
...
...
@@ -29,10 +29,10 @@ class Node(Base):
'
district
'
:
self
.
district
}
# Example for Edge model
# Example for Edge model
with composite primary key
class
Edge
(
Base
):
__tablename__
=
'
edges
'
id
=
Column
(
String
,
primary_key
=
True
)
source
=
Column
(
String
)
target
=
Column
(
String
)
label
=
Column
(
String
)
...
...
@@ -43,9 +43,12 @@ class Edge(Base):
distance
=
Column
(
Float
)
edge_type
=
Column
(
String
)
__table_args__
=
(
PrimaryKeyConstraint
(
'
source
'
,
'
target
'
),
)
def
to_dict
(
self
):
return
{
'
id
'
:
self
.
id
,
'
source
'
:
self
.
source
,
'
target
'
:
self
.
target
,
'
label
'
:
self
.
label
,
...
...
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