Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions backend/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# RETURN HEALTH OF THE APP
######################################################################


@app.route("/health")
def health():
return jsonify(dict(status="OK")), 200
Expand All @@ -35,7 +34,7 @@ def count():
######################################################################
@app.route("/picture", methods=["GET"])
def get_pictures():
pass
return jsonify(data)

######################################################################
# GET A PICTURE
Expand All @@ -44,15 +43,28 @@ def get_pictures():

@app.route("/picture/<int:id>", methods=["GET"])
def get_picture_by_id(id):
pass
for picture in data:
if picture["id"] == id:
return picture
return {"message": "picture not found"}, 404


######################################################################
# CREATE A PICTURE
######################################################################
@app.route("/picture", methods=["POST"])
def create_picture():
pass
# get data from the json body
picture_in = request.json
print(picture_in)
# if the id is already there, return 303 with the URL for the resource
for picture in data:
if picture_in["id"] == picture["id"]:
return {
"Message": f"picture with id {picture_in['id']} already present"
}, 302
data.append(picture_in)
return picture_in, 201

######################################################################
# UPDATE A PICTURE
Expand All @@ -61,11 +73,21 @@ def create_picture():

@app.route("/picture/<int:id>", methods=["PUT"])
def update_picture(id):
pass
# get data from the json body
picture_in = request.json
for index, picture in enumerate(data):
if picture["id"] == id:
data[index] = picture_in
return picture, 201
return {"message": "picture not found"}, 404

######################################################################
# DELETE A PICTURE
######################################################################
@app.route("/picture/<int:id>", methods=["DELETE"])
def delete_picture(id):
pass
for picture in data:
if picture["id"] == id:
data.remove(picture)
return "", 204
return {"message": "picture not found"}, 404