Skip to content
This repository has been archived by the owner on May 15, 2022. It is now read-only.

Commit

Permalink
Finalizado Crud Parcial
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarcon83 committed Apr 30, 2021
1 parent 47aef3b commit 2d00d11
Show file tree
Hide file tree
Showing 18 changed files with 545 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dia 63 e 64 - Node - MiniCrud/minicrud/views/mostrar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<%= details.nome %>
</td>
<td>
<%= details.cidade %>
<%= details.cargahoraria %>
</td>
<td><a href="/editar/<%= details._id %>"> Editar </a> - <a href="/apagar/<%= details._id %>"> Apagar </a></td>
</tr>
Expand Down
33 changes: 33 additions & 0 deletions Dia 64 - Node - Projeto Escola/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const express = require("express")
const app = express()
const mongoose = require("mongoose")

// Conexão a DB
const LINKDB = "mongodb+srv://admin:[email protected]/escola2?retryWrites=true&w=majority"

mongoose.connect(LINKDB, { useUnifiedTopology: true, useNewUrlParser: true }, (err, client) => {
if (err) return console.log(err);

db = mongoose.connection;
console.log("BD Conectado");
});


// Middlewares
app.use(express.urlencoded({ extended: true }));
app.use(express.json());

// configura a view
app.set("view engine", "ejs");

// Importa as Routes
const Router = require('./routes/index');
app.use('/', Router);


// Iniciamos o servidor
const PORTA = 3000;

app.listen(PORTA, () => {
console.log("Servidor ativado na porta " + PORTA);
});
11 changes: 11 additions & 0 deletions Dia 64 - Node - Projeto Escola/conectarbd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mongoose = require("mongoose");

const LINKDB = "mongodb+srv://admin:[email protected]/escola2?retryWrites=true&w=majority"

async function conectarDB(){
await mongoose.connect(LINKDB, { useNewUrlParser: true, useUnifiedTopology: true });
console.log("DB conectada")
return client.db("escola2")
}

module.exports = conectarDB()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const Disciplina = require("../models/disciplina");
const async = require("async");

// Listar
exports.listar = (req, res) => {
Disciplina.find((err, resultado) => {
if (err) return console.log(err);

res.render("disciplinas.ejs", { dados: resultado });
});
};

// Cadastrar
exports.cadastrar = (req, res) => {
res.render("disciplinasnova.ejs");
};

exports.cadastrarPost = async (req, res) => {
try {
const disciplina = new Disciplina({
nome: req.body.nome,
cargahoraria: req.body.cargahoraria,
});
await disciplina.save();
res.redirect("../disciplinas");
} catch (err) {
res.send(err);
}
};

// Editar
exports.editar = (req, res) => {
res.render("disciplinaseditar.ejs");
};

// Apagar
exports.apagar = async (req, res) => {
try {
const id = req.params.id;
await Disciplina.findByIdAndDelete(id);
res.redirect("/disciplinas");
} catch (err) {
res.send(err);
}
};
Empty file.
36 changes: 36 additions & 0 deletions Dia 64 - Node - Projeto Escola/models/aluno.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
let mongoose = require("mongoose");

let alunoSchema = new mongoose.Schema({
matricula: {
type: String,
required: true,
maxLenght: 15,
},
nome: {
type: String,
required: true,
maxLenght: 80,
},
cpf: {
type: String,
required: true,
maxLenght: 14,
},
rg: {
type: String,
required: true,
maxLenght: 25,
},
endereco: {
type: String,
required: true,
maxLenght: 200,
},
telefone: {
type: String,
required: true,
maxLenght: 20,
},
});

module.exports = mongoose.model("aluno", alunoSchema)
16 changes: 16 additions & 0 deletions Dia 64 - Node - Projeto Escola/models/disciplina.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let mongoose = require("mongoose");

let disciplinaSchema = new mongoose.Schema({
nome: {
type: String,
required: true,
maxLenght: 80,
},
cargahoraria: {
type: String,
required: true,
maxLenght: 4,
},
});

module.exports = mongoose.model("disciplina", disciplinaSchema)
31 changes: 31 additions & 0 deletions Dia 64 - Node - Projeto Escola/models/professor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
let mongoose = require("mongoose");

let professorSchema = new mongoose.Schema({
nome: {
type: String,
required: true,
maxLenght: 80,
},
cpf: {
type: String,
required: true,
maxLenght: 14,
},
rg: {
type: String,
required: true,
maxLenght: 25,
},
endereco: {
type: String,
required: true,
maxLenght: 200,
},
telefone: {
type: String,
required: true,
maxLenght: 20,
},
});

module.exports = mongoose.model("professor", professorSchema)
Loading

0 comments on commit 2d00d11

Please sign in to comment.