Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}"
}
]
}
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* HTML5 e CSS3
* Interação com JSON para renderizar os produtos
* Interação com JSON para filtar os produtos
* Funcionalidade de adicionar ao carrinho*
* Funcionalidade de adicionar ao carrinho
* Funcionalidade de carregar mais produtos
* Não utilizar Bootstrap!

Expand All @@ -55,4 +55,12 @@
* Responsividade
* REACT

###### dúvidas: getdevs@profite.com.br
###### dúvidas: getdevs@profite.com.br
```
# Seguem as intruções para rodar o projeto:
Abrir a pasta "angular-ver" e rodar o comando "npm install" e iniciar o mongo e mongod
Após a instalação rodar o comando "nodemon"
Para cadastrar novos produtos, abrir o seguinte link "localhost:3001/#/cadastro"
Depois de cadastrar os produtos, navegue até "http://localhost:3001/#/livros"
Obs: no campo "Genero" preencher com "Fantasia" ou "Policial"
```
89 changes: 89 additions & 0 deletions angular-ver/app/api/livro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
var mongoose = require('mongoose');

module.exports = function (app) {

var model = mongoose.model('Livro');
var modelo = mongoose.model('Carrinho');
/*As variaveis são para definir diferentes coleções ao banco de Dados,
a segunda coleção é para ser o carrinho de compras*/

var api = {};
api.lista = function (req, res) {
model.find()
.then(function(livros) {
res.json(livros);
}, function (error) {
console.log("Erro na api lista")
console.log(erro);
res.sendStatus(500);
});
}
/*Aqui termina a api para listar os livros*/

/*Aqui começam as apis para filtrar os livros, ao realizar mudança em uma,
fazer verificar se a mesma foi realizado em todos*/
api.filtroF = function (req, res) {
model.find()
.then(function(livros) {
for(i = 0; i < livros.length; i++);
function compativel(n){
if(n.genero == "Fantasia"){
return n;
}
};

var filtrado = livros.filter(compativel);
res.json(filtrado);
}, function (error) {
console.log("Erro na api Filtro Fantasia")
console.log(erro);
res.sendStatus(500);
});
}

api.filtroR = function (req, res) {
model.find()
.then(function(livros) {
for(i = 0; i < livros.length; i++);
function compativel(n){
if(n.genero == "Policial"){
return n;
}
};

var filtrado = livros.filter(compativel);
res.json(filtrado);
}, function (error) {
console.log("Erro na api Filtro Policial")
console.log(erro);
res.sendStatus(500);
});
}

/*Aqui termina o codigo das apis de filtro*/
api.adiciona = function (req, res) {

model.create(req.body)
.then(function (livros) {
res.json(livros);
}, function (error) {
console.log("Erro na api adicionar produtos ao db")
console.log(erro);
res.sendStatus(500);
});
}

api.adicionar = function (req, res) {

modelo.create(req.body)
.then(function (livros) {
res.json(livros);
}, function (error) {
console.log("Erro na api Adicionar ao Carrinho")
console.log(erro);
res.sendStatus(500);
});
}

return api;
}
21 changes: 21 additions & 0 deletions angular-ver/app/models/carrinho.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var mongoose = require('mongoose');

var schema = new mongoose.Schema({
titulo: {
type: String,
},
url: {
type: String,
},
preco: {
type: Number,
},
editora: {
type: String,
},
genero: {
type: String,
}
});

mongoose.model('Carrinho', schema);
25 changes: 25 additions & 0 deletions angular-ver/app/models/livro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var mongoose = require('mongoose');

var schema = new mongoose.Schema({
titulo: {
type: String,
required: true
},
url: {
type: String,
required: true
},
preco: {
type: Number,
required: true
},
editora: {
type: String,
required: true
},
genero: {
type: String,
}
});

mongoose.model('Livro', schema);
19 changes: 19 additions & 0 deletions angular-ver/app/routes/livro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = function (app) {

var api = app.api.livro;

app.route('/v1/livros')
.get(api.lista)
.post(api.adiciona)

app.route('/v1/fantasia')
.get(api.filtroF);

app.route('/v1/policial')
.get(api.filtroR);

app.route('/v1/carrinho')
.post(api.adicionar)

return app;
};
24 changes: 24 additions & 0 deletions angular-ver/config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = function (uri) {
var mongoose = require('mongoose');

mongoose.connect(uri);

mongoose.connection.on('conconnected', function () {
console.log("Aplicação contectada ao banco de dados!")
});

mongoose.connection.on('error', function (error) {
console.log("Erro na conecxão com o db: " + error);
});

mongoose.connection.on('disconnected', function () {
console.log("Aplicação descontectada do banco de dados!")
});

process.on("SIGINT", function () {
mongoose.connection.close(function () {
console.log("Aplicação finzalida, conexão finalizada!")
process.exit(0);
});
});
};
15 changes: 15 additions & 0 deletions angular-ver/config/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var express = require('express');
var consign = require('consign');
var bodyParser = require('body-parser');
var app = express();

app.use(express.static('./public'));
app.use(bodyParser.json());

consign({ cwd: 'app' })
.include('models')
.then('api')
.then('routes')
.into(app);

module.exports = app;
15 changes: 15 additions & 0 deletions angular-ver/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions angular-ver/node_modules/.bin/mime.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions angular-ver/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions angular-ver/node_modules/.bin/semver.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading