Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
where
Commits
8f3ce9f1
Commit
8f3ce9f1
authored
Feb 23, 2020
by
Zach Perkins
Browse files
split endpoint view functions based on request method
parent
86f6d008
Changes
1
Hide whitespace changes
Inline
Side-by-side
where/app.py
View file @
8f3ce9f1
...
@@ -3,6 +3,8 @@ from flask import Flask, redirect, jsonify, abort, request, url_for, make_respon
...
@@ -3,6 +3,8 @@ from flask import Flask, redirect, jsonify, abort, request, url_for, make_respon
from
where.model
import
with_session
,
Point
,
Category
,
Field
from
where.model
import
with_session
,
Point
,
Category
,
Field
from
where.model.field_types
import
FieldType
from
where.model.field_types
import
FieldType
from
where.validation
import
PointSchema
,
CategorySchema
,
FieldSchema
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
...
@@ -116,27 +118,36 @@ def get_category_children(session, id):
...
@@ -116,27 +118,36 @@ def get_category_children(session, id):
return
search_resource
(
session
,
Point
,
data
)
return
search_resource
(
session
,
Point
,
data
)
@
app
.
route
(
'/point'
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
'/point'
,
methods
=
[
'GET'
])
@
with_session
@
with_session
def
handle_point
(
session
):
def
search_point
(
session
):
if
request
.
method
==
'GET'
:
return
search_resource
(
session
,
Point
,
dict
(
request
.
args
))
return
search_resource
(
session
,
Point
,
dict
(
request
.
args
))
elif
request
.
method
==
'POST'
:
data
=
request
.
get_json
()
@
app
.
route
(
'/point'
,
methods
=
[
'POST'
])
data
[
'category'
]
=
session
.
query
(
Category
).
get
(
data
.
pop
(
'category_id'
))
def
create_point
(
session
):
data
=
request
.
get_json
()
return
create_resource
(
session
,
Point
,
data
,
'get_point'
)
data
[
'category'
]
=
session
.
query
(
Category
).
get
(
data
.
pop
(
'category_id'
))
return
create_resource
(
session
,
Point
,
data
,
'get_point'
)
@
app
.
route
(
'/point/<id>'
,
methods
=
[
'GET'
,
'PUT'
,
'DELETE'
])
@
app
.
route
(
'/point/<id>'
,
methods
=
[
'GET'
])
@
with_session
@
with_session
def
get_point
(
session
,
id
):
def
get_point
(
session
,
id
):
if
request
.
method
==
'GET'
:
return
get_resource
(
session
,
Point
,
id
)
return
get_resource
(
session
,
Point
,
id
)
elif
request
.
method
==
'DELETE'
:
return
delete_resource
(
session
,
Point
,
id
)
@
app
.
route
(
'/point/<id>'
,
methods
=
[
'DELETE'
])
elif
request
.
method
==
'PUT'
:
@
with_session
return
edit_resource
(
session
,
Point
,
id
,
request
.
get_json
())
def
del_point
(
session
,
id
):
return
delete_resource
(
session
,
Point
,
id
)
@
app
.
route
(
'/point/<id>'
,
methods
=
[
'PUT'
])
@
with_session
def
edit_point
(
session
,
id
):
return
edit_resource
(
session
,
Point
,
id
,
request
.
get_json
())
@
app
.
route
(
'/point/<id>/children'
,
methods
=
[
'GET'
])
@
app
.
route
(
'/point/<id>/children'
,
methods
=
[
'GET'
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment