Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Salamander - API
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Herman Andersen Dyrkorn
Salamander - API
Merge requests
!4
Resolve "creating database flask-sqlalchemy"
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Resolve "creating database flask-sqlalchemy"
3-creating-database-flask-sqlalchemy
into
master
Overview
0
Commits
6
Pipelines
0
Changes
1
Merged
Herman Andersen Dyrkorn
requested to merge
3-creating-database-flask-sqlalchemy
into
master
4 years ago
Overview
0
Commits
6
Pipelines
0
Changes
1
Closes
#3 (closed)
Edited
4 years ago
by
Herman Andersen Dyrkorn
0
0
Merge request reports
Viewing commit
4e0fd9d3
Prev
Next
Show latest version
1 file
+
33
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
4e0fd9d3
setting up all tables and sqlalchemy config
· 4e0fd9d3
Herman Andersen Dyrkorn
authored
4 years ago
src/main.py
+
33
−
1
View file @ 4e0fd9d3
Edit in single-file editor
Open in Web IDE
Show full file
from
flask
import
Flask
,
request
from
flask_restful
import
Api
,
Resource
import
os.path
from
datetime
import
datetime
from
flask_sqlalchemy
import
SQLAlchemy
app
=
Flask
(
__name__
)
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
=
'
sqlite:///database.db
'
db
=
SQLAlchemy
(
app
)
api
=
Api
(
app
)
class
User
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
name
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
email
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
pwd
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
class
Salamander
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
sex
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
species
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
location
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
location_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'
location.id
'
),
nullable
=
False
)
image_path
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
uid
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'
user.id
'
),
nullable
=
False
)
date
=
db
.
Column
(
db
.
DateTime
,
default
=
datetime
.
now
)
class
Location
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
name
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
coordinates
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
pwd
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
radius
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
# matchSalamander endpoint
class
MatchSalamander
(
Resource
):
@staticmethod
def
post
():
@@ -40,6 +72,7 @@ class MatchSalamander(Resource):
return
output
# findSalamanderInfo endpoint
class
FindSalamanderInfo
(
Resource
):
@staticmethod
def
post
():
@@ -63,7 +96,6 @@ def get_path(data, end_directory):
def
directory_not_empty
(
directory_path
):
if
os
.
path
.
exists
(
directory_path
)
and
not
os
.
path
.
isfile
(
directory_path
):
# Checking if the directory is empty or not
if
not
os
.
listdir
(
directory_path
):
return
False
Loading