generated from nyu-devops/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from CSCI-GA-2820-SP24-003/feat-deactivate-acc…
…ount Feat: Deactivate account
- Loading branch information
Showing
5 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
|
||
|
||
def encrypt_password(password): | ||
""" Hashing Passwords """ | ||
"""Hashing Passwords""" | ||
return hashlib.sha256(password.encode("UTF-8")).hexdigest() | ||
|
||
|
||
|
@@ -42,17 +42,22 @@ def index(): | |
# "Reminder: return some useful information in json format about the service here", | ||
# status.HTTP_200_OK, | ||
# ) | ||
return jsonify({ | ||
"1_Customers": "Welcome to the Customer Store Service API. This API allows you to manage the customers.", | ||
"2_methods_available": { | ||
"2.1 GET /customers/<customer_id>": "Retrieve a single customer by ID.", | ||
"2.2 POST /customers": "Create a new customer.", | ||
"2.3 DELETE /customers/<customer_id>": "Delete a customer by ID.", | ||
"2.4 GET /customers": "Retrieve a list of all customers.", | ||
"2.5 PUT /customers/<customer_id>": "Update an existing customer by ID." | ||
}, | ||
"3_contact": "For more information, refer to the API documentation or contact [email protected]." | ||
}), status.HTTP_200_OK | ||
return ( | ||
jsonify( | ||
{ | ||
"1_Customers": "Welcome to the Customer Store Service API. This API allows you to manage the customers.", | ||
"2_methods_available": { | ||
"2.1 GET /customers/<customer_id>": "Retrieve a single customer by ID.", | ||
"2.2 POST /customers": "Create a new customer.", | ||
"2.3 DELETE /customers/<customer_id>": "Delete a customer by ID.", | ||
"2.4 GET /customers": "Retrieve a list of all customers.", | ||
"2.5 PUT /customers/<customer_id>": "Update an existing customer by ID.", | ||
}, | ||
"3_contact": "For more information, refer to the API documentation or contact [email protected].", | ||
} | ||
), | ||
status.HTTP_200_OK, | ||
) | ||
|
||
|
||
###################################################################### | ||
|
@@ -79,9 +84,7 @@ def get_customers(customer_id): | |
f"Customer with id '{customer_id}' was not found.", | ||
) | ||
|
||
app.logger.info( | ||
"Returning customer: %s", customer.id | ||
) | ||
app.logger.info("Returning customer: %s", customer.id) | ||
return jsonify(customer.serialize()), status.HTTP_200_OK | ||
|
||
|
||
|
@@ -175,6 +178,26 @@ def update_customers(customer_id): | |
return jsonify(customer.serialize()), status.HTTP_200_OK | ||
|
||
|
||
###################################################################### | ||
# DEACTIVATE A CUSTOMER | ||
###################################################################### | ||
@app.route("/customers/<int:customer_id>/deactivate", methods=["PUT"]) | ||
def deactivate_customer(customer_id): | ||
""" | ||
Deactivate a customer | ||
This endpoint will deactivate a customer based on the id specified in the path | ||
""" | ||
customer = Customer.find(customer_id) | ||
if not customer: | ||
abort( | ||
status.HTTP_404_NOT_FOUND, | ||
f"Customer with id '{customer_id}' was not found.", | ||
) | ||
|
||
customer.deactivate() | ||
return jsonify(""), status.HTTP_204_NO_CONTENT | ||
|
||
|
||
###################################################################### | ||
# U T I L I T Y F U N C T I O N S | ||
###################################################################### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters