This repository has been archived by the owner on May 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
4,342 additions
and
24 deletions.
There are no files selected for viewing
Empty file.
54 changes: 54 additions & 0 deletions
54
Dia 64 - Node - Projeto Escola/controllers/alunosController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const Aluno = require("../models/aluno"); | ||
|
||
// Listar | ||
exports.listar = (req, res) => { | ||
Aluno.find((err, resultado) => { | ||
if (err) return console.log(err); | ||
|
||
res.render("alunos.ejs", { dados: resultado }); | ||
}); | ||
}; | ||
|
||
// Cadastrar | ||
exports.cadastrar = (req, res) => { | ||
res.render("alunosnovo.ejs"); | ||
}; | ||
|
||
exports.cadastrarPOST = async (req, res) => { | ||
try { | ||
const aluno = new Aluno({ ...req.body }); | ||
await aluno.save(); | ||
res.redirect("/alunos"); | ||
} catch (err) { | ||
return console.log(err); | ||
} | ||
}; | ||
|
||
// Editar | ||
exports.editar = async (req, res) => { | ||
try { | ||
const resultado = await Aluno.findById(req.params.id); | ||
res.render("alunoseditar.ejs", {dados: resultado}); | ||
} catch (err) { | ||
res.send(err); | ||
} | ||
}; | ||
|
||
exports.editarPOST = async (req, res) => { | ||
try { | ||
await Aluno.findOneAndReplace({_id: req.params.id},{ ...req.body }); | ||
res.redirect("/alunos"); | ||
} catch (err) { | ||
return console.log(err); | ||
} | ||
}; | ||
|
||
// Apagar | ||
exports.apagar = async (req, res) => { | ||
try { | ||
await Aluno.findByIdAndDelete(req.params.id); | ||
res.redirect("/alunos"); | ||
} catch (err) { | ||
return console.log(err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const Professor = require("../models/professor"); | ||
|
||
// Listar | ||
exports.listar = (req, res) => { | ||
Professor.find((err, resultado) => { | ||
if (err) return console.log(err); | ||
|
||
res.render("professores.ejs", { dados: resultado }); | ||
}); | ||
}; | ||
|
||
// Cadastrar | ||
exports.cadastrar = (req, res) => { | ||
res.render("professoresnovo.ejs"); | ||
}; | ||
|
||
exports.cadastrarPOST = async (req, res) => { | ||
try { | ||
const professor = new Professor({ ...req.body }); | ||
await professor.save(); | ||
res.redirect("/professores"); | ||
} catch (err) { | ||
return console.log(err); | ||
} | ||
}; | ||
|
||
// Editar | ||
exports.editar = async (req, res) => { | ||
try { | ||
const resultado = await Professor.findById(req.params.id); | ||
res.render("professoreseditar.ejs", {dados: resultado}); | ||
} catch (err) { | ||
res.send(err); | ||
} | ||
}; | ||
|
||
exports.editarPOST = async (req, res) => { | ||
try { | ||
await Professor.findOneAndReplace({_id: req.params.id},{ ...req.body }); | ||
res.redirect("/professores"); | ||
} catch (err) { | ||
return console.log(err); | ||
} | ||
}; | ||
|
||
// Apagar | ||
exports.apagar = async (req, res) => { | ||
try { | ||
await Professor.findByIdAndDelete(req.params.id); | ||
res.redirect("/professores"); | ||
} catch (err) { | ||
return console.log(err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,66 @@ | ||
const express = require('express'); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const disciplinas = require('../controllers/disciplinasController.js') | ||
const alunos = require("../controllers/alunosController.js"); | ||
const disciplinas = require("../controllers/disciplinasController.js"); | ||
const professores = require("../controllers/professoresController.js"); | ||
|
||
// Página Inicial. | ||
router.get('/', (req, res) => { | ||
router.get("/", (req, res) => { | ||
res.render("index.ejs"); | ||
}); | ||
}); | ||
|
||
|
||
// Rotas Disciplinas | ||
// ------------ // | ||
// Rotas Alunos // | ||
// ------------ // | ||
|
||
// Listar | ||
router.get('/disciplinas', disciplinas.listar) | ||
router.get("/alunos", alunos.listar); | ||
|
||
// Cadastrar | ||
router.get('/disciplinas/nova', disciplinas.cadastrar) | ||
router.post('/disciplinas/nova', disciplinas.cadastrarPost) | ||
router.get("/alunos/novo", alunos.cadastrar); | ||
router.post("/alunos/novo", alunos.cadastrarPOST); | ||
|
||
// Editar | ||
router.get('/disciplinas/editar/:id', disciplinas.editar) | ||
router.post('/disciplinas/editar/:id', disciplinas.editarPOST) | ||
router.get("/alunos/editar/:id", alunos.editar); | ||
router.post("/alunos/editar/:id", alunos.editarPOST); | ||
|
||
// Apagar | ||
router.get('/disciplinas/apagar/:id', disciplinas.apagar) | ||
router.get("/alunos/apagar/:id", alunos.apagar); | ||
|
||
// ----------------- // | ||
// Rotas Disciplinas // | ||
// ----------------- // | ||
|
||
// Listar | ||
router.get("/disciplinas", disciplinas.listar); | ||
|
||
// Cadastrar | ||
router.get("/disciplinas/nova", disciplinas.cadastrar); | ||
router.post("/disciplinas/nova", disciplinas.cadastrarPOST); | ||
|
||
// Editar | ||
router.get("/disciplinas/editar/:id", disciplinas.editar); | ||
router.post("/disciplinas/editar/:id", disciplinas.editarPOST); | ||
|
||
// Apagar | ||
router.get("/disciplinas/apagar/:id", disciplinas.apagar); | ||
|
||
// ----------------- // | ||
// Rotas Professores // | ||
// ----------------- // | ||
|
||
// Listar | ||
router.get("/professores", professores.listar); | ||
|
||
// Cadastrar | ||
router.get("/professores/novo", professores.cadastrar); | ||
router.post("/professores/novo", professores.cadastrarPOST); | ||
|
||
// Editar | ||
router.get("/professores/editar/:id", professores.editar); | ||
router.post("/professores/editar/:id", professores.editarPOST); | ||
|
||
// Apagar | ||
router.get("/professores/apagar/:id", professores.apagar); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<%- include('head'); -%> | ||
|
||
<main> | ||
<div class="container"> | ||
<div class="d-flex justify-content-between align-items-end"> | ||
<h1 class="my-3">Alunos</h1> <a href="alunos/novo" class="btn btn-primary flex">Cadastrar Novo</a> | ||
</div> | ||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<td scope="col">Nome</td> | ||
<td scope="col">CPF</td> | ||
<td scope="col">RG</td> | ||
<td scope="col">Endereço</td> | ||
<td scope="col">Telefone</td> | ||
<td scope="col">Matrícula</td> | ||
<td scope="col">Ações</td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% dados.forEach(function(dados) { %> | ||
<tr> | ||
<td> | ||
<%= dados.nome %> | ||
</td> | ||
<td> | ||
<%= dados.cpf %> | ||
</td> | ||
<td> | ||
<%= dados.rg %> | ||
</td> | ||
<td> | ||
<%= dados.endereco %> | ||
</td> | ||
<td> | ||
<%= dados.telefone %> | ||
</td> | ||
<td> | ||
<%= dados.matricula %> | ||
</td> | ||
<td> | ||
<a class="btn btn-warning" href="alunos/editar/<%= dados._id %>"> Editar </a> | ||
<a class="btn btn-danger" href="alunos/apagar/<%= dados._id %>"> Apagar </a> | ||
</td> | ||
</tr> | ||
<% }) %> | ||
</tbody> | ||
|
||
|
||
</div> | ||
</main> | ||
|
||
<%- include('foot'); -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<%- include('head'); -%> | ||
|
||
<main> | ||
|
||
<div class="container"> | ||
<div class="d-flex justify-content-between align-items-end"> | ||
<h1 class="my-3">Editar Aluno</h1> <a href="/alunos" class="btn btn-warning">Voltar</a> | ||
</div> | ||
|
||
<form action="/alunos/editar/<%= dados._id %>" method="post"> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="nome">Nome do Aluno</label> | ||
<input class="form-control" type="text" name="nome" id="nome" value="<%= dados.nome %>" required> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="cpf">CPF</label> | ||
<input class="form-control" type="text" name="cpf" id="cpf" value="<%= dados.cpf %>" required> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="rg">RG</label> | ||
<input class="form-control" type="text" name="rg" id="rg" value="<%= dados.rg %>" required> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="endereco">Endereço</label> | ||
<input class="form-control" type="text" name="endereco" id="endereco" value="<%= dados.endereco %>" required> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="telefone">Telefone</label> | ||
<input class="form-control" type="text" name="telefone" id="telefone" value="<%= dados.telefone %>" required> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="matricula">Matrícula</label> | ||
<input class="form-control" type="text" name="matricula" id="matricula" value="<%= dados.matricula %>" | ||
required> | ||
</div> | ||
|
||
<button class="btn btn-success" type="submit">Alterar</button> | ||
</form> | ||
|
||
</div> | ||
</main> | ||
|
||
<%- include('foot'); -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<%- include('head'); -%> | ||
|
||
<main> | ||
|
||
<div class="container"> | ||
<div class="d-flex justify-content-between align-items-end"> | ||
<h1 class="my-3">Cadastrar Aluno</h1> <a href="/alunos" class="btn btn-warning">Voltar</a></div> | ||
|
||
<form action="/alunos/novo" method="post"> | ||
<div class="mb-3"> | ||
<label class="form-label" for="nome">Nome do Aluno</label> | ||
<input class="form-control" type="text" name="nome" id="nome" required> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="cpf">CPF</label> | ||
<input class="form-control" type="text" name="cpf" id="cpf" required> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="rg">RG</label> | ||
<input class="form-control" type="text" name="rg" id="rg" required> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="endereco">Endereço</label> | ||
<input class="form-control" type="text" name="endereco" id="endereco" required> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="telefone">Telefone</label> | ||
<input class="form-control" type="text" name="telefone" id="telefone" required> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label" for="matricula">Matrícula</label> | ||
<input class="form-control" type="text" name="matricula" id="matricula" required> | ||
</div> | ||
|
||
<button class="btn btn-success" type="submit">Cadastrar</button> | ||
</form> | ||
|
||
</div> | ||
</main> | ||
|
||
<%- include('foot'); -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.