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
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# compiled output
/dist
/node_modules
25 changes: 25 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.5'

services:

postgres:
container_name: postgres_container
image: postgres
environment:
POSTGRES_USER: docker
POSTGRES_PASSWORD: docker
POSTGRES_DB: pokemongodb
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- postgres
restart: unless-stopped

networks:
postgres:

volumes:
postgres:
15 changes: 15 additions & 0 deletions backend/ormconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type" : "postgres",
"host" : "localhost",
"port": 5432,
"username" : "docker",
"password" : "docker",
"database" : "pokemondb",
"migrations" : ["./src/database/migrations/**.ts"],
"entities" : [
"./src/entities/**.ts"
],
"cli": {
"migrationsDir" : "./src/database/migrations"
}
}
27 changes: 27 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "backend",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "tsnd --transpile-only --respawn --ignore-watch node_modules src/server.ts",
"typeorm": "ts-node-dev node_modules/typeorm/cli.js"
},
"dependencies": {
"axios": "^0.21.1",
"cors": "^2.8.5",
"express": "^4.17.1",
"pg": "^8.7.1",
"reflect-metadata": "^0.1.13",
"typeorm": "^0.2.37",
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/uuid": "^8.3.1",
"ts-node-dev": "^1.1.8",
"typescript": "^4.3.5"
}
}
268 changes: 268 additions & 0 deletions backend/src/controllers/PokemonController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
import { Request, Response } from 'express';
import { PokemonService } from '../services/PokemonService';

class PokemonController {

async index(request: Request, response: Response){
const pokemonService = new PokemonService();

const {
search,
page,
name,
pokedex_number,
generation,
evolution_stage,
evolved,
family_id,
cross_gen,
type_one,
type_two,
weather_one,
weather_two,
stat_total,
atk,
def,
sta,
legendary,
aquireable,
spawns,
regional,
raidable,
hatchable,
shiny,
nest,
is_new,
not_gettable,
future_evolve,
cp_100_40,
cp_100_39
} = request.query;

try{
const pokemon = await pokemonService.index({
search,
page,
name,
pokedex_number,
generation,
evolution_stage,
evolved,
family_id,
cross_gen,
type_one,
type_two,
weather_one,
weather_two,
stat_total,
atk,
def,
sta,
legendary,
aquireable,
spawns,
regional,
raidable,
hatchable,
shiny,
nest,
is_new,
not_gettable,
future_evolve,
cp_100_40,
cp_100_39
});

return response.status(200).json(pokemon)
}catch(err){
return response.status(400).json({error: err.message});
}
}

async show(request:Request, response: Response){
const pokemonService = new PokemonService();

const { id } = request.params;

try{
const pokemon = await pokemonService.show(id)

return response.status(200).json(pokemon)
}
catch(err){
return response.status(400).json({error: err.message});
}
}

async store(request: Request, response: Response): Promise<Response>{
const pokemonService = new PokemonService();

const {
name,
pokedex_number,
img_name,
generation,
evolution_stage,
evolved,
family_id,
cross_gen,
type_one,
type_two,
weather_one,
weather_two,
stat_total,
atk,
def,
sta,
legendary,
aquireable,
spawns,
regional,
raidable,
hatchable,
shiny,
nest,
is_new,
not_gettable,
future_evolve,
cp_100_40,
cp_100_39
} = request.body;

try{
const pokemon = await pokemonService.store({
name,
pokedex_number,
img_name,
generation,
evolution_stage,
evolved,
family_id,
cross_gen,
type_one,
type_two,
weather_one,
weather_two,
stat_total,
atk,
def,
sta,
legendary,
aquireable,
spawns,
regional,
raidable,
hatchable,
shiny,
nest,
is_new,
not_gettable,
future_evolve,
cp_100_40,
cp_100_39
})

return response.status(201).json(pokemon)
}
catch(err){
return response.status(400).json({error: err.message});
}

}

async update(request: Request, response: Response): Promise<Response>{
const pokemonService = new PokemonService();

const { id } = request.params;

const {
name,
pokedex_number,
img_name,
generation,
evolution_stage,
evolved,
family_id,
cross_gen,
type_one,
type_two,
weather_one,
weather_two,
stat_total,
atk,
def,
sta,
legendary,
aquireable,
spawns,
regional,
raidable,
hatchable,
shiny,
nest,
is_new,
not_gettable,
future_evolve,
cp_100_40,
cp_100_39
} = request.body;

try{
const pokemon = await pokemonService.update({
id,
name,
pokedex_number,
img_name,
generation,
evolution_stage,
evolved,
family_id,
cross_gen,
type_one,
type_two,
weather_one,
weather_two,
stat_total,
atk,
def,
sta,
legendary,
aquireable,
spawns,
regional,
raidable,
hatchable,
shiny,
nest,
is_new,
not_gettable,
future_evolve,
cp_100_40,
cp_100_39
})

return response.status(201).json(pokemon)
}
catch(err){
return response.status(400).json({error: err.message});
}

}

async delete(request: Request, response: Response){
const pokemonService = new PokemonService();

const { id } = request.params;

try{
const pokemon = await pokemonService.delete(id)

return response.status(200).json(pokemon)
}
catch(err){
return response.status(400).json({error: err.message});
}
}
}

export { PokemonController }
3 changes: 3 additions & 0 deletions backend/src/database/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createConnection } from 'typeorm';

createConnection();
Loading