Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PizzaPalace
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
TheJoeCoder
PizzaPalace
Commits
c3a0fdc3
Verified
Commit
c3a0fdc3
authored
Jul 18, 2023
by
TheJoeCoder
Browse files
Options
Downloads
Patches
Plain Diff
[Server] Allow args from both `json` and `params`
parent
0ac8e05c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/app.py
+20
-12
20 additions, 12 deletions
server/app.py
with
20 additions
and
12 deletions
server/app.py
+
20
−
12
View file @
c3a0fdc3
...
@@ -91,8 +91,8 @@ def open_cart():
...
@@ -91,8 +91,8 @@ def open_cart():
@app.route
(
"
/cart/items
"
,
methods
=
[
"
GET
"
])
@app.route
(
"
/cart/items
"
,
methods
=
[
"
GET
"
])
def
get_cart_items
():
def
get_cart_items
():
# Get cart id and key from request
# Get cart id and key from request
cart_id
=
request
.
args
.
get
(
"
id
"
)
cart_id
=
get_property
(
request
,
"
id
"
)
cart_key
=
request
.
args
.
get
(
"
key
"
)
cart_key
=
get_property
(
request
,
"
key
"
)
# Get cart and verify not none
# Get cart and verify not none
cart
=
get_cart
(
cart_id
,
cart_key
)
cart
=
get_cart
(
cart_id
,
cart_key
)
if
(
cart
==
None
):
if
(
cart
==
None
):
...
@@ -102,14 +102,14 @@ def get_cart_items():
...
@@ -102,14 +102,14 @@ def get_cart_items():
@app.route
(
"
/cart/add
"
,
methods
=
[
"
POST
"
])
@app.route
(
"
/cart/add
"
,
methods
=
[
"
POST
"
])
def
add_cart_item
():
def
add_cart_item
():
# Get cart id and key from request
# Get cart id and key from request
cart_id
=
request
.
args
.
get
(
"
id
"
)
cart_id
=
get_property
(
request
,
"
id
"
)
cart_key
=
request
.
args
.
get
(
"
key
"
)
cart_key
=
get_property
(
request
,
"
key
"
)
# Get cart and verify not none
# Get cart and verify not none
cart
=
get_cart
(
cart_id
,
cart_key
)
cart
=
get_cart
(
cart_id
,
cart_key
)
if
(
cart
==
None
):
if
(
cart
==
None
):
return
gen_invalid_creds_msg
()
return
gen_invalid_creds_msg
()
# Get pizza type from request
# Get pizza type from request
pizza_type
=
request
.
args
.
get
(
"
type
"
)
pizza_type
=
get_property
(
request
,
"
type
"
)
if
(
pizza_type
==
None
):
if
(
pizza_type
==
None
):
return
gen_missing_message
(
"
pizza type
"
)
return
gen_missing_message
(
"
pizza type
"
)
# Get pizza type (ID) from pizza types
# Get pizza type (ID) from pizza types
...
@@ -121,7 +121,7 @@ def add_cart_item():
...
@@ -121,7 +121,7 @@ def add_cart_item():
if
(
pizza_type_obj
==
None
):
if
(
pizza_type_obj
==
None
):
return
gen_invalid_message
(
"
pizza type
"
)
return
gen_invalid_message
(
"
pizza type
"
)
# Get number of people from request
# Get number of people from request
num_people
=
request
.
args
.
get
(
"
num_people
"
)
num_people
=
get_property
(
request
,
"
num_people
"
)
if
(
num_people
==
None
):
if
(
num_people
==
None
):
return
gen_missing_message
(
"
number of people
"
)
return
gen_missing_message
(
"
number of people
"
)
# Test for invalid number of people and convert to integer
# Test for invalid number of people and convert to integer
...
@@ -130,7 +130,7 @@ def add_cart_item():
...
@@ -130,7 +130,7 @@ def add_cart_item():
except
:
except
:
return
gen_invalid_message
(
"
number of people
"
)
return
gen_invalid_message
(
"
number of people
"
)
# Get stuffed crust from request
# Get stuffed crust from request
stuffed_crust
=
request
.
args
.
get
(
"
stuffed_crust
"
)
stuffed_crust
=
get_property
(
request
,
"
stuffed_crust
"
)
if
(
stuffed_crust
==
None
):
if
(
stuffed_crust
==
None
):
return
gen_missing_message
(
"
stuffed crust
"
)
return
gen_missing_message
(
"
stuffed crust
"
)
# Test for invalid stuffed crust and convert to boolean
# Test for invalid stuffed crust and convert to boolean
...
@@ -150,8 +150,8 @@ def add_cart_item():
...
@@ -150,8 +150,8 @@ def add_cart_item():
@app.route
(
"
/cart/total
"
,
methods
=
[
"
GET
"
])
@app.route
(
"
/cart/total
"
,
methods
=
[
"
GET
"
])
def
get_cart_total
():
def
get_cart_total
():
# Get cart id and key from request
# Get cart id and key from request
cart_id
=
request
.
args
.
get
(
"
id
"
)
cart_id
=
get_property
(
request
,
"
id
"
)
cart_key
=
request
.
args
.
get
(
"
key
"
)
cart_key
=
get_property
(
request
,
"
key
"
)
# Get cart and verify not none
# Get cart and verify not none
cart
=
get_cart
(
cart_id
,
cart_key
)
cart
=
get_cart
(
cart_id
,
cart_key
)
if
(
cart
==
None
):
if
(
cart
==
None
):
...
@@ -186,16 +186,24 @@ def get_cart_total():
...
@@ -186,16 +186,24 @@ def get_cart_total():
grand_total
=
subtotal
+
config
.
delivery_flatrate
grand_total
=
subtotal
+
config
.
delivery_flatrate
return
"
{
\"
status
\"
:200,
\"
message
\"
:
\"
ok
\"
,
\"
subtotal
\"
:
"
+
str
(
subtotal
)
+
"
,
\"
delivery_rate
\"
:
"
+
str
(
config
.
delivery_flatrate
)
+
"
,
\"
total
\"
:
"
+
str
(
grand_total
)
+
"
,
\"
breakdown
\"
:
"
+
json
.
dumps
(
breakdown
)
+
"
}
"
,
200
return
"
{
\"
status
\"
:200,
\"
message
\"
:
\"
ok
\"
,
\"
subtotal
\"
:
"
+
str
(
subtotal
)
+
"
,
\"
delivery_rate
\"
:
"
+
str
(
config
.
delivery_flatrate
)
+
"
,
\"
total
\"
:
"
+
str
(
grand_total
)
+
"
,
\"
breakdown
\"
:
"
+
json
.
dumps
(
breakdown
)
+
"
}
"
,
200
def
get_property
(
request
,
param
):
if
(
request
.
headers
.
get
(
"
Content-Type
"
)
==
"
application/json
"
and
request
.
json
[
param
]):
return
request
.
json
[
param
]
elif
(
request
.
args
.
get
(
param
)):
return
request
.
args
.
get
(
param
)
else
:
return
None
@app.route
(
"
/cart/confirmorder
"
,
methods
=
[
"
POST
"
])
@app.route
(
"
/cart/confirmorder
"
,
methods
=
[
"
POST
"
])
def
confirm_order_cart
():
def
confirm_order_cart
():
# Get cart id and key from request
# Get cart id and key from request
cart_id
=
request
.
args
.
get
(
"
id
"
)
cart_id
=
get_property
(
request
,
"
id
"
)
cart_key
=
request
.
args
.
get
(
"
key
"
)
cart_key
=
get_property
(
request
,
"
key
"
)
# Get cart and verify not none
# Get cart and verify not none
cart
=
get_cart
(
cart_id
,
cart_key
)
cart
=
get_cart
(
cart_id
,
cart_key
)
if
(
cart
==
None
):
if
(
cart
==
None
):
return
gen_invalid_creds_msg
()
return
gen_invalid_creds_msg
()
address
=
request
.
args
.
get
(
"
address
"
)
address
=
get_property
(
request
,
"
address
"
)
if
(
address
==
None
):
if
(
address
==
None
):
return
gen_missing_message
(
"
address
"
)
return
gen_missing_message
(
"
address
"
)
# Test for invalid address and convert to dict
# Test for invalid address and convert to dict
...
...
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