Table of Contents

Sesiuna 5 - Implementarea serviciului de Notificari si cuplarea integrala a microserviciilor

In primul rand, felicitari tuturor celor care ati ajuns pana aici!

Astazi este ultima sesiune de scris cod si, pentru a celebra acest lucru, veti avea parte de o sesiune complet practica, in care va trebui sa dezvoltati de la zero serviciul de Notificari.

Ce veti invata?

Resurse

Resursele sunt, ca intotdeauna, gasite pe repository-ul grupului.

Aveti implementate complet:

Pentru a porni cele 3 microservicii, efectuati urmatoarele comenzi:

- in folderul database-deploy din library si auth

docker-compose up 

- in toate cele 3 servicii:

npm run start-dev

Serviciul de mailing NU ARE .env pus in git, ci are un .env.example. Va trebui sa va creati voi fisierul .env si sa va puneti credentialele de la serviciul de email pe care il veti folosi.

Dupa ce terminati de scris mailing, PUNETI .env IN .gitignore pentru ca acesta va contine date sensibile

Exercitii

Trebuie sa implementati serviciul de notificari complet. Trebuie sa tineti cont de urmatoarele:

-> GET /subscribe //autorizare pentru ADMIN si READER, adauga un subscriber in sistem
 
-> DELETE /unsubscribe //autorizare pe ADMIN si READER, scoate un subscriber din sistem
 
-> DELETE /unsubscribe/user/:userId //ruta interna ce va fi folosita pentru sincronizare atunci cand se sterge un user
 
-> POST /notify 
/* ruta interna ce va fi folosita de microserviciul library, atunci cand se adauga o carte
 * primeste un obiect JSON de forma
 * {
 *    bookName,
 *    author
 * }
 */
-> POST http://${process.env.MAILING_SERVICE}/api/newsletter
class MailingPayload {
    constructor(bookName, author, emails) {
        this.mailingList = emails.map(e => e.to_email);
        this.book = {
            name: bookName,
            author: author
        }
    }
}
PGHOST=localhost
PGUSER=test
PGPASSWORD=test
PGPORT=5557
PGDATABASE=workshop-newsletter
 
PORT=3002
NODE_ENV=development
 
AUTH_SERVICE='localhost:3001'
MAILING_SERVICE='localhost:3003'
 
ADMIN_ROLE='administrator'
READER_ROLE='reader'
// .env
PGUSER=test
PGPASSWORD=test
PGPORT=5557
PGDATABASE=workshop-newsletter
 
// docker-compose.yml
version: "3.8"
 
services:
  newsletter-db:
    image: postgres
    environment:
      POSTGRES_USER: ${PGUSER}
      POSTGRES_PASSWORD: ${PGPASSWORD}
      POSTGRES_DB: ${PGDATABASE}
      TZ: Europe/Bucharest
      PGTZ: Europe/Bucharest
    ports:
      - ${PGPORT}:5432
    volumes:
      - workshop-newsletter:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
 
  newsletter-pgadmin:
    image: dpage/pgadmin4
    ports:
      - "30004:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: test
      PGADMIN_DEFAULT_PASSWORD: test
    logging:
      driver: none
 
volumes:
  workshop-newsletter:
 
//init.sql
CREATE TABLE IF NOT EXISTS newsletter (
    id serial PRIMARY KEY,
    id_user INTEGER NOT NULL UNIQUE,
    to_email VARCHAR NOT NULL UNIQUE
)

De astazi, serviciul de auth va intoarce, in momentul interogarii de catre alte servicii, si email, pe langa userId si role