This shows you the differences between two versions of the page.
moby:backend:05 [2020/07/31 15:49] alexandru.hogea |
moby:backend:05 [2020/07/31 15:56] (current) alexandru.hogea [Exercitii] |
||
---|---|---|---|
Line 34: | Line 34: | ||
<note warning>Dupa ce terminati de scris mailing, **PUNETI .env IN .gitignore** pentru ca acesta va contine date sensibile</note> | <note warning>Dupa ce terminati de scris mailing, **PUNETI .env IN .gitignore** pentru ca acesta va contine date sensibile</note> | ||
- | |||
- | <note tip>De astazi, serviciul de auth va intoarce, in momentul interogarii de catre alte servicii, si **email**, pe langa userId si role</note> | ||
==== Exercitii ==== | ==== Exercitii ==== | ||
Line 44: | Line 42: | ||
<code javascript> | <code javascript> | ||
- | -> GET /subscribe //autorizare pentru ADMIN si READER | + | -> GET /subscribe //autorizare pentru ADMIN si READER, adauga un subscriber in sistem |
- | -> DELETE /unsubscribe //autorizare pe ADMIN si READER | + | -> DELETE /unsubscribe //autorizare pe ADMIN si READER, scoate un subscriber din sistem |
- | -> DELETE /unsubscribe/user/:userId //ruta interna ce va fi folosita pentru sincronizare | + | -> DELETE /unsubscribe/user/:userId //ruta interna ce va fi folosita pentru sincronizare atunci cand se sterge un user |
-> POST /notify | -> POST /notify | ||
Line 59: | Line 57: | ||
*/ | */ | ||
</code> | </code> | ||
+ | |||
+ | * atunci cand este apelat **notify**, se va trimite un POST catre serviciul de mail. Interactiunea cu serviciul de mail se face pe ruta | ||
+ | <code javascript> | ||
+ | -> POST http://${process.env.MAILING_SERVICE}/api/newsletter | ||
+ | </code> | ||
+ | * interactiunea cu serviciul de mail se va face prin trimiterea urmatorului obiect: | ||
+ | <code javascript> | ||
+ | class MailingPayload { | ||
+ | constructor(bookName, author, emails) { | ||
+ | this.mailingList = emails.map(e => e.to_email); | ||
+ | this.book = { | ||
+ | name: bookName, | ||
+ | author: author | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | * veti avea urmatorul fisier **.env** | ||
+ | <code javascript> | ||
+ | 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' | ||
+ | </code> | ||
+ | * folderul **database-deploy** va contine urmatoarele: | ||
+ | |||
+ | <code javascript> | ||
+ | // .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 | ||
+ | ) | ||
+ | </code> | ||
+ | |||
+ | <note tip>De astazi, serviciul de auth va intoarce, in momentul interogarii de catre alte servicii, si **email**, pe langa userId si role</note> | ||
+ | |||
+ | * in middlewareul de autorizare, sa salvati in **req.state** si **email** |