Skip to content

Desenvolvimento de um sistema de enquete, com a integração de tecnologias como WebSockets para comunicação em tempo real e armazenamento em cache de cada votação utilizando Redis.

Notifications You must be signed in to change notification settings

mateussilva01/polling-system-real-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NLW Expert (Node.js)

A real-time voting system where users can create a poll and other users can cast their votes. The system generates a ranking among the options and updates the votes in real-time.

Screenshots

1.png

Requisites

  • Docker;
  • Node.js;

Setup

  • Clone the repository;
  • Install dependencies (npm install);
  • Setup PostgreSQL and Redis (docker compose up -d);
  • Copy .env.example file (cp .env.example .env);
  • Run application (npm run dev);
  • Test it! (I personally recommend testing with Hoppscotch).

HTTP

POST /polls

Create a new poll.

Request body

{
  "title": "Qual o melhor framework Node.js?",
  "options": [
    "Express",
    "Fastify",
    "NestJS",
    "HapiJS"
  ]
}

Response body

{
  "pollId": "f69fef07-6702-4f06-ac1e-3671dcb60514"
}

GET /polls/:pollId

Return data from a single poll.

Response body

{
   "poll":{
      "id":"f69fef07-6702-4f06-ac1e-3671dcb60514",
      "title":"Qual o melhor framework Node.js?",
      "options":[
         {
            "id":"ea19a517-da23-41d5-86ad-222945b2fdd7",
            "title":"Express",
            "score":0
         },
         {
            "id":"0d69f658-066c-4142-93b5-519b3dda9792",
            "title":"Fastify",
            "score":1
         },
         {
            "id":"1ad6b046-9fc3-425f-ad8c-dcaccbde7b69",
            "title":"NestJS",
            "score":0
         },
         {
            "id":"45344819-8faf-4076-b9fb-d5d11fccc5d8",
            "title":"HapiJS",
            "score":0
         }
      ]
   }
}

POST /polls/:pollId/votes

Add a vote to specific poll.

Request body

{
  "pollOptionId": "0d69f658-066c-4142-93b5-519b3dda9792"
}

WebSockets

ws /polls/:pollId/results

Message

{
  "pollOptionId": "0d69f658-066c-4142-93b5-519b3dda9792",
  "votes": 1
}

About

Desenvolvimento de um sistema de enquete, com a integração de tecnologias como WebSockets para comunicação em tempo real e armazenamento em cache de cada votação utilizando Redis.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published