Skip to content

pokepokepokedex/pokedex-backend-cj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pokestats API

Introduction

pokestats.netlify.com

FIND any Pokémon. Find your favorite Pokémon right away through our extensive directory. LEARN about your Pokémon. Uncover everything you need to know about any Pokemon, including their HP, strengths, weaknesses, special defenses, and more! TRACK and grow your Pokémon Build your very own powerful team of Pokémon. You can build and customize as many teams as you want.

Table of Contents


Overview

This repository holds all back-end files and resources for pokestats application and its readme documentation. This repository was made during Lambda School's build week where students join a team that consists other students from different cohorts. Each cohorts are responsible for either UI, Front End, Back End, and leading the team. This repository is for th Back end side.


API URL

https://pokepokepokedex.herokuapp.com

Back to Table of Contents


Installation

Fork/Clone the repository. In the same directory as the package.json, in your terminal:

yarn install

This is to install all needed packages. To start the server, in your terminal, type:

yarn server

To test the repository:

yarn test

Back to Table of Contents


DATA SET

Found in: https://www.kaggle.com/rounakbanik/pokemon

Back to Table of Contents


SCHEMA

users

{
  "id": 1,                            // Integer [Primary key]
  "username": "admin",                // String [Required, Unique]
  "password": "password",             // String [Required]
  "email": "[email protected]"  // String [Required, Unique]
}

pokemon

{
  "id": 1,                                      // Integer
  "name": "Bulbasaur",                          // Text
  "pokedex_number": 1,                          // Integer
  "type1": "grass",                             // Text
  "type2": "poison",                            // Text
  "height_m": 0.7,                              // Numeric(3, 1)
  "weight_kg": 6.9,                             // Numeric(4, 1)
  "abilities": "['Overgrow', 'Chlorophyll']",   // Text
  "base_happiness": 70,                         // Integer
  "hp": 45,                                     // Integer
  "attack": 49,                                 // Integer
  "defense": 49,                                // Integer
  "sp_attack": 65,                              // Integer
  "sp_defense": 65,                             // Integer
  "speed": 45,                                  // Integer
  "generation": 1,                              // Integer
  "capture_rate": "45"                          // Text
}

backpack

{
  "id": 1,                                      // Integer [Primary key]
  "type1": fire,                                // String [Required]
  "type2": flying                               // String
  "name": Charizard                             // String [Required]
  "pokedex_number": 9,                          // Integer [Required, Unsigned]
  "users_id": 1                                 // Integer [Foreign Key]
}

Back to Table of Contents

Pagination

navigate at the end of url by: ?page=2

{
  "total": 1,
  "last_page": 1, 
  "per_page": 15,
  "current_page": 1,
  "from": 0,
  "to": 1,
  "data": []
}

Back to Table of Contents

Test Accounts


  username: 'admin',
  password: 'password'


  username: 'beniscool',
  password: 'password'


  username: 'ceciljohn',
  password: 'password'

Back to Table of Contents

API ENDPOINTS

name method endpoint description
Register POST /auth/register Creates a new user to the users table in the database
Login POST /auth/login Checks whether payload from the body matches with a user in the database. On Succesful login, returns a message and a JWT Token
Get all users GET /api/users PROTECTED ROUTE - Returns an array of user objects of all users
Get user by ID GET /api/users/:id PROTECTED ROUTE - Returns an array of object of selected user by ID
Delete user by ID DELETE /api/users/:id delete selected user by ID
Get all pokemon GET /api/pokemon/all PROTECTED ROUTE - Returns an array of pokemon objects of all pokemon(limited)
Get all pokemon by pagination GET /api/pokemon PROTECTED ROUTE - Returns an array of pokemon objects of all pokemon with pagination
Get ErrThang GET /api/pokemon/errthang PROTECTED ROUTE - Gets all pokemon with all properties without pagination
Get pokemon by ID GET /api/pokemon/:id PROTECTED ROUTE - Returns an array of pokemon objects of selected pokemon by ID
Get backpack of specific user GET /api/backpack:id PROTECTED ROUTE - Returns and array of objects of all pokemons in the user's backpack
Get all pokemon GET /api/backpack PROTECTED ROUTE - returns an array of pokemon in backpack object
Insert to backpack POST /api/backpack PROTECTED ROUTE - Inserts payload into the backpack database
Delete in backpack DELETE /api/backpack/:id PROTECTED ROUTE - Delete a specific pokemon in backpack

Back to Table of Contents


AUTH ROUTES

REGISTER

Registers a user

Method Url: /auth/register

HTTP method: [POST]

Headers

name type required description
Content-Type String Yes Must be application/json

Body

name type required description
username String Yes Must be unique
email String Yes Must be unique
password String Yes

example:

{
  username: "ceciljohn",
  password: "password",
  email: "[email protected]"
}

Response

200 (OK)

If you successfully register a user the endpoint will return an HTTP response with a status code 200 and a body as below.

{ 
  "message" : "You have registered, ceciljohn!"
}
400 (Bad Request)

If you send in invalid fields, the endpoint will return an HTTP response with a status code 400 and a body as below.

{
  "error": true,
  "message": "There was a problem with your request."
}

Back to Table of Contents


LOGIN

Logs a user in

Method Url: /auth/login

HTTP method: [POST]

Headers

name type required description
Content-Type String Yes Must be application/json

Body

name type required description
username String Yes Must match a username in the database
password String Yes Must match a password in the database corresponding to above email

example:

{
  username: "ceciljohn",
  password: "password"
}

Response

200 (OK)

If you successfully login, the endpoint will return an HTTP response with a status code 200 and a body as below.

{
  "message": "Welcome ceciljohn!",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTQ0MzM1NjUxLCJleHAiOjE1NzU4OTMyNTF9.uqd2OHBYkGQpwjLTPPiPWYkYOKlG7whQDFkk46xGXoE"
}
400 (Bad Request)

If you send in invalid fields or the passwords do not match, the endpoint will return an HTTP response with a status code 400 and a body as below.

{
  "error": true,
  "message": "There was a problem with your request."
}
404 (Not Found)

If you send in an email address that does not match one in the database, the endpoint will return an HTTP response with a status code 404 and a body as below.

{
  "error": true,
  "message": "The requested content does not exist."
}

Back to Table of Contents


USER ROUTES

GET ALL USERS

Returns all users

Mehod Url: /api/users HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No Bearer JWT authorization token

Response

200 (OK)

If you successfully get al the users, the endpoint will return an HTTP response with a status code 200 and a body as below.

{
  {
    "total": 3,
    "last_page": 1,
    "per_page": 15,
    "current_page": 1,
    "from": 0,
    "to": 3,
    "data": [
      {
        "id": 1,
        "username": "admin",
        "email": "[email protected]"
      },
      {
        "id": 2,
        "username": "beniscool",
        "email": "[email protected]"
      },
      {
        "id": 3,
        "username": "ceciljohn",
        "email": "[email protected]"
      }
    ]
  }
}
400 (Bad Request)

If you send in invalid fields or the password of the user corresponding to the token does not match the currentPassword field, the endpoint will return an HTTP response with a status code 400 and a body as below.

{
  "error": true,
  "message": "There was a problem with your request."
}
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

GET USER BY ID

Returns selected user by ID

Mehod Url: /api/users/:id HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No Bearer JWT authorization token

Parameters

name type required description
id Int Yes Id of specific user

Response

200 (OK)

If you successfully get al the users, the endpoint will return an HTTP response with a status code 200 and a body as below.

{
  "id": 1,
  "username": "admin",
  "email": "[email protected]"
}
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

Back to Table of Contents


DELETE USER

Deletes seletcted user by ID

Mehod Url: /api/users/:id HTTP method: [DELETE]

Headers

name type required description
Content-Type String Yes Must be application/json

Parameters

name type required description
id Int Yes Id of specific user

Response

200 (OK)

If you successfully delete the selected user, the endpoint will return an HTTP response with a status code 200 and a body as below.

{
  "id": 1,
  "username": "admin",
  "email": "[email protected]"
}
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

Back to Table of Contents


UPDATE USER

Updates seletcted user by ID

TBA

Back to Table of Contents


POKEMON ROUTES

GET ALL POKEMON(LIMITED)

Returns all pokemon name and ID

Mehod Url: /api/pokemon/all HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No Bearer JWT authorization token

Response

200 (OK)

If you successfully get all the pokemon, the endpoint will return an HTTP response with a status code 200 and a body as below.

{
  {
        "id": 1,
        "name": "Bulbasaur"
    },
    {
        "id": 2,
        "name": "Ivysaur"
    },
    {
        "id": 3,
        "name": "Venusaur"
    },
    {
        "id": 4,
        "name": "Charmander"
    },
    {
        "id": 5,
        "name": "Charmeleon"
    },
    
    
    ...

   to the 800th+ pokemon object
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

Back to Table of Contents


GET ERRTHANG

Returns all pokemon and pokemon properties

Mehod Url: /api/pokemon/errthang HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No Bearer JWT authorization token

Response

200 (OK)

If you successfully get all the pokemon, the endpoint will return an HTTP response with a status code 200 and a body as below.

{
        "id": 1,
        "name": "Bulbasaur",
        "pokedex_number": 1,
        "type1": "grass",
        "type2": "poison",
        "height_m": 0.7,
        "weight_kg": 6.9,
        "abilities": "['Overgrow', 'Chlorophyll']",
        "base_happiness": 70,
        "hp": 45,
        "attack": 49,
        "defense": 49,
        "sp_attack": 65,
        "sp_defense": 65,
        "speed": 45,
        "generation": 1,
        "capture_rate": "45",
        "graph": [
            1,
            1,
            1,
            0.5,
            0.5,
            0.5,
            2,
            2,
            1,
            0.25,
            1,
            2,
            1,
            1,
            2,
            1,
            1,
            0.5
        ]
    },
    {
        "id": 2,
        "name": "Ivysaur",
        "pokedex_number": 2,
        "type1": "grass",
        "type2": "poison",
        "height_m": 1,
        "weight_kg": 13,
        "abilities": "['Overgrow', 'Chlorophyll']",
        "base_happiness": 70,
        "hp": 60,
        "attack": 62,
        "defense": 63,
        "sp_attack": 80,
        "sp_defense": 80,
        "speed": 60,
        "generation": 1,
        "capture_rate": "45",
        "graph": [
            1,
            1,
            1,
            0.5,
            0.5,
            0.5,
            2,
            2,
            1,
            0.25,
            1,
            2,
            1,
            1,
            2,
            1,
            1,
            0.5
        ]
    },
    
    ...

   to the 800th+ pokemon object
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

Back to Table of Contents


GET ALL POKEMON WITH PAGINATION

Returns all pokemon; 15 per page

Mehod Url: /api/pokemon HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No Bearer JWT authorization token

Response

200 (OK)

If you successfully get all the pokemon with pagination that limits the list to 15 pokemon per page, the endpoint will return an HTTP response with a status code 200 and a body as below.

{
  "total": 801,
  "last_page": 54,
  "per_page": 15,
  "current_page": 1,
  "from": 0,
  "to": 15,
  "data": [
    {
      "id": 1,
      "name": "Bulbasaur",
      "pokedex_number": 1,
      "type1": "grass",
      "type2": "poison",
      "height_m": 0.7,
      "weight_kg": 6.9,
      "abilities": "['Overgrow', 'Chlorophyll']",
      "base_happiness": 70,
      "hp": 45,
      "attack": 49,
      "defense": 49,
      "sp_attack": 65,
      "sp_defense": 65,
      "speed": 45,
      "generation": 1,
      "capture_rate": "45"
    },
    
    ...

    {
      "id": 15,
      "name": "Beedrill",
      "pokedex_number": 15,
      "type1": "bug",
      "type2": "poison",
      "height_m": 1,
      "weight_kg": 29.5,
      "abilities": "['Swarm', 'Sniper']",
      "base_happiness": 70,
      "hp": 65,
      "attack": 150,
      "defense": 40,
      "sp_attack": 15,
      "sp_defense": 80,
      "speed": 145,
      "generation": 1,
      "capture_rate": "45"
    }
  ]
}
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

Back to Table of Contents


GET POKEMON BY ID

Returns selected pokemon by ID

Mehod Url: /api/pokemon/:id HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No Bearer JWT authorization token

Parameters

name type required description
id Int Yes Id of specific pokemon

Response

200 (OK)

If you successfully get the selected pokemon, the endpoint will return an HTTP response with a status code 200 and a body as below.

{
  "id": 151,
  "name": "Mew",
  "pokedex_number": 151,
  "type1": "psychic",
  "type2": null,
  "height_m": 0.4,
  "weight_kg": 4,
  "abilities": "['Synchronize']",
  "base_happiness": 100,
  "hp": 100,
  "attack": 100,
  "defense": 100,
  "sp_attack": 100,
  "sp_defense": 100,
  "speed": 100,
  "generation": 1,
  "capture_rate": "45"
}
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

Back to Table of Contents


BACKPACK ROUTES

GET ALL

Returns all pokemon in backpack

Mehod Url: /api/backpack HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No Bearer JWT authorization token

Response

200 (OK)

If you successfully get all the pokemon in the backpack table, the endpoint will return an HTTP response with a status code 200 and a body as below.

[
    {
        "id": 1,
        "type1": "fire",
        "type2": null,
        "name": "Charmander",
        "pokedex_number": 4,
        "users_id": 1
    },
    {
        "id": 2,
        "type1": "water",
        "type2": null,
        "name": "Squirtle",
        "pokedex_number": 7,
        "users_id": 2
    }
]
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

Back to Table of Contents


POST TO BACKPACK

Inserts a pokemon to the backpack

Mehod Url: /api/backpack HTTP method: [POST]

Headers

name type required description
Content-Type String Yes Must be application/json

Body

name type required description
name String Yes
pokedex_number Integer Yes
type1 String Yes
type2 String No
users_id Interer Yes Foreign Key

example:

{
    "name": "Squirtle",
    "pokedex_number": 7,
    "type1": "water",
    "type2": null
    "users_id": 1,
}

Response

200 (OK)

If you successfully get all the pokemon in the backpack table, the endpoint will return an HTTP response with a status code 200 and a body as below.

{
    "id": 3,
    "type1": "water",
    "type2": null,
    "name": "Squirtle",
    "pokedex_number": 7,
    "users_id": 1
}
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

Back to Table of Contents


GET BACKPACK OF USER

Returns backpack of selected user by ID

Mehod Url: /api/backpack/:id HTTP method: [GET]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No Bearer JWT authorization token

Parameters

name type required description
id Int Yes Id of specific user

Response

200 (OK)

If you successfully get al the users, the endpoint will return an HTTP response with a status code 200 and a body as below.

[
    {
        "id": 1,
        "type1": "fire",
        "type2": null,
        "name": "Charmander",
        "pokedex_number": 4,
        "users_id": 1
    },
    {
        "id": 2,
        "type1": "water",
        "type2": null,
        "name": "Squirtle",
        "pokedex_number": 7,
        "users_id": 1
    },
    {
        "id": 3,
        "type1": "water",
        "type2": null,
        "name": "Squirtle",
        "pokedex_number": 7,
        "users_id": 1
    }
]
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

Back to Table of Contents


DELETE POKEMON IN BACKPACK

Returns backpack of selected user by ID

Mehod Url: /api/backpack/:id HTTP method: [DELETE]

Headers

name type required description
Content-Type String Yes Must be application/json
Authorization String No Bearer JWT authorization token

Parameters

name type required description
id Int Yes Id of specific user

Response

200 (OK)

If you successfully delete one pokemon in backpack, the endpoint will return an HTTP response with a status code 200 and a body as below.

1
401 (Unauthorized)

If you are not logged in, then endpoint will return an HTTP response with a status code 401 and a body as below.

{
  "error": true,
  "message": "You are unathorized to view the content."
}

Back to Table of Contents


About

Back End Engineer for LambdaSchool's BuildWeeks | Pokemon Pokedex App

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •