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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions database/addPokemon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* arquivo responsavel por adicionar um novo pokemon
*/

const {conectarBanco} = require('./coneccao')
const { pokemons } = require('./pokemonSchema')

async function addPokemons(novoPokemon)
{
try {
let addPokemon = new pokemons(novoPokemon)
await addPokemon.save()
console.log("pokemon adicionado")
conectarBanco.desconectar
return "adicionado"
} catch (error) {
console.log("error ao adicionar pokemon")
}
}

exports.addPokemons = addPokemons
22 changes: 22 additions & 0 deletions database/apagarPokemon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* arquivo responsavel por apagar um pokemon pelo nome
*/

const {conectarBanco} = require('./coneccao')
const { pokemons } = require('./pokemonSchema')

async function apagarPokemon(_pokemon) {
try {
pokemons.findOneAndDelete({Name: _pokemon})
.then(rst=>{
console.log("pokemon apagado com sucesso")
return rst
})
await conectarBanco.desconectar
return "apagado"
} catch (error) {
console.log("falha ao apagar o pokemon")
}
}

exports.apagarPokemon = apagarPokemon
45 changes: 45 additions & 0 deletions database/coneccao.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* classe de conecção com o banco mongoDB
* a conecção com o banco é feita assim que a classe é importada
* para o outro arquivo, apesar de fornecer o metodo conectar
* este não é necessario
*/

const mongoose = require("mongoose")

class conectarBanco{
constructor(){
try {
this.conectar = mongoose.connect("mongodb+srv://bruno:[email protected]/pokemons?retryWrites=true&w=majority",
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
})
console.log("conecção\n ao mongo feita com sucesso")
} catch (error) {
console.log("ocorreu um erro ao conectar \n, error")
}
return this.conectar
}

conectar(){
mongoose.connect("mongodb+srv://bruno:[email protected]/pokemons?retryWrites=true&w=majority",
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
})
}

desconectar(){
try {
mongoose.disconnect()
console.log("desconecatdo do banco de dados")
} catch (error) {
console.log("erro ao desconectar", error)
}
}
}

exports.conectarBanco = new conectarBanco()
26 changes: 26 additions & 0 deletions database/editaPokemon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const {conectarBanco} = require('./coneccao')
const { pokemons } = require('./pokemonSchema')

/**
* arquivo responsavel por editar um pokemon
* @param {recebe o nome do pokemon} filtro
* @param {recebe um objeto com os novos dados do pokemon} novoPokemon
*/

async function editarPokemon(filtro, novoPokemon) {
try {
return await pokemons.findOneAndUpdate({ Name: filtro}, novoPokemon)
.then((rst)=> {
console.log("edicao feita com sucesso")
conectarBanco.desconectar
return "feito"
})

} catch (error) {
console.log("erro ao editar o pokemon", error)
return "ops! erro ocorrido"
}

}

exports.editarPokemon = editarPokemon
45 changes: 45 additions & 0 deletions database/pesquisaPokemon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* arquivo responsavel por pesquisar os pokemons, este arquivo
* estabelece um limite na pesquisa fazendo a paginacao e aliviando
* a carga do servidor fornecendo apenas o necessario para o usuario
*
* A forma de pesquisa é livre ou seja o aplicativo que estiver
* consumindo está api é livre para pesquisar por qualquer categoria
* desde que esta se encontre disponivel no documento da coleção
* do mongoDB
*/

const {conectarBanco} = require('./coneccao')
const { pokemons } = require('./pokemonSchema')

async function pesquisaPokemon(filtro = {}, op = null, quantidade = 0, limite = 15) {
if(quantidade != 0){
quantidade = quantidade * limite - limite
}
try {
return await pokemons.find({[filtro]: {$regex:op, $options:"$i"}}).limit(limite).skip(quantidade)
.then(resultados => {
conectarBanco.desconectar
return resultados
})
} catch (error) {
console.log("error ao buscar pokemon", error)
}
}

async function pesquisaCategoria(filtro = {}, op = null, quantidade = 0, limite = 15) {
if(quantidade != 0){
quantidade = quantidade * limite - limite
}
try {
return await pokemons.find({[filtro]: op}).limit(limite).skip(quantidade)
.then(resultados => {
conectarBanco.desconectar
return resultados
})
} catch (error) {
console.log("error ao buscar pokemon", error)
}
}

module.exports = {pesquisaPokemon, pesquisaCategoria}
39 changes: 39 additions & 0 deletions database/pokemonSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* arquivo responsavel por padronizar os dados
* que irão passar pelo banco
*/

const mongoose = require("mongoose")

const pokemonSchema = new mongoose.Schema({
Name: String,
PokedexNumber: Number,
Generation: Number,
EvolutionStage: Number,
Evolved: Number,
FamilyID: Number,
CrossGen: Number,
Type1: String,
Type2: String,
Weather1: String,
Weather2: String,
STATTOTAL: Number,
ATK: Number,
DEF: Number,
STA: Number,
Legendary: Number,
Aquireable: Number,
Spawns: Number,
Regional: Number,
Raidable: Number,
Hatchable: Number,
Shiny: Number,
Nest: Number,
New: Number,
NotGettable: Number,
FutureEvolve: Number,
})

const pokemons = mongoose.model("pokemons", pokemonSchema)

exports.pokemons = pokemons
64 changes: 64 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';

const Hapi = require('@hapi/hapi')
const Path = require('path');
const Inert = require('@hapi/inert');


const {pesquise, pesquiseCategoria} = require("./rotas/rotaTodosPaginacao")
const {edite,adiciona} = require("./rotas/rotaEditaEaddPokemon")
const {apague} = require("./rotas/rotaApagaPokemon")
const startServer = async ()=>{
const server = Hapi.server({
port: 3500,
host: 'localhost',
routes: {
files: {
relativeTo: Path.join(__dirname, 'public')
}
}
});

await server.register(Inert);

let all = {
method: '*',
path: '/{venon}',
handler: {
directory: {
path: '.',
redirectToSlash: true,
index: true,
},
}
}

let index = {
method: '*',
path: '/',
handler: (request, h)=>{
return h.file("index.html")
}
}

let _404 = {
method: '*',
path: '/{any*}',
handler: {
file: './index.html'
}
}

server.route([pesquise,pesquiseCategoria,edite,adiciona, apague, all,index, _404]);

await server.start();
console.log('Server running on %s', server.info.uri);
}

process.on('unhandledRejection', (err) => {

console.log(err);
process.exit(1);
});

startServer();
17 changes: 17 additions & 0 deletions modeloRota/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* classe responsavel por estabelecer um padrao nas rotas
* e facilitar a manutenção de alterações futuras
*/

class rotaPadrao{
constructor(metodo, endereco, funcao){
this.novaRota = {
method: metodo,
path: endereco,
handler: funcao
}
return this.novaRota
}
}

exports.rota = rotaPadrao
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "pokemon-store",
"version": "1.0.0",
"description": "pokemon store, informaçoes e detalhes sobre diversos pokemons",
"main": "index.js",
"repository": "https://github.com/brunosoouza/vaga-fullstack.git",
"author": "Bruno Souza",
"license": "apache2",
"private": false,
"dependencies": {
"@hapi/hapi": "^18.4.0",
"@hapi/inert": "^5.2.2",
"inert": "^5.1.3",
"mongoose": "^5.7.14"
}
}
29 changes: 29 additions & 0 deletions pokemonstore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# pokemonstore

## Project setup
```
yarn install
```

### Compiles and hot-reloads for development
```
yarn run serve
```

### Compiles and minifies for production
```
yarn run build
```

### Run your tests
```
yarn run test
```

### Lints and fixes files
```
yarn run lint
```

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
5 changes: 5 additions & 0 deletions pokemonstore/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
1 change: 1 addition & 0 deletions pokemonstore/dist/css/app.fc3f7d2f.css

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

1 change: 1 addition & 0 deletions pokemonstore/dist/css/chunk-vendors.18521181.css

Large diffs are not rendered by default.

Binary file added pokemonstore/dist/favicon.ico
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pokemonstore/dist/img/icons/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pokemonstore/dist/img/icons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pokemonstore/dist/img/icons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pokemonstore/dist/img/icons/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading