Leaderboard

Tabla de Clasificación

POSITION

NAME

SCORE

DATE

1

MANUELA RECIO GOMEZ

900

29-08-2016

2

JUAN CAMILO RIOS QUINTERO

700

26-08-2016

3

JUAN DAVID NICHOLLS C.

700

26-08-2016

4

HÉCTOR ALZATE

600

28-08-2016

5

MANUELA RECIO GOMEZ

500

24-08-2016

6

MANUELA RECIO GOMEZ

450

22-08-2016

Stores players scores and sorts them in a leaderboard

Level 1

Retrieves a player's data with the last score [GET]

Url: /users/{id}

Response: 200 (application/json)
  {

    "username": "juan.riosq",

    "name": "Juan Camilo Rios Quintero",
    "score": 700,

    "updated_at": "2017-08-26T13:18:05"
  }

Stores player's new score [POST]

Url: /users/{id}

Request: (application/json)
  {

    "score": 900,
    "level": 1

  }

Retrieves a player's leaderboard position [GET]

Url: /leaderboard/{levelId}/{userId}

Response: 200 (application/json)
  {

    "position": 1,

    "score": 900,

    "updated_at": "2017-08-29T13:18:05"
  }

Retrives paged leaderboard starting from the first player [GET]

Url: /leaderboard/{levelId}{?pageSize,page}

Response: 200 (application/json)
  { [
            {
                "position": 1,
                "name": "Manuela",
                "username": "rawrcrush",
                "score": 500
            },
            {
                "position": 2,
                "id": "HFG0555",
                "name": "rawrcrush",
                "score": 500
            },
  }

API REST

Esquema de Base de datos

Obtener la posición

row_number() OVER(ORDER BY score DESC, date ASC) as position

Paginar los resultados

var page = Number(req.query.page) || 1;
var limit = Number(req.query.pageSize) || 10;
var offset = (page - 1) * limit;

db.query(`
  SELECT
    *
  ...
  LIMIT $1 
  OFFSET $2
`, [limit, offset])

Rest Client?

Leaderboard

By J.D Nicholls

Leaderboard

  • 1,695