Skip to content

Latest commit

 

History

History
1127 lines (1019 loc) · 18.6 KB

endpoints.md

File metadata and controls

1127 lines (1019 loc) · 18.6 KB

Endpoints

  • /api
    • /auth
      • /sign_up
        • POST /
      • /sign_in
        • POST /
    • /v1
      • /user
        • GET /
      • /attendee
        • GET /
      • /badges
        • GET /
        • GET /:id
      • /attendees
        • GET /
        • GET /:id
        • POST /:id
        • DELETE /:id
      • /company
        • GET /
      • /companies
        • GET /
        • GET /:id
      • /referrals
        • GET /:id
      • /redeems
        • POST /
      • /leaderboard
        • GET /
        • GET /:date
      • /association
        • GET /:discord_id
        • POST /
      • /store
        • GET /
        • GET /:id
        • POST /buy
      • /roulette
        • POST
      • /roulette/prizes
        • GET /
        • GET /:id
      • /roulette/latestwins
        • GET /
      • /give_bonus
        • POST /:id
      • /spotlight
        • POST

Attendee

  • /api
    • /auth
      • /sign_up
      • POST /
      • /sign_in
      • POST /
    • /v1
      • /user
        • GET /
      • /attendee
        • GET /
      • /badges
        • GET /
        • GET /:id
      • /attendees
        • GET /
        • GET /:id
        • POST /:id
        • DELETE /:id
      • /companies
        • GET /
        • GET /:id
      • /referrals
        • GET /:id
      • /store
        • GET /
        • GET /:id
        • POST /buy
      • /leaderboard
        • GET /
        • GET /:date
      • /roulette
        • POST
      • /roulette/prizes
        • GET /
        • GET /:id

Company

  • /api
    • /auth
      • /sign_in
      • POST /
    • /v1
      • /user
        • GET /
      • /badges
        • GET /
        • GET /:id
      • /attendees
        • GET /
        • GET /:id
        • POST /:id
        • DELETE /:id
      • /company
        • GET /
        • /attendees
          • GET /:id
      • /companies
        • GET /
        • GET /:id
      • /redeems
        • POST /
      • /give_bonus
        • POST /:id
      • /spotlight
        • POST

Manager

  • /api
    • /auth
      • /user
        • GET /
      • /sign_up
        • POST /
      • /sign_in
        • POST /
    • /v1
      • /redeems
        • POST /
      • /association
        • GET /:discord_id
        • POST /
      • /store
        • POST /redeem

sign_up

POST /

{
    "user": {
        "email": "foo@bar.com",
        "password": "somePassword",
        "password_confirmation": "somePassword",
        "attendee": {
            "id": "adaa8aab4e-7549-494b-91f0-52e9c9a8cf5d",
            "nickname": "foobar",
	    "name": "Foo Bar"
        }
    }
}

Valid:

{
    "discord_association_code": "733405df-0b7b-4dc3-9666-3038fde44698",
    "jwt": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJzYWZpcmEiLCJl..."

}

Errors:

  • Invalid email, email already taken, password doesn't match, username already taken
{
    "error": "Invalid register data"
}
  • UUID taken
{
    "error": "Already registered"
}
  • UUID Incorrect
{
    "errors": {
        "detail": "Bad Request"
    }
}

sign_in

POST /

{
    "email": "foo@bar.com",
    "password": "somePassword"
}

Valid:

{
    "jwt": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJzYWZpcmEiLCJle..."
}

Errors:

  • Invalid username or password
{
    "error": "Login error"
}

Authenticated Endpoints

When you are autheticated you get a jwt token.

This token is used as a bearer token to service any calls to the api that need to be authenticated.

Errors:

{
    "error": "unauthenticated"
}
{
    "error": "invalid_token"
}

badges

GET / (Index)

Fetches all badges depending in the type of user that is consulting them.

Valid:

{
    "data": [
        {
            "name": "Dia 1",
            "id": 1,
            "end": "2018-07-31T15:59:51.746577Z",
            "description": "coisa",
            "begin": "2018-07-31T15:59:51.742630Z",
            "avatar": "/images/default/badge-missing.png",
            "tokens": 1,
            "type": 3
        }
    ]
}

GET /:id (Show)

Fetches a single badge.

Valid:

{
    "data": {
        "attendees": [ ... ],
        "name": "Dia 1",
        "id": 1,
        "end": "2018-07-31T15:59:51.746577Z",
        "description": "coisa",
        "begin": "2018-07-31T15:59:51.742630Z",
        "avatar": "/images/default/badge-missing.png",
        "tokens": 1,
        "type": 3
    }
}

Errors:

{
    "errors": {
        "detail": "Endpoint Not Found"
    }
}

attendee

GET / (Show)

Fetches the nick, uuid, email and avatar of the logged in attendee.

Valid:

{
    "nick": "qwrqasd",
    "id": "43ffc4f5-3b12-4243-a157-e4e9e90d35dc",
    "email": "fooo@bar.com",
    "name": "Name LastName",
    "avatar": "/images/default/attendee-missing.png"
}

attendees

GET / (Index)

Lists all attendees.

Valid:

{
    "data": [
        {
            "avatar": "/images/attendee-missing.png",
            "badge_count": 1,
            "badges": [
                {
                    "avatar": "https://teste.amazonaws.com/uploads/badge/avatars/179/original.png?v=63731919919",
                    "begin": "2019-02-05T00:00:00Z",
                    "description": "Estiveste presente na talk do Celso Martinho",
                    "end": "2019-02-06T00:00:00Z",
                    "id": 179,
                    "name": "Talk Celso Martinho",
                    "tokens": 1,
                    "type": 3
                }
            ],
            "entries": 0,
            "id": "eae3333d-51a6-4142-b35d-0154e431ff60",
            "name": "user1",
            "nickname": "user1",
            "token_balance": 10,
            "volunteer": false
        },
        {
            "avatar": "/images/attendee-missing.png",
            "badge_count": 0,
            "badges": [],
            "entries": 0,
            "id": "87656cdb-5615-4118-b981-a76f5ee4352a",
            "name": "user3",
            "nickname": "user3",
            "token_balance": 10,
            "volunteer": false
        }
    ]
}

GET /:id (Show)

Shows an attendee.

Valid:

{
    "data": {
        "avatar": "/images/attendee-missing.png",
        "badge_count": 1,
        "badges": [{
                    "avatar": "https://teste.amazonaws.com/uploads/badge/avatars/179/original.png?v=63731919919",
                    "begin": "2019-02-05T00:00:00Z",
                    "description": "Estiveste presente na talk do Celso Martinho",
                    "end": "2019-02-06T00:00:00Z",
                    "id": 179,
                    "name": "Talk Celso Martinho",
                    "type": 3
                }],
        "entries": 0,
        "id": "eae3333d-51a6-4142-b35d-0154e431ff60",
        "name": "user1",
        "nickname": "user1",
        "prizes": [{
                    "avatar": "/uploads/prize/avatars/26/original.png?v=63780572129",
                    "id": 26,
                    "name": "Raspberry Pi 4 2gb + carregador"
        }],
        "redeemables": [
            {
                "id": 1,
                "image": "/images/redeemable-missing.png",
                "name": "T-shirt",
                "price": 10,
                "quantity": 1
            }
        ],
        "token_balance": 10,
        "volunteer": false
    }
}

Errors:

{
    "errors": {
        "detail": "Bad Request"
    }
}

PUT /:id (Update)

Changes an attendee.

Request:

{
    "attendee": {
        "nickname": "qwrqasd"
    }

}

Valid:

{
    "data": {
        "nickname": "qwrqasd",
        "id": "d832f350-fe30-4d98-a245-59d1aa186f36",
        "name": "Name LastName",
        "avatar": "/images/default/attendee-missing.png"
    }
}

Errors:

{
    "errors": {
        "detail": "Bad Request"
    }
}

DELETE /:id (Delete)

Removes an attendee.

Valid:

204 (no content)

Errors:

  • Invalid uuid
{
    "errors": {
        "detail": "Endpoint Not Found"
    }
}

referrals

POST /

{
	"id": "ee2c4d55-7765-47c6-85af-b087fa03dc9b"
}

Valid:

{
    "referral": "Referral redeemed successfully"
}

Errors:

  • Used referrals
{
    "referral": "Referral not available"
}
  • Attende allready had this badge
{
    "errors": {
        "unique_attendee_badge": [
            "An attendee can't have the same badge twice"
        ]
    }
}

company

GET /

{
    "data": {
        "badge_id": 37,
        "channel_id": "1",
        "id": 1,
        "name": "Accenture",
        "sponsorship": "Exclusive"
    }
}

companies

GET /

{
    "data": [
        {
            "badge_id": 37,
            "channel_id": "1",
            "id": 1,
            "name": "Accenture",
            "sponsorship": "Exclusive"
        }
    ]
}

GET /:id

Valid:

{
    "data": {
        "sponsorship": "ola",
        "name": "ola",
        "id": 1
    }
}

GET /attendees/:id

Valid:

{
    "data": {
        "id": 1,
        "nickname": "AttendeeMega2",
        "name": "Attendee Mega 2",
        "avatar": "/images/default/attendee-missing.png",
        "token_balance": 10,
        "entries": 0,
    }
}

Errors:

{
    "errors": {
        "detail": "Endpoint Not Found"
    }
}

redeems

POST /

{
    "redeem": {
        "attendee_id": "43ffc4f5-3b12-4243-a157-e4e9e90d35dc",
        "badge_id": "1"
    }
}

Valid:

{
    "redeem": "Badge redeemed successfully. Tokens added to your balance"
}

Errors:

  • User allready had the badge
{
    "errors": {
        "unique_attendee_badge": [
            "An attendee can't have the same badge twice"
        ]
    }
}
  • Not a manager, no badge_id, not valid badge_id
{
    "errors": {
        "detail": "Endpoint Not Found"
    }
}

leaderboard

GET /

{
    "data": [
        {
            "avatar": "/images/attendee-missing.png",
            "badges": 28,
            "id": "79a29c1c-9f2e-4de1-a318-54eb1e6ec060",
            "name": "user1",
            "nickname": "user1",
            "token_balance": 80,
            "volunteer": false
        },
        {
            "avatar": "/images/attendee-missing.png",
            "badges": 11,
            "id": "05942830-fe17-4133-aadf-23c44d5dc24b",
            "name": "user2",
            "nickname": "user2",
            "token_balance": 91,
            "volunteer": false
        }
    ]
}

GET /:date (The format is: {yyyy-mm-dd} , ex: /leaderboard/2021-02-17)

Get the daily leaderboard

{
    "data": [
        {
            "avatar": "/images/attendee-missing.png",
            "badges": 2,
            "id": "1f18064f-9fe8-437a-9141-9c75ee85d25b",
            "name": "user3",
            "nickname": "user3",
            "token_balance": 2,
            "volunteer": false
        },
        {
            "avatar": "/images/attendee-missing.png",
            "badges": 1,
            "id": "79a29c1c-9f2e-4de1-a318-54eb1e6ec060",
            "name": "user1",
            "nickname": "user1",
            "token_balance": 71,
            "volunteer": false
        }
    ]
  }
}

spotlight

POST

No body

Valid

{
  "spotlight": "Spotlight requested succesfully"
}

Errors:

  • A company is already in spotlight
{
  "errors": {
    "active": [
      "Another spotlight is still active"
    ]
  }
}
  • The company has no remaining spotlights
{
  "errors": {
    "remaining_spotlights": [
      "must be greater than or equal to 0"
    ]
  }
}

Association

/:discord_id (Show)

Fetches the id of the attendee associated with the given discord id

Valid:

{
  "id": "f90b60ce-219c-4edc-a92a-e6c63fec4a4d"
}

Errors:

  • Discord id is not associated:
{
  "error": "No attendee with that discord_id"
}

POST /

{
	"discord_association_code": "733405df-0b7b-4dc3-9666-3038fde44698",
	"discord_id": "abc"
}

Valid:

{
  "association": "participante"/"empresa"/"orador"/"staff"
}

Errors:

  • Invalid association code:
{
  "error": "Unable to associate"
}

Store

GET / (Index)

Fetches all redeemables in store.

  • When is an attendee

Valid:

{
    "data": [
        {
            "can_buy": 1,
            "description": "PowerBank 5k com logo SEI",
            "id": 1,
            "image": "/uploads/redeemable/avatars/1/original.png?v=63780993725",
            "max_per_user": 1,
            "name": "PowerBank",
            "price": 100,
            "stock": 30
        },
        {
            "can_buy": 3,
            "description": "Merch SEI",
            "id": 2,
            "image": "/uploads/redeemable/avatars/2/original.png?v=63780993725",
            "max_per_user": 4,
            "name": "T-shirt",
            "price": 50,
            "stock": 10
        }
    ]
}
  • When is not an attendee

Valid:

{
    "data": [
        {
            "can_buy": 0,
            "description": "PowerBank 5k com logo SEI",
            "id": 1,
            "image": "/uploads/redeemable/avatars/1/original.png?v=63780993725",
            "max_per_user": 1,
            "name": "PowerBank",
            "price": 100,
            "stock": 30
        },
        {
            "can_buy": 0,
            "description": "Merch SEI",
            "id": 2,
            "image": "/uploads/redeemable/avatars/2/original.png?v=63780993725",
            "max_per_user": 4,
            "name": "T-shirt",
            "price": 50,
            "stock": 10
        }
    ]
}

GET /:id (Show)

Fetches a single item.

  • When is an attendee

Valid:

{
    "data": {
        "can_buy": 7,
        "description": "Merch SEI",
        "id": 2,
        "image": "/images/redeemable-missing.png",
        "max_per_user": 10,
        "name": "Caneta",
        "price": 5,
        "stock": 7
    }
}
  • When is not an attendee

Valid:

{
    "data": {
        "can_buy": 0,
        "description": "Merch SEI",
        "id": 2,
        "image": "/images/redeemable-missing.png",
        "max_per_user": 10,
        "name": "Caneta",
        "price": 5,
        "stock": 7
    }
}

Errors:

  • When an item does not exist in store.
{
    "errors": {
        "detail": "Endpoint Not Found"
    }
}

POST /buy

Buy a redeemable.

{
    "redeemable": {
        "redeemable_id": 3
    }
}

Valid:

{
    "Redeemable": "Caneta bought successfully!"
}

Errors:

  • When the participant has already reached the maximum quantity allowed per user.
{
    "errors": {
        "quantity": [
            "Quantity is greater than the maximum amount permitted per attendee"
        ]
    }
}
  • Attendee token balance is insufficient to buy the redeemable.
{
    "errors": {
        "token_balance": [
            "Token balance is insufficient."
        ]
    }
}
  • The stock of the selected redeemable reached 0.
{
    "errors": {
        "stock": [
            "Item is sold out!"
        ]
    }
}
  • There is no redeemable_id parameter or it is written differently.
{
    "Redeemable": "No 'redeemable_id' param"
}
  • Not an attendee
{
    "error": "Only attendees can buy products!"
}
  • There is no redeemable with that id
{
    "Redeemable": "There is no such redeemable"
}

POST /redeem

deliver a redeemable to the atendee.

{
    "redeem": {
        "user_id": 2,
        "redeemable_id": 3,
        "quantity": 1
    }
}

Valid:

{
    "Redeemable": "Caneta bought successfully!"
}

Errors:

  • User doesn not exist
{
    "errors": {
        "User": [
            "User does not exist"
        ]
    }
}
  • redeemable does not exist
{
    "errors": {
        "Redeemable": [
            "There is no such redeemable"
        ]
    }
}
  • json is lacking the quantity parameter
{
    "errors": {
        "stock": [
            "Json does not have `quantity` param"
        ]
    }
}

Roulette

POST /

Valid

  • When you win tokens
{
    "prize": {
        "avatar": "/uploads/prize/avatars/45/original.png?v=63781002813",
        "id": 45,
        "name": "Tokens"
    },
    "tokens": 10
}
  • When you win a normal prize
{
    "prize": {
        "avatar": "/uploads/prize/avatars/57/original.png?v=63781049535",
        "id": 57,
        "name": "Raspberry Pi 4 2gb + carregador"
    }
}
  • When you win entries for the final draw
{
    "entries": 1,
    "prize": {
        "avatar": "/uploads/prize/avatars/66/original.png?v=63781049535",
        "id": 66,
        "name": "Entradas para o sorteio final"
    }
}
  • When you win a roulette badge
{
    "badge": {
        "avatar": "/uploads/badge/avatars/129/original.png?v=63780362701",
        "begin": "2020-02-26T00:00:00Z",
        "description": "Lucky Bastard 1",
        "end": "2020-02-27T00:00:00Z",
        "id": 129,
        "name": "Lucky Bastard 1",
        "tokens": 1,
        "type": 9
    },
    "prize": {
        "avatar": "/uploads/prize/avatars/61/original.png?v=63781049535",
        "id": 61,
        "name": "Lucky Bastard 1"
    }
}
  • When you win nothing
{
    "prize": {
        "avatar": "/uploads/prize/avatars/67/original.png?v=63781049535",
        "id": 67,
        "name": "Nada"
    }
}

Roulette - Prizes

Prizes that an attendee can win by spinning the roulette.

GET /

{
  "data": [
    {
      "avatar": "/uploads/prize/avatars/25/original.png?v=63780572128",
      "id": 25,
      "max_amount_per_attendee": 1,
      "name": "Amazon Voucher",
      "stock": 8
    }
  ]
}

GET /:prize_id

Get a specific prize by prize_id

Valid

{
  "data": {
    "avatar": "/uploads/prize/avatars/26/original.png?v=63780572129",
    "id": 26,
    "max_amount_per_attendee": 1,
    "name": "Raspberry Pi 4 2gb + carregador",
    "stock": 1
  }
}

Errors

  • When the prize_id does not exist.
{
  "errors": {
    "detail": "Endpoint Not Found"
  }
}

Roulette - Latest 5 Wins

GET /

{
  "data": [
    {
      "attendee_name": "user1",
      "date": "2021-02-21T21:36:13",
      "prize": {
        "avatar": "/uploads/prize/avatars/12/original.png?v=63781160330",
        "id": 12,
        "max_amount_per_attendee": 1,
        "name": "ATH-M50X Profissional Audio-technica",
        "stock": 0
      }
    }
  ]
}

Give Bonus

Company gives a pre-defined bonus to an attendee

POST /:attendee_id

Valid

{
  "attendee_id": "05942830-fe17-4133-aadf-23c44d5dc24b",
  "bonus_count": 2,
  "company_id": 1,
  "name": "user2",
  "token_bonus": 10
}

Errors

  • When a company tries to give more than 3 bonuses to the same attendee.
{
  "errors": {
    "count": [
      "must be less than or equal to 3"
    ]
  }
}
  • When the attendee_id is not valid
{
  "errors": {
    "detail": "Bad Request"
  }
}