From d47976ffa8bfdeed28feb4e7cb4df7d79eee0ad9 Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Thu, 18 Nov 2021 08:57:39 +1100 Subject: [PATCH] updates --- python/introduction/part-4.http/README.md | 6 +++--- python/introduction/part-4.http/dockerfile | 5 +++-- python/introduction/part-4.http/requirements.txt | 1 - python/introduction/part-4.http/src/app.py | 8 +++++--- python/introduction/part-4.http/src/requirements.txt | 1 + 5 files changed, 12 insertions(+), 9 deletions(-) delete mode 100644 python/introduction/part-4.http/requirements.txt create mode 100644 python/introduction/part-4.http/src/requirements.txt diff --git a/python/introduction/part-4.http/README.md b/python/introduction/part-4.http/README.md index 14ae74d..565ac00 100644 --- a/python/introduction/part-4.http/README.md +++ b/python/introduction/part-4.http/README.md @@ -185,7 +185,7 @@ our application and needs grow. Best is to use a `requirements.txt` file. Let's create a `requirements.txt` file: ``` -Flask == 2.0.1 +Flask == 2.0.2 ``` We can install our dependencies using: @@ -418,10 +418,10 @@ WORKDIR /work FROM dev as runtime WORKDIR /app -COPY requirements.txt /app/ +COPY ./src/requirements.txt /app/ RUN pip install -r /app/requirements.txt -COPY ./src/ /app +COPY ./src/app.py /app/app.py ENV FLASK_APP=app.py CMD flask run -h 0.0.0 -p 5000 diff --git a/python/introduction/part-4.http/dockerfile b/python/introduction/part-4.http/dockerfile index e4c7b93..39ef558 100644 --- a/python/introduction/part-4.http/dockerfile +++ b/python/introduction/part-4.http/dockerfile @@ -4,10 +4,11 @@ WORKDIR /work FROM dev as runtime WORKDIR /app -COPY requirements.txt /app/ + +COPY ./src/requirements.txt /app/ RUN pip install -r /app/requirements.txt -COPY ./src/ /app +COPY ./src/app.py /app/app.py ENV FLASK_APP=app.py CMD flask run -h 0.0.0 -p 5000 \ No newline at end of file diff --git a/python/introduction/part-4.http/requirements.txt b/python/introduction/part-4.http/requirements.txt deleted file mode 100644 index 8cee146..0000000 --- a/python/introduction/part-4.http/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -Flask == 2.0.1 \ No newline at end of file diff --git a/python/introduction/part-4.http/src/app.py b/python/introduction/part-4.http/src/app.py index 503fd6e..ffe1364 100644 --- a/python/introduction/part-4.http/src/app.py +++ b/python/introduction/part-4.http/src/app.py @@ -24,10 +24,11 @@ def getCustomers(): def getCustomer(customerID): customers = getCustomers() + if customerID in customers: return customers[customerID] - else: - return {} + else: + return {} def updateCustomers(customers): with open(dataPath, 'w', newline='') as customerFile: @@ -44,6 +45,7 @@ def get_customers(): @app.route("/get/", methods=['GET']) def get_customer(customerID): customer = getCustomer(customerID) + if customer == {}: return {}, 404 else: @@ -59,7 +61,7 @@ def add_customer(): return "firstName required", 400 if "lastName" not in jsonData: return "lastName required", 400 - + customers = getCustomers() customers[jsonData["customerID"]] = Customer( jsonData["customerID"], jsonData["firstName"], jsonData["lastName"]).__dict__ updateCustomers(customers) diff --git a/python/introduction/part-4.http/src/requirements.txt b/python/introduction/part-4.http/src/requirements.txt new file mode 100644 index 0000000..d5c19d3 --- /dev/null +++ b/python/introduction/part-4.http/src/requirements.txt @@ -0,0 +1 @@ +Flask == 2.0.2 \ No newline at end of file