Skip to content

This is a backend application that allows sending of notifications to customers either by sms or push notifications and also tracks of the notifications

Notifications You must be signed in to change notification settings

maxteebabs/notification_challenge

Repository files navigation

SWVL NOTIFICATION APP


Introduction

The Backend Challenge is a project that communicates with our customers via notifications. It allows sending of Promo codes and riders notification to customers via SMS

Motivation

In search for new opportunites, I am inpired to take on this backend challenge.

Getting Started

Installing Dependencies

Python 3.7

Follow instructions to install the latest version of python for your platform in the python docs

Docker

Follow instructions to install the latest version of docker for your platform in the docker docs After Installation is complete, run:

docker-compose build 
Key Dependencies
  • Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.

  • DOCKER help developers and development teams build and ship apps with ease. Docker allows you to build and share containerized applications and microservices.

  • SQLAlchemy and Flask-SQLAlchemy

  • Flask-CORS is the extension I used for cross origin request

Starting the App

To run the migration script

docker-compose exec api python manage.py db init
docker-compose exec api python manage.py db migrate
docker-compose exec python manage.py db upgrade

To start the application, run

docker-compose build
# docker run --env-file=.env -p 5000:5000 swvl
docker-compose up -d
# docker-compose exec db psql --username=postgres --dbname=swvl

How to run test

# python manage.py test
docker-compose exec api python manage.py test

API Endpoints

GET '/api/notifications'

  • fetches a collection of all notifications in the database
curl --location --request GET 'localhost:5000/api/notifications'

Sample Response:

{
    "notifications": [
        {
            "channel": "sms",
            "created_at": "Sat, 06 Mar 2021 15:34:38 GMT",
            "group_name": null,
            "id": 28,
            "message": "Dear Customer, Your promo code is xx339kk. Best Regards",
            "status": "sent",
            "type": "single",
            "user": {
                "id": 1,
                "language": "en",
                "mobile": "23480000000523",
                "name": "Mark Dean"
            }
        }
    ],
    "status": true
}

GET '/api/notifications/1'

  • fetches a collection of all notifications per customer_id in the database
curl --location --request GET 'localhost:5000/api/notifications/customer/1'

Sample Response:

"notifications": [
        {
            "channel": "sms",
            "created_at": "Sat, 06 Mar 2021 15:34:38 GMT",
            "group_name": null,
            "id": 28,
            "message": "Dear Customer, Your promo code is xx339kk. Best Regards",
            "status": "sent",
            "type": "single",
            "user": {
                "id": 1,
                "language": "en",
                "mobile": "23480000000523",
                "name": "Mark Dean"
            }
        }
    ],
    "status": true

POST '/api/notifications/send'

  • send notification to customers
curl --location --request POST 'localhost:5000/api/notifications/send' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message": "Dear Customer, Your promo code is xx339kk. Best Regards",
    "should_send_sms": true,
    "should_send_push_notification": false,
    "should_send_email": false,
    "customer_id": 1
}'

Sample Response

{
    "message": "sent",
    "status": true
}

POST '/api/notifications/group/send'

  • send notification to a group of customers
curl --location --request POST 'localhost:5000/api/notifications/group/send' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message": "Dear Customer, Your promo code is xx339kk. Best Regards",
    "should_send_sms": true,
    "should_send_push_notification": false,
    "should_send_email": false,
    "group_id": 1
}'

Sample Response

{
    "message": "sent",
    "status": true
}

POST '/api/notifications/riders'

  • send notification to riders
curl --location --request POST 'localhost:5000/api/notifications/riders' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message": "Dear Customer, Your promo code is xx339kk. Best Regards",
    "should_send_sms": true,
    "should_send_push_notification": false,
    "should_send_email": false,
    "user_id": 1
}'

Sample Response

{
    "message": "sent",
    "status": true
}

About

This is a backend application that allows sending of notifications to customers either by sms or push notifications and also tracks of the notifications

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages