Skip to content

Commit

Permalink
hello
Browse files Browse the repository at this point in the history
  • Loading branch information
jdubya747 committed Dec 28, 2021
1 parent 2274d5d commit 4868b82
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 0 deletions.
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.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask==1.1.2
Empty file.
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"}
]
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"}
]
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ services:
ports:
- "5000:5000"

api1:
build: api1
command: ["flask", "run", "--host=0.0.0.0"]
volumes:
- ./api:/backend
environment:
- FLASK_ENV=development
- FLASK_APP=app.py
ports:
- "5001:5000"

client:
tty: true
build: client
Expand Down

0 comments on commit 4868b82

Please sign in to comment.