├── .gitignore ├── database.sqlite ├── src ├── public │ ├── img │ │ ├── pag1.jpg │ │ └── pag2.jpg │ └── css │ │ ├── admin.css │ │ └── index.css ├── configs │ ├── database │ │ ├── exitError.js │ │ ├── database.js │ │ └── createTable.js │ ├── server │ │ ├── custom-express.js │ │ └── server.js │ ├── middlewares │ │ └── middlewares.js │ └── routes │ │ └── routes.js ├── controller │ └── ParticipantesController.js ├── dao │ └── participantesDao.js └── views │ ├── index.js │ └── admin.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /database.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicckm/projeto-globo/master/database.sqlite -------------------------------------------------------------------------------- /src/public/img/pag1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicckm/projeto-globo/master/src/public/img/pag1.jpg -------------------------------------------------------------------------------- /src/public/img/pag2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicckm/projeto-globo/master/src/public/img/pag2.jpg -------------------------------------------------------------------------------- /src/configs/database/exitError.js: -------------------------------------------------------------------------------- 1 | module.exports = (err) => { 2 | console.log(err); 3 | process.exit(1); 4 | } -------------------------------------------------------------------------------- /src/configs/server/custom-express.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | module.exports = { app, express } -------------------------------------------------------------------------------- /src/configs/middlewares/middlewares.js: -------------------------------------------------------------------------------- 1 | const bodyParser = require('body-parser'); 2 | const { express } = require('../server/custom-express'); 3 | 4 | module.exports = (app) => { 5 | app.use('/static', express.static(__dirname + '../../../public')); 6 | app.use(bodyParser.json()) 7 | app.use(bodyParser.urlencoded({ extended: true })); 8 | } -------------------------------------------------------------------------------- /src/configs/server/server.js: -------------------------------------------------------------------------------- 1 | const { app } = require('./custom-express'); 2 | const routes = require('../routes/routes'); 3 | const middlewares = require('../middlewares/middlewares'); 4 | const port = 3000; 5 | 6 | middlewares(app); 7 | 8 | routes(app); 9 | 10 | app.listen(port, () => { 11 | console.log(`Server started in http://localhost:${port}`); 12 | }) -------------------------------------------------------------------------------- /src/configs/database/database.js: -------------------------------------------------------------------------------- 1 | const exitError = require('./exitError'); 2 | const sqlite = require('sqlite3'); 3 | const db = new sqlite.Database('./database.sqlite', err => 4 | { if(err) return exitError(err) }); 5 | 6 | process.on("SIGINT", () => { 7 | db.close( () => { 8 | console.log('\n Database closed'); 9 | process.exit(0); 10 | }); 11 | }); 12 | 13 | module.exports = db; -------------------------------------------------------------------------------- /src/public/css/admin.css: -------------------------------------------------------------------------------- 1 | body { 2 | background:#d2fafb; 3 | } 4 | 5 | .titulo { 6 | text-align:center; 7 | font-family:'Bangers',cursive; 8 | font-size:50px; 9 | color:#6bc5d2; 10 | } 11 | 12 | .participantes { 13 | display:flex; 14 | flex-wrap: wrap; 15 | justify-content:center; 16 | } 17 | 18 | .personagem { 19 | width: 300px; 20 | height: 300px; 21 | object-fit:cover; 22 | border-radius:50%; 23 | } 24 | 25 | p { 26 | text-align:center; 27 | font-family:'Bangers',cursive; 28 | font-size:20px; 29 | } 30 | -------------------------------------------------------------------------------- /src/configs/routes/routes.js: -------------------------------------------------------------------------------- 1 | const page = require("../../views/index"); 2 | const admin = require("../../views/admin"); 3 | const ParticipantesController = require("../../controller/ParticipantesController"); 4 | let db = require("../../configs/database/database"); 5 | 6 | module.exports = (app) => { 7 | app.get("/", (req, res) => { 8 | res.send(page); 9 | }); 10 | 11 | app.get("/votacao", ParticipantesController.computaVotos()); 12 | 13 | app.post("/votacao", ParticipantesController.inserirParticipantes()); 14 | 15 | app.get("/admin/:part1/:part2", (req, res) => { 16 | res.send(admin(req.params.part1, req.params.part2)); 17 | }); 18 | }; 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "projeto-globo", 3 | "version": "1.0.0", 4 | "description": "> É um projeto, proposto pelas mentoras da Globo, para resolver um problema de votação entre participantes de um reality show.", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "nodemon src/configs/server/server.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/vicckm/projeto-globo.git" 13 | }, 14 | "author": "Brunna Mattos, Samantha Cardoso e Victoria Marques", 15 | "license": "ISC", 16 | "bugs": { 17 | "url": "https://github.com/vicckm/projeto-globo/issues" 18 | }, 19 | "homepage": "https://github.com/vicckm/projeto-globo#readme", 20 | "dependencies": { 21 | "body-parser": "^1.19.0", 22 | "express": "^4.17.1", 23 | "sqlite3": "^5.0.0" 24 | }, 25 | "devDependencies": { 26 | "nodemon": "^2.0.5" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/controller/ParticipantesController.js: -------------------------------------------------------------------------------- 1 | const ParticipantesDao = require("../dao/participantesDao"); 2 | let db = require("../configs/database/database"); 3 | 4 | 5 | 6 | class ParticipantesController { 7 | static inserirParticipantes() { 8 | return (req, res) => { 9 | const participantesDao = new ParticipantesDao(db); 10 | 11 | participantesDao 12 | .inserir(req.body.participante) 13 | .then((rows) => { 14 | res.redirect('/votacao'); 15 | }) 16 | .catch((err) => { 17 | console.log(err); 18 | }); 19 | }; 20 | } 21 | 22 | static computaVotos() { 23 | return (req, res) => { 24 | const participantesDao = new ParticipantesDao(db); 25 | 26 | participantesDao 27 | .computaVotos() 28 | .then((rows) => { 29 | res.redirect(`/admin/${rows[0].part1}/${rows[0].part2}`); 30 | }) 31 | .catch((err) => { 32 | console.log(err); 33 | }); 34 | }; 35 | } 36 | } 37 | 38 | module.exports = ParticipantesController; 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Projeto de Mentoria - Globo 2 | > Projeto elaborado durante o período de mentoria com o Grupo Globo, cuja proposta era a criação de uma página de votação, com seleção de candidato e leitura de votos. 3 | 4 | ## Colaboradoras 5 | - [Brunna Mattos](https://github.com/brunnamattos) 6 | - [Samantha Cardoso](https://github.com/samanthacardosoo) 7 | - [Victoria Marques](https://github.com/vicckm) 8 | 9 | ## Status 10 | Projeto concluído 11 | 12 | ### Execute o projeto 13 | - Clone este repositório com *$ git clone * 14 | - Instale as dependências com *npm install* 15 | - Execute a aplicação com *npm start* (O servidor iniciará na porta 3000. Acesse 16 | 17 | ### Tecnologias 18 | Para a construção do projeto, utilizamos: 19 | 20 | - HTML 21 | - CSS 22 | - JavaScript 23 | - Node.js 24 | 25 | ### Demonstração da aplicação 26 | - Veja o projeto no Heroku: 27 | - Demonstração: 28 | ![Pagina de votação](https://github.com/vicckm/projeto-globo/blob/master/src/public/img/pag1.jpg) 29 | 30 | ![Pagina de resultado parcial](https://github.com/vicckm/projeto-globo/blob/master/src/public/img/pag2.jpg) 31 | -------------------------------------------------------------------------------- /src/dao/participantesDao.js: -------------------------------------------------------------------------------- 1 | const paginaResultado = require("../views/admin"); 2 | 3 | class ParticipantesDao { 4 | constructor(db) { 5 | this._db = db; 6 | } 7 | 8 | inserir(participante) { 9 | return new Promise((resolve, reject) => { 10 | if (participante == "participante_1") { 11 | const INSERT = ` 12 | INSERT INTO votacao (id_participante_1, votos_participante_1, id_participante_2, votos_participante_2) 13 | VALUES (1, 1, 0, 0); 14 | `; 15 | 16 | this._db.run(INSERT, (err) => { 17 | if (err) { 18 | reject("Não foi possível inserir na tabela 1"); 19 | } 20 | 21 | resolve(paginaResultado); 22 | }); 23 | } else { 24 | const INSERT = ` 25 | INSERT INTO votacao (id_participante_1, votos_participante_1, id_participante_2, votos_participante_2) 26 | VALUES (0, 0, 2, 1); 27 | `; 28 | 29 | this._db.run(INSERT, (err) => { 30 | if (err) { 31 | reject("Não foi possível inserir na tabela 2"); 32 | } 33 | 34 | resolve(paginaResultado); 35 | }); 36 | } 37 | }); 38 | } 39 | 40 | computaVotos() { 41 | return new Promise((resolve, reject) => { 42 | const query = ` 43 | SELECT SUM(votos_participante_1) AS part1, SUM(votos_participante_2) AS part2 FROM votacao; 44 | `; 45 | 46 | this._db.all(query, [], (err, rows) => { 47 | if (err) { 48 | reject("Não foi possível computar os votos"); 49 | } 50 | 51 | resolve(rows) 52 | }); 53 | }); 54 | } 55 | } 56 | 57 | module.exports = ParticipantesDao; 58 | -------------------------------------------------------------------------------- /src/public/css/index.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Bangers&display=swap'); 2 | 3 | body { 4 | background:#f1f1f1; 5 | font-family: 'Bangers', cursive; 6 | color:#6bc5d2; 7 | padding: 3%; 8 | } 9 | 10 | h2 { 11 | font-weight: bold; 12 | text-align:center; 13 | font-size:50px; 14 | color: #e5487b; 15 | } 16 | 17 | .votacao { 18 | width: 100%; 19 | display: inline-block; 20 | 21 | } 22 | 23 | .votacao .titulo { 24 | font-size: 24px; 25 | color: #5cb4c2; 26 | text-align: center; 27 | font-weight: bold; 28 | } 29 | .titulo { 30 | font-weight: bold; 31 | } 32 | 33 | .legenda { 34 | text-align: center; 35 | font-size: 18px; 36 | } 37 | 38 | .container { 39 | display: flex; 40 | justify-content: center; 41 | text-align: center; 42 | } 43 | 44 | .container .fotoParticipante { 45 | display: flex; 46 | position: relative; 47 | width: 250px; 48 | height: 250px; 49 | align-items: center; 50 | 51 | } 52 | 53 | .participante { 54 | display: inline-block; 55 | margin: 3%; 56 | } 57 | 58 | .fotoParticipante { 59 | border: 6px solid #fff; 60 | } 61 | 62 | .checked { 63 | border: 6px solid #E5487B; 64 | } 65 | 66 | .form { 67 | display: inline-block; 68 | justify-content: space-between; 69 | width: 90%; 70 | } 71 | 72 | .container .checkParticipante { 73 | display: flex; 74 | position: absolute; 75 | top: 0; 76 | left: 0; 77 | z-index: 1; 78 | opacity: 0; 79 | } 80 | 81 | .fotoParticipante { 82 | text-align: center; 83 | position: relative; 84 | cursor: pointer; 85 | color: #E5487B; 86 | } 87 | 88 | .votarBotao { 89 | width: 20%; 90 | height: 50px; 91 | font-size: 24px; 92 | transform: skew(-20deg); 93 | 94 | } 95 | 96 | .votarBotao:hover { 97 | background-color: #E5487B; 98 | border-color: #E5487B; 99 | } 100 | -------------------------------------------------------------------------------- /src/configs/database/createTable.js: -------------------------------------------------------------------------------- 1 | const exitError = require('./exitError'); 2 | const sqlite = require('sqlite3'); 3 | const db = new sqlite.Database('./database.sqlite', err => 4 | { if(err) return exitError(err) }); 5 | 6 | 7 | const TABLE_PARTICIPANTES = ` 8 | CREATE TABLE IF NOT EXISTS participantes ( 9 | id INTEGER PRIMARY KEY AUTOINCREMENT, 10 | nome TEXT, 11 | url_foto TEXT 12 | ); 13 | ` 14 | 15 | // colocar duas chaves estrangeiras id_participante 1 e 2 e adicionar data final da votação 16 | const TABLE_VOTACAO = ` 17 | CREATE TABLE IF NOT EXISTS votacao ( 18 | id INTEGER PRIMARY KEY AUTOINCREMENT, 19 | id_participante_1 INTEGER, 20 | votos_participante_1 INTEGER, 21 | id_participante_2 INTEGER, 22 | votos_participante_2 INTEGER, 23 | FOREIGN KEY (id_participante_1) REFERENCES participantes(id) 24 | FOREIGN KEY (id_participante_2) REFERENCES participantes(id) 25 | ); 26 | ` 27 | 28 | const INSERT_PARTICIPANTES = ` 29 | INSERT INTO participantes (nome, url_foto) 30 | VALUES ('Bob Esponja', 'https://bit.ly/3jKVint'), 31 | ('Capitão Gancho', 'https://bit.ly/34Fa6xs'), 32 | ('Dexter', 'https://bit.ly/34B1yYG'), 33 | ('Docinho', 'https://bit.ly/2SBIELN'), 34 | ('Elsa', 'https://bit.ly/3jK4g4l'), 35 | ('Fred Flinstone', 'https://bit.ly/2SDyUkc'), 36 | ('Johnny Bravo', 'https://bit.ly/30IxmtC'), 37 | ('Leitão', 'https://bit.ly/2GKoHjc'), 38 | ('Magali', 'https://bit.ly/3jTRMqM'), 39 | ('Margarida', 'https://bit.ly/34zpXha'), 40 | ('Marge Simpson', 'https://bit.ly/3lwtCU1'), 41 | ('Papai Smurf', 'https://bit.ly/2GFRA01'), 42 | ('Penelope Charmosa', 'https://bit.ly/3dajHAf'), 43 | ('Popeye', 'https://bit.ly/30MHxxc'), 44 | ('Ursula', 'https://bit.ly/3dbH6S2'), 45 | ('Velma', 'https://bit.ly/36JWWlF') 46 | ` 47 | 48 | 49 | const INSERT_VOTACAO = ` 50 | INSERT INTO votacao (id_participante_1, votos_participante_1, id_participante_2, votos_participante_2) 51 | VALUES (1, 0, 2, 0) 52 | ` 53 | 54 | db.serialize( () => { 55 | db.run(TABLE_PARTICIPANTES, err => { if(err) return exitError(err) }); 56 | 57 | db.run(TABLE_VOTACAO, err => { if(err) return exitError(err) }); 58 | 59 | // db.run(INSERT_PARTICIPANTES, err => { if(err) return exitError(err) }); 60 | 61 | // db.run(INSERT_VOTACAO, err => { if(err) return exitError(err) }); 62 | }) 63 | -------------------------------------------------------------------------------- /src/views/index.js: -------------------------------------------------------------------------------- 1 | const page = ` 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | Votação 12 | 13 | 14 | 15 | 16 |
17 |
18 |

Quem deve deixar as telinhas?

19 |
20 |
21 |

Vote para passar a borracha e eliminar um desses participantes!

22 |
23 |
24 | 25 |
26 |
27 | 31 | 33 |
34 |
35 | 39 | 41 |
42 |
43 | 44 |
45 |
46 |
47 |
48 | 59 | 60 | 61 | ` 62 | 63 | module.exports = page; -------------------------------------------------------------------------------- /src/views/admin.js: -------------------------------------------------------------------------------- 1 | const admin = (part1, part2) => { 2 | return ` 3 | 4 | 5 | 6 | 7 | 8 | 9 | Parcial de Votos 10 | 42 | 43 | 44 |

Resultado Parcial

45 |
46 |
47 | 48 |

Bob Esponja

49 |
50 |
51 |
52 | 53 |

Popeye

54 |
55 |
56 | 57 | 58 | 83 | 84 | 85 | `; 86 | }; 87 | 88 | module.exports = admin; 89 | --------------------------------------------------------------------------------