Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "pypi"
[packages]
chalice = "*"
boto3 = "*"
pydantic = "*"

[dev-packages]

Expand Down
181 changes: 155 additions & 26 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from chalicelib.s3 import S3Client
from chalicelib.utils import get_file_extension_from_base64


import uuid

app = Chalice(app_name="zap")
Expand All @@ -14,10 +15,12 @@
def index():
return {"hello": "world"}


@app.route("/test")
def test():
return {"test": "test"}


@app.route("/submit", methods=["POST"], cors=True)
def submit_form():
# Get data as JSON and attach unique id for applicantId
Expand Down Expand Up @@ -55,6 +58,7 @@ def create_listing():
data = app.current_request.json_body
listing_id = str(uuid.uuid4())
data["listingId"] = listing_id
data["isVisible"] = True

db.put_data(table_name="zap-listings", data=data)

Expand Down Expand Up @@ -88,3 +92,21 @@ def get_all_applicants(listing_id):
"""Gets all applicants from <listing_id>"""
data = db.get_applicants(table_name="zap-applications", listing_id=listing_id)
return data


@app.route("/listings/{id}/toggle/visibility", methods=["PATCH"], cors=True)
def toggle_visibility(id):
"""Toggles visibilility of a given <listing_id>"""
try:
# Perform visibility toggle in the database
data = db.toggle_visibility(table_name="zap-listings", key={"listingId": id})

# Check the result and return the appropriate response
if data:
return {"status": True}
else:
return {"status": False, "message": "Invalid listing ID"}, 400

except Exception as e:
app.log.error(f"An error occurred: {str(e)}")
return {"status": False, "message": "Internal Server Error"}, 500
Loading