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
Commits
68cfb0ce
Commit
68cfb0ce
authored
Feb 10, 2021
by
Herman Andersen Dyrkorn
Browse files
Options
Downloads
Plain Diff
Merge branch '3-creating-database-flask-sqlalchemy' into 'master'
Resolve "creating database flask-sqlalchemy" Closes
#3
See merge request
!4
parents
3e599458
b1926bf0
No related branches found
No related tags found
1 merge request
!4
Resolve "creating database flask-sqlalchemy"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
src/main.py
+55
-1
55 additions, 1 deletion
src/main.py
with
57 additions
and
2 deletions
.gitignore
+
2
−
1
View file @
68cfb0ce
venv
venv
.idea
.idea
images
images
src/__pycache__
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main.py
+
55
−
1
View file @
68cfb0ce
from
flask
import
Flask
,
request
from
flask
import
Flask
,
request
from
flask_restful
import
Api
,
Resource
from
flask_restful
import
Api
,
Resource
import
os.path
import
os.path
from
datetime
import
datetime
from
flask_sqlalchemy
import
SQLAlchemy
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
=
'
sqlite:///database.db
'
db
=
SQLAlchemy
(
app
)
api
=
Api
(
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
)
admin
=
db
.
Column
(
db
.
Boolean
,
nullable
=
False
,
default
=
False
)
accepted
=
db
.
Column
(
db
.
Boolean
,
nullable
=
False
,
default
=
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
):
class
MatchSalamander
(
Resource
):
@staticmethod
@staticmethod
def
post
():
def
post
():
...
@@ -40,6 +74,7 @@ class MatchSalamander(Resource):
...
@@ -40,6 +74,7 @@ class MatchSalamander(Resource):
return
output
return
output
# findSalamanderInfo endpoint
class
FindSalamanderInfo
(
Resource
):
class
FindSalamanderInfo
(
Resource
):
@staticmethod
@staticmethod
def
post
():
def
post
():
...
@@ -53,6 +88,26 @@ class FindSalamanderInfo(Resource):
...
@@ -53,6 +88,26 @@ class FindSalamanderInfo(Resource):
return
output
return
output
class
RegisterUser
(
Resource
):
@staticmethod
def
post
():
output
=
{
"
message
"
:
"
something went wrong
"
}
data
=
request
.
form
if
not
data
[
'
name
'
]
or
not
data
[
'
email
'
]
or
not
data
[
'
password
'
]
or
not
data
[
'
confirmPassword
'
]:
output
=
{
"
message
"
:
"
data is incorrect
"
}
else
:
if
data
[
'
password
'
]
==
data
[
'
confirmPassword
'
]:
user
=
User
(
name
=
data
[
'
name
'
],
email
=
data
[
'
email
'
],
pwd
=
data
[
'
password
'
])
db
.
session
.
add
(
user
)
db
.
session
.
commit
()
output
=
{
"
message
"
:
"
user added
"
}
return
output
api
.
add_resource
(
RegisterUser
,
"
/registerUser
"
)
api
.
add_resource
(
MatchSalamander
,
"
/matchSalamander
"
)
api
.
add_resource
(
MatchSalamander
,
"
/matchSalamander
"
)
api
.
add_resource
(
FindSalamanderInfo
,
"
/findSalamanderInfo
"
)
api
.
add_resource
(
FindSalamanderInfo
,
"
/findSalamanderInfo
"
)
...
@@ -63,7 +118,6 @@ def get_path(data, end_directory):
...
@@ -63,7 +118,6 @@ def get_path(data, end_directory):
def
directory_not_empty
(
directory_path
):
def
directory_not_empty
(
directory_path
):
if
os
.
path
.
exists
(
directory_path
)
and
not
os
.
path
.
isfile
(
directory_path
):
if
os
.
path
.
exists
(
directory_path
)
and
not
os
.
path
.
isfile
(
directory_path
):
# Checking if the directory is empty or not
# Checking if the directory is empty or not
if
not
os
.
listdir
(
directory_path
):
if
not
os
.
listdir
(
directory_path
):
return
False
return
False
...
...
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