Small microservice to handle notifications, it allows you to send and cancel notifications, mark as read/unread and get the recipient notifications list.
Easy peasy lemon squeezy:
$ yarn
Or:
$ npm install
Was installed and configured the
eslint
andprettier
to keep the code clean and patterned.
The application is using just one database: SQLite. For the fastest setup is recommended to use docker-compose, you just need to up all services:
$ docker-compose up -d
Or follow the instructions in SQLite and Kafka sections.
It stores all the application's data. You just need to remember to run the migrations:
$ npx prisma migrate dev
See more information on Prisma Migrate.
Kafka is used to receive notifications through events:
$ docker-compose up -d zookeeper kafka
Remember to run the application manually, see Usage
The repository is shipped with a script to help you to send random notifications to Kafka:
$ node scripts/send-message.js
In this file you may configure the path to the SQLite database file and Kafka settings. Rename the .env.example
in the root directory to .env
then just update with your settings.
key | description | default |
---|---|---|
DATABASE_URL | Path to SQLite file. | file:./dev.db |
KAFKA_TOPIC | Name of the Kafka's topic. | notifications.send-notification |
KAFKA_BROKER | Kafka Broker URL. | localhost:9092 |
To start up the app run:
$ yarn start:dev
Or:
npm run start:dev
route | HTTP Method | params | description |
---|---|---|---|
/notifications |
POST | Body with notification content , category and recipientId . |
Create a new notification. |
/notifications/recipient/:id |
GET | :id of the recipient. |
Lists recipient notifications. |
/notifications/recipient/:id/count |
GET | :id of the recipient. |
Count recipient notifications. |
/notifications/:id/cancel |
PATCH | :id of the notification. |
Set notification as canceled. |
/notifications/:id/read |
PATCH | :id of the notification. |
Set notification as read. |
/notifications/:id/unread |
PATCH | :id of the notification. |
Set notification as unread. |
POST /notifications
Request body:
{
"content": "Lorem ipsum dolor sit amet",
"category": "example",
"recipientId": "69c9a4f1-adbb-44c7-97ca-eac8eee9f029"
}
Jest was the choice to test the app, to run:
$ yarn test
Or:
$ npm run test
You can see the coverage report inside tests/coverage
. They are automatically created after the tests run.