Skip to content

Commit ca7c717

Browse files
committed
bug(link): add s03 final code folder
Also add link to downloadable zip file in s04
1 parent fe7da8b commit ca7c717

File tree

2 files changed

+46
-1
lines changed
  • docs/docs
    • 03_first_rest_api/09_final_code/end
    • 04_docker_intro/03_run_docker_container

2 files changed

+46
-1
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from flask import Flask, request
2+
3+
app = Flask(__name__)
4+
5+
stores = [{"name": "My Store", "items": [{"name": "Chair", "price": 15.99}]}]
6+
7+
8+
@app.get("/store")
9+
def get_stores():
10+
return {"stores": stores}
11+
12+
13+
@app.post("/store")
14+
def create_store():
15+
request_data = request.get_json()
16+
new_store = {"name": request_data["name"], "items": []}
17+
stores.append(new_store)
18+
return new_store, 201
19+
20+
21+
@app.post("/store/<string:name>/item")
22+
def create_item(name):
23+
request_data = request.get_json()
24+
for store in stores:
25+
if store["name"] == name:
26+
new_item = {"name": request_data["name"], "price": request_data["price"]}
27+
store["items"].append(new_item)
28+
return new_item, 201
29+
return {"message": "Store not found"}, 404
30+
31+
32+
@app.get("/store/<string:name>")
33+
def get_store(name):
34+
for store in stores:
35+
if store["name"] == name:
36+
return store
37+
return {"message": "Store not found"}, 404
38+
39+
40+
@app.get("/store/<string:name>/item")
41+
def get_item_in_store(name):
42+
for store in stores:
43+
if store["name"] == name:
44+
return {"items": store["items"]}
45+
return {"message": "Store not found"}, 404

docs/docs/04_docker_intro/03_run_docker_container/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Docker Desktop is an application to help you manage your images and containers.
66

77
## Create your Docker image
88

9-
Next, download the REST API code from Section 3. You can download it here: LINK.
9+
Next, download the REST API code from Section 3. You can download it [here](https://www.dropbox.com/s/qs28amk2h420f2y/s03-final-code.zip?dl=0).
1010

1111
If you want to use the code you wrote while following the videos, that's fine! Just make sure it works by running the Flask app locally and testing it with Insomnia REST Client or Postman.
1212

0 commit comments

Comments
 (0)