Skip to content

Latest commit

 

History

History
301 lines (227 loc) · 3.23 KB

DOCS.md

File metadata and controls

301 lines (227 loc) · 3.23 KB

API Documentation

ENDPOINTS

  • POST /api/v1/users

Creates a new user

body:

{
	"username": "string",
	"password": "string",
	"role": "string"
}

response:

{
	"message": "string",
	"user": {
		"id": "string",
		"username": "string",
		"role": "string",
		"deposit": "number"
	}
}
  • POST /api/v1/users/auth

authenticates user

body:

{
	"username": "string",
	"password": "string"
}

response:

{
	"id": "string",
	"username": "string",
	"role": "string",
	"deposit": "number"
}

// jwt token sent in cookie
  • GET /api/v1/users/current

gets current user

response:

{
	"id": "string",
	"username": "string",
	"role": "string",
	"deposit": "number"
}
  • POST /api/v1/users/logout

logs out user

response:

{
	"message": "string"
}
  • PUT /api/v1/users/{id}

updates user

body:

{
	// optional fields
	"username": "string",
	"password": "string",
	"role": "string"
}

response:

{
	"message": "string",
	"user": {
		"id": "string",
		"username": "string",
		"role": "string",
		"deposit": "number"
	}
}
  • DELETE /api/v1/users/{id}

deletes user

response:

{
	"message": "string"
}
  • PUT /api/v1/users/{id}/deposit

deposits money

body:

{
	"amount": "number" // should be a value in [5, 10, 20, 50, 100]
}

response:

{
	"message": "string",
	"deposit": "number"
}

PUT /api/v1/users/{id}/reset

resets user deposit

response:

{
	"message": "string",
	"deposit": "number"
}

GET /api/v1/products

gets all products

response:

[
	{
		"id": "string",
		"productName": "string",
	        "cost": "number",
	        "amountAvailable": "number",
	        "sellerId": "number"
	}
]

POST /api/v1/products

creates new product

body:

{
    "productName": "string",
    "cost": "number", // cost should be a multiple of 5
    "amountAvailable": "number",
}

response:

{
    "message": "string",
    "product": {
        "id": "string",
        "productName": "string",
        "cost": "number",
        "amountAvailable": "number",
        "sellerId": "number"
    }
}

GET /api/v1/products/:id

gets product

response:

    {
        "id": "string",
        "productName": "string",
        "cost": "number",
        "amountAvailable": "number",
        "sellerId": "number"
    }

PUT /api/v1/products/:id

updates product

body:

{
	// optional fields
    "productName": "string",
    "cost": "number",
    "amountAvailable": "number",
}

response:

{
	"message": "string",
	"product": {
		"id": "string",
		"productName": "string",
		"cost": "number",
		"amountAvailable": "number",
		"sellerId": "number"
	}
}

DELETE /api/v1/products/:id

deletes product

response:

{
	"message": "string"
}

POST /api/v1/products/:id/buy

buys product

body:

{
	"amount": "number"
}

response:

{
	"message": "string",
	"product": {
		"id": "string",
		"productName": "string",
		"cost": "number",
		"amountAvailable": "number",
		"sellerId": "number"
	},
	// return user change in coins
	"change": [
		"5": "number"
		"10": "number"
		"20": "number"
		"50": "number"
		"100": "number"
	]
}