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
Ross I Kinsey
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
Show 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
from
where.model
import
with_session
,
Point
,
Category
,
Field
from
where.model.field_types
import
FieldType
from
where.validation
import
PointSchema
,
CategorySchema
,
FieldSchema
app
=
Flask
(
__name__
)
...
...
@@ -116,26 +118,35 @@ def get_category_children(session, id):
return
search_resource
(
session
,
Point
,
data
)
@
app
.
route
(
'/point'
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
'/point'
,
methods
=
[
'GET'
])
@
with_session
def
handle_point
(
session
):
if
request
.
method
==
'GET'
:
def
search_point
(
session
):
return
search_resource
(
session
,
Point
,
dict
(
request
.
args
))
elif
request
.
method
==
'POST'
:
@
app
.
route
(
'/point'
,
methods
=
[
'POST'
])
def
create_point
(
session
):
data
=
request
.
get_json
()
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
def
get_point
(
session
,
id
):
if
request
.
method
==
'GET'
:
return
get_resource
(
session
,
Point
,
id
)
elif
request
.
method
==
'DELETE'
:
@
app
.
route
(
'/point/<id>'
,
methods
=
[
'DELETE'
])
@
with_session
def
del_point
(
session
,
id
):
return
delete_resource
(
session
,
Point
,
id
)
elif
request
.
method
==
'PUT'
:
@
app
.
route
(
'/point/<id>'
,
methods
=
[
'PUT'
])
@
with_session
def
edit_point
(
session
,
id
):
return
edit_resource
(
session
,
Point
,
id
,
request
.
get_json
())
...
...
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