Last active
March 5, 2022 18:18
-
-
Save DavidDeCoding/f17b0847835777a4487eb817df282cf2 to your computer and use it in GitHub Desktop.
Building Coupon Reminders - Part 2 Serverless and Secured Image Storage and Processing - app.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pydantic import BaseModel | |
from typing import List | |
from fastapi import FastAPI | |
from mangum import Mangum | |
import Coupon | |
class AddCouponRequest(BaseModel): | |
user_id: str | |
class GetCouponsResponse(BaseModel): | |
coupons: List[Coupon] | |
stage = os.environ.get('STAGE', None) | |
openapi_prefix = f"/{stage}" if stage else "/" | |
app = FastAPI(title="Coupon Reminders App", openapi_prefix=openapi_prefix) | |
@app.post("/addCoupon") | |
def add_coupon(request: AddCouponRequest): | |
Coupon.process_and_store(request.user_id) | |
return | |
@app.get("/getCoupons/{user_id}") | |
def get_coupon(user_id: str) -> GetCouponsResponse: | |
return GetCouponsResponse(coupons=Coupon.retrieve_latest_all(user_id)) | |
handler = Mangum(app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment