Skip to content

Commit

Permalink
changed both product listing to same function
Browse files Browse the repository at this point in the history
  • Loading branch information
abhigyanghosh30 committed Oct 5, 2023
1 parent 0e58c7f commit e24f55e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
10 changes: 4 additions & 6 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@
cred_syllabus_data,
cred_your_exams,
get_activation_keys,
get_exam_products,
get_cue_products,
get_filtered_webhook_responses,
get_issued_badges,
get_key_products,
get_my_issued_badges,
get_webhook_response,
issue_badges,
Expand Down Expand Up @@ -1133,7 +1132,9 @@ def takeovers_index():
app.add_url_rule("/credentials/assessments", view_func=cred_assessments)
app.add_url_rule("/credentials/exam", view_func=cred_exam)
app.add_url_rule(
"/credentials/exam/products", view_func=get_exam_products, methods=["GET"]
"/credentials/<string:type>/products",
view_func=get_cue_products,
methods=["GET"],
)
app.add_url_rule(
"/credentials/exit-survey",
Expand Down Expand Up @@ -1165,9 +1166,6 @@ def takeovers_index():
view_func=activate_activation_key,
methods=["POST"],
)
app.add_url_rule(
"/credentials/keys/products", view_func=get_key_products, methods=["GET"]
)
app.add_url_rule(
"/credentials/beta/activation",
view_func=cred_beta_activation,
Expand Down
28 changes: 5 additions & 23 deletions webapp/shop/cred/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,11 @@ def issue_badges(trueability_api, credly_api, **kwargs):


@shop_decorator(area="cred", permission="user", response="json")
def get_key_products(ua_contracts_api, **kwargs):
def get_cue_products(ua_contracts_api, type, **kwargs):
listings = ua_contracts_api.get_product_listings("canonical-cube").get(
"productListings"
)
key_products = [
filtered_products = [
{
"id": listing["productID"],
"longId": listing["id"],
Expand All @@ -731,25 +731,7 @@ def get_key_products(ua_contracts_api, **kwargs):
"price": listing["price"],
}
for listing in listings
if listing["productID"].endswith("key")
if (listing["productID"].endswith("key") and type == "keys")
or (type == "exam")
]
return flask.jsonify(key_products)


@shop_decorator(area="cred", permission="user", response="json")
def get_exam_products(ua_contracts_api, **kwargs):
listings = ua_contracts_api.get_product_listings("canonical-cube").get(
"productListings"
)
exam_products = [
{
"id": listing["productID"],
"longId": listing["id"],
"period": listing["period"],
"marketplace": listing["marketplace"],
"name": listing["name"],
"price": listing["price"],
}
for listing in listings
]
return flask.jsonify(exam_products)
return flask.jsonify(filtered_products)

0 comments on commit e24f55e

Please sign in to comment.