forked from udacity/cd0309-message-passing-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
lesson-1-refactoring-from-a-monolith/udacredit-monolith/api1/Dockerfile
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM python:3.7-slim | ||
RUN mkdir /backend | ||
WORKDIR /backend | ||
COPY requirements.txt /backend/requirements.txt | ||
RUN pip install --upgrade pip && \ | ||
pip install -r requirements.txt | ||
COPY . . |
Empty file.
59 changes: 59 additions & 0 deletions
59
lesson-1-refactoring-from-a-monolith/udacredit-monolith/api1/app.py
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from flask import Flask, jsonify, make_response | ||
|
||
from .services.customers import get_customers | ||
from .services.employees import get_employees | ||
from .services.notifications import send_notifications | ||
|
||
app = Flask(__name__) | ||
|
||
# Mozilla provides good references for Access Control at: | ||
# https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS | ||
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Server-Side_Access_Control | ||
|
||
@app.route('/api/customers', methods=['GET']) | ||
def customers(): | ||
"""Return a JSON response for all customers.""" | ||
sample_response = { | ||
"customers": get_customers() | ||
} | ||
# JSONify response | ||
response = make_response(jsonify(sample_response)) | ||
|
||
# Add Access-Control-Allow-Origin header to allow cross-site request | ||
response.headers['Access-Control-Allow-Origin'] = 'http://localhost:3000' | ||
|
||
return response | ||
|
||
|
||
@app.route('/api/employees', methods=['GET']) | ||
def employees(): | ||
"""Return a JSON response for all employees.""" | ||
sample_response = { | ||
"employees": get_employees() | ||
} | ||
# JSONify response | ||
response = make_response(jsonify(sample_response)) | ||
|
||
# Add Access-Control-Allow-Origin header to allow cross-site request | ||
response.headers['Access-Control-Allow-Origin'] = 'http://localhost:3000' | ||
|
||
return response | ||
|
||
|
||
@app.route('/api/employees/notifications', methods=['POST']) | ||
def notifications(): | ||
# Notifications service can be used to remind employees to fill out their timecards | ||
employee_emails = [employee.get('email') for employee in get_employees()] | ||
send_notifications(employee_emails) | ||
|
||
sample_response = { | ||
"recipients": employee_emails | ||
} | ||
|
||
# JSONify response | ||
response = make_response(jsonify(sample_response)) | ||
|
||
# Add Access-Control-Allow-Origin header to allow cross-site request | ||
response.headers['Access-Control-Allow-Origin'] = 'http://localhost:3000' | ||
|
||
return response |
1 change: 1 addition & 0 deletions
1
lesson-1-refactoring-from-a-monolith/udacredit-monolith/api1/requirements.txt
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Flask==1.1.2 |
Empty file.
7 changes: 7 additions & 0 deletions
7
lesson-1-refactoring-from-a-monolith/udacredit-monolith/api1/services/customers.py
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
def get_customers(): | ||
return [ | ||
{"id": 1, "name": "John Smith", "balance": "$2000"}, | ||
{"id": 2, "name": "Ronald Alberts", "balance": "$500"}, | ||
{"id": 3, "name": "Raymond Sparks", "balance": "$250"}, | ||
{"id": 4, "name": "Amy Salvador", "balance": "$890"} | ||
] |
7 changes: 7 additions & 0 deletions
7
lesson-1-refactoring-from-a-monolith/udacredit-monolith/api1/services/employees.py
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
def get_employees(): | ||
return [ | ||
{"id": 1, "name": "Faye Solomon", "email": "fsolomon@udacredit.com"}, | ||
{"id": 2, "name": "Frank Chang", "email": "fchang@udacredit.com"}, | ||
{"id": 3, "name": "Cullen Ocean", "email": "cocean@udacredit.com"}, | ||
{"id": 4, "name": "Arvind Patel", "email": "apatel@udacredit.com"} | ||
] |
3 changes: 3 additions & 0 deletions
3
lesson-1-refactoring-from-a-monolith/udacredit-monolith/api1/services/notifications.py
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def send_notifications(recipients): | ||
# this method is stubbed -- we don't want to send anything! | ||
return |
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