Giter VIP home page Giter VIP logo

pokevault's Introduction

Pokevault API Documentation

Description

Pokevault is an API for managing a collection of Pokemon, allowing players to buy, sell, and view details about their Pokemon. This documentation provides details on the available endpoints and how to use them.


Getting Started

To get started with the Pokevault API, follow these steps:

  1. Clone the repository.
  2. Install dependencies using npm install.
  3. Set up the database by running migrations with npm run migrate.
  4. Start the server with npm start.
  5. Explore the API endpoints detailed below.

Endpoint List

Player Endpoint:
  • POST /players/register
  • POST /players/login
  • POST /players/profile
Pokemon Endpoint:
  • GET /pokemons
  • GET /pokemons/:id
My Pokemon Endpoint:
  • GET /mypokemons
  • POST /mypokemons/gacha
  • DELETE /mypokemons/:id
Order Endpoint:
  • POST /orders/topup
  • POST /orders/pay

Player Endpoint

Get /players/profile

Profile information of the authenticated player.

Headers: Authorization: Bearer token

{
  "accessToken":"example_token"
}

Success Response:

Response: (200 - OK)

{
    "id": 1,
    "username": "Example",
    "email": "[email protected]",
    "balance": 0,
    "createdAt": "2024-01-18T14:08:21.561Z",
    "updatedAt": "2024-01-19T05:33:04.735Z"
}

Error Response:

Response: (404 - Not Found)

{
  "message": "NotFoundError",
}
POST /players/register

Register new player for player authentication.

Body:

{
    "username": "Example",
    "email": "[email protected]",
    "password": "12345"
}

Success Response:

Response: (201 - Created)

{
    "message": "Register Successful",
    "username": "example",
    "email": "[email protected]"
}

Error Response:

Response: (400 - Bad Request)

{
  "message": "Username is required"
}
OR
{
  "message": "Email is required"
}
OR
{
  "message": "Invalid email format"
}
OR
{
  "message": "Password is required"
}

Response: (401 - Unauthorized)

{
  "message": "Email already registered"
}
POST /players/login

Player authentication.

Body:

{
    "email": "[email protected]",
    "password": "12345"
}

Success Response:

Response: (200 - OK)

{
  "accessToken":"example_token"
}

Error Response:

Response: (400 - Bad Request)

{
  "message": "Email is required"
}
OR
{
  "message": "Password is required"
}

Response: (401 - Unauthorized)

{
  "message": "Authentication failed"
}

Pokemon Endpoint

GET /pokemons

Get a list of all Pokemon.

Success Response:

Response: (200 - OK)

"pokemons":
    [
        {
            "id": 1,
            "name": "bulbasaur",
            "image": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png",
            "attack": 49,
            "defense": 49,
            "hp": 45,
            "speed": 45,
            "level": 1,
            "type": "grass, poison",
            "rarity": "Uncommon",
            "createdAt": "2024-01-18T04:26:01.787Z",
            "updatedAt": "2024-01-18T04:26:01.787Z"
        },
    ]
GET /pokemons/:id

Display Pokemon details based id.

Params:

{
    "id": integer
}

Success Response:

Response: (200 - OK)

{
    "id": 1,
    "name": "bulbasaur",
    "image": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png",
    "attack": 49,
    "defense": 49,
    "hp": 45,
    "speed": 45,
    "level": 1,
    "type": "grass, poison",
    "rarity": "Uncommon",
    "createdAt": "2024-01-18T04:26:01.787Z",
    "updatedAt": "2024-01-18T04:26:01.787Z"
}

Error Response:

Response: (404 - Not found)

{
  "message": "Not found"
}

MyPokemon Endpoint

GET /mypokemons

Get the Pokemon that the player has.

Headers: Authorization: Bearer token

{
  "accessToken":"example_token"
}

Success Response:

Response: (200 - OK)

  • If Don't have any Pokemon
[]
  • If Have any Pokemon
[
    {
        "PlayerId": 2,
        "PokemonId": 49,
        "Pokemon": {
            "name": "venomoth",
            "image": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/49.png",
            "attack": 65,
            "defense": 60,
            "hp": 70,
            "speed": 90,
            "level": 1,
            "type": "bug, poison",
            "rarity": "Rare"
        }
    },
    {
        "PlayerId": 2,
        "PokemonId": 52,
        "Pokemon": {
            "name": "meowth",
            "image": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/52.png",
            "attack": 45,
            "defense": 35,
            "hp": 40,
            "speed": 90,
            "level": 1,
            "type": "normal",
            "rarity": "Uncommon"
        }
    },
]
POST /mypokemons/gacha

Gacha to get Pokemon randomly.

Headers: Authorization: Bearer token

{
  "accessToken":"example_token"
}

Success Response:

Response: (201 - Created)

{
    "message": "Gacha successful.",
    "newBalance": 0,
    "acquiredPokemon": {
        "id": 648,
        "name": "meloetta-aria",
        "attack": 77,
        "defense": 77,
        "hp": 100,
        "speed": 90,
        "type": "normal, psychic",
        "rarity": "Legendary"
    }
}

Error Response:

Response: (400 - Bad Request)

{
  "message": "InsufficientBalanceError"
}

Response: (404 - Not found)

{
  "message": "Not found"
}
DELETE /mypokemons/:id

Delete owned pokemon based on id.

Headers: Authorization: Bearer token

{
  "accessToken":"example_token"
}

Params:

{
  "id": integer
}

Success Response:

Response: (201 - Created)

{
    "message": "Deleted"
}

Error Response:

Response: (404 - Not found)

{
  "message": "Not found"
}

Order Endpoint

POST /orders/topup

Do an initial Midtrans to make an order for how much balance want to add to the player.

Headers: Authorization: Bearer token

{
  "accessToken":"example_token"
}

body:

{
  "amount": integer
}

Success Response:

Response: (200 - OK)

{
    "token": "example_token_order",
    "redirect_url": "example_midtrans_url"
}

Error Response:

Response: (400 - Bad Request)

{
  "message": "Amount is required"
}
POST /orders/pay

Make status and balance changes after Midtrans payments based on token.

Headers: Authorization: Bearer token

{
  "accessToken":"example_token"
}

body:

{
  "token": "example_token_order",
  "transaction_status": "capture",
  "fraud_status": "accept"
}

Success Response:

Response: (201 - Created)

{
    "message": "Payment status updated"
}

Global Error

Response: (500 - Internal Server Error)

{
  "message": "Internal Server Error"
}

Dependencies

The project uses the following dependencies:

  • Express
  • Sequelize
  • Bcrypt
  • Jsonwebtoken
  • Jest & Supertest (for testing)
  • Axios (for Poke API integration)

Install them using npm install.


External APIs

Poke API

The Poke API is used to fetch details about Pokemon, including names, images, stats, and more. Visit the Poke API documentation for more information.

Midtrans

Midtrans is integrated to handle payment transactions for player balance top-up. Visit the Midtrans documentation for more information on integrating Midtrans into your application.

pokevault's People

Contributors

ibnufajarw avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.