Skip to content

FridgeFinder/CFM_Notification

Repository files navigation

CFM_Notification

FridgeFinder Notification Service

GitHub contributors GitHub commit activity (dev)

Service that manages and sends out User Fridge Notifications to users of FridgeFinder

User's of FridgeFinder are able to receive notification on status updates of a Community Fridge they are following

User's can Follow to a Community Fridge by going to a Fridge Profile and clicking on the Follow Button [TODO: implement follow button :)] - find one near you https://www.fridgefinder.app/browse

Currently User's can receive fridge notification via Email or SMS


Pre-Requisites

  1. AWS CLI - Install the AWS CLI
    • You DO NOT have to create an AWS account to use AWS CLI for this project, skip these steps if you don't want to create an AWS account
    • AWS CLI looks for credentials when using it, but doesn't validate. So will need to set some fake one. But the region name matters, use any valid region name.
      $ aws configure
      $ AWS Access Key ID: [ANYTHING YOU WANT]
      $ AWS Secret Access Key: [ANYTHING YOUR HEART DESIRES]
      $ Default region nam: us-east-1
      $ Default output format [None]: (YOU CAN SKIP)
  2. SAM CLI - Install the SAM CLI
    • You DO NOT need to create an aws account to use SAM CLI for this project, skip these steps if you don't want to create an aws account
    • Note: if you are getting the following error: runtime is not supported when running sam build --use-container make sure your SAM CLI version is up to date
  3. Python 3 - Install Python 3
  4. Docker - Install Docker

Setup Local Database Connection

Guide that was used: https://betterprogramming.pub/how-to-deploy-a-local-serverless-application-with-aws-sam-b7b314c3048c

Follow these steps to get Dynamodb running locally

  1. Start a local DynamoDB service

    $ docker compose up
    # OR if you want to run it in the background:
    $ docker compose up -d
  2. Create tables

    $ ./scripts/create_local_dynamodb_tables.py

Build and Test Locally

Confirm that the following requests work for you

  1. cd Notification/
  2. sam build --use-container
  3. sam local invoke HelloWorldFunction --event events/event.json
    • response: {"statusCode": 200, "body": "{\"message\": \"hello world\"}"}
  4. sam local start-api
  5. curl http://localhost:3000/hello
    • response: {"message": "hello world"}

If it does yay, keep going 🤸‍♀️


User Fridge Notification

These APIs are for interacting with individual user/fridge notification records

URL format: v1/users/{user_id}/notifications/{fridge_id}

Note: make sure your local dynamodb instance is running on docker. Follow instructions on Setup Local Database Connection

Local Invoke

To test locally we use sam local invoke to mimick a cognito authorized request

  1. POST Example

    sam local invoke UserFridgeNotificationsFunction --event events/post_notification.json --parameter-overrides ParameterKey=Environment,ParameterValue=local ParameterKey=Stage,ParameterValue=dev --docker-network cfm-network
  2. PUT Example

    sam local invoke UserFridgeNotificationsFunction --event events/put_notification.json --parameter-overrides ParameterKey=Environment,ParameterValue=local ParameterKey=Stage,ParameterValue=dev --docker-network cfm-network
  3. GET Example

    sam local invoke UserFridgeNotificationsFunction --event events/get_notification.json --parameter-overrides ParameterKey=Environment,ParameterValue=local ParameterKey=Stage,ParameterValue=dev --docker-network cfm-network

Running Unit Tests

  1. Create and activate a virtual environment from the project root:
python3 -m venv .venv
source .venv/bin/activate
  1. Upgrade packaging tools and install the project in editable mode:
pip install -U pip setuptools wheel
pip install -e .
  1. Install test dependencies:
pip install -r Notification/tests/requirements.txt
  1. Run tests (unittest discovery):
python -m unittest discover -s Notification/tests/unit -t .

Or run a single test file:

python -m unittest Notification.tests.unit.test_user_fridge_notifications_api

To deactivate the environment when done:

deactivate

Deployment

  1. Build: sam build --use-container
  2. Deploy: sam deploy --config-file samconfig.toml --config-env <ENVIRONMENT>
  • edit CFMHostedZoneId in samconfig.toml

APIs with Cognito ID Token - Dev Server Examples

Only authenticated users are able to get or edit their notification preferences

GET

curl --location --request GET 'https://notifications-api-dev.communityfridgefinder.com/v1/users/<USER_ID>/notifications/<FRIDGE_ID>' --header 'Authorization: <ID_TOKEN>'

POST/PUT

curl --location --request <POST/PUT> 'https://notifications-api-dev.communityfridgefinder.com/v1/users/<USER_ID>/notifications/<FRIDGE_ID>'
--header 'Authorization: <ID_TOKEN>'
--header 'Content-Type: application/json'
--data '{
    "contact_types_status": {"sms": "stop"},
    "contact_types_preferences": {"sms": {"good": true, "dirty": true, "out_of_order": true, "not_at_location": true, "ghost": true, "food_level_0": false, "food_level_1": false, "food_level_2": true, "food_level_3": true, "cleaned": false}},
    "contact_info": {"sms": "+18577048438"}
  }'

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages