Skip to content

Repository files navigation

Market

Description

This simple application have three basic entities:

  • Customers
  • Executors
  • Tasks

Customer can place a task into Market and set a price. Executor can execute a task for a given price. Market gets it's fee. Entities are stored in different databases.

API

All responses are json objects or empty objects.

Route Method Parameters Reply Errors Description
/customers GET offset=<int>, length=<int> List of customers
  • 200(OK)
Returns list of customers with paging
/customers POST balance=<int> Customer object
  • 201(Created)
Returns new customer object with one's id
/customers/{id} GET   Customer object
  • 200(OK)
  • 404(Not Found)
Returns existing customer by one's id
/customers/{id} PUT balance=<int> Customer object
  • 200(OK)
  • 404(Not Found)
Updates customer balance
/customers/{id} DELETE    
  • 200(OK)
  • 404(Not Found)
Delete customer with all one's tasks
/customers/{id}/tasks POST value=<int> Task object
  • 200(OK)
  • 404(Not Found)
Creates new task with a given value
/executors GET offset=<int>, length=<int> List of executors
  • 200(OK)
Returns list of executors with paging
/executors POST balance=<int> Executor object
  • 201(Created)
Returns new executor object with one's id
/executors/{id} GET   Executor object
  • 200(OK)
  • 404(Not Found)
Returns existing executor by one's id
/executors/{id} DELETE    
  • 200(OK)
  • 404(Not Found)
Delete executor
/executors/{id}/tasks/{id} POST    
  • 200(OK)
  • 404(Not Found)
  • 409(Conflict)

Customer balance is too low.

Transfers money from to executor. Executor pays fee. Task is deleted.
/tasks GET length=<int>, offset=<int> List of tasks
  • 200(OK)
Returns list of tasks with paging

Objects

Customer:

{
  "id": <int>,
  "balance: <int>
}

Executor:

{
  "id": <int>,
  "balance: <int>
}

Task:

{
  "id": <int>,
  "value": <int>,
  "customer": <int>
}

Run

> php -S localhost:8000 router.php

Examples

Create new customer

$ curl -X POST 'localhost:8000/customers?balance=1000'
{"id":1,"balance":1000}

List customers

$ curl 'localhost:8000/customers'
{"users":[{"id":"1","balance":"1000"}]}

Update customer balance

$ curl -X PUT 'localhost:8000/customers/1?balance=5000'
{"id":"1","balance":5000}

Create new executor

$ curl -X POST 'localhost:8000/executors'
{"id":1,"balance":0}

Create new task

$ curl -X POST 'localhost:8000/customers/1/tasks?value=10'
{"id":1,"value":10,"customerId":"1"}

Execute task

$ curl -X POST 'localhost:8000/executors/1/tasks/1'
$ curl 'localhost:8000/customers'
{"users":[{"id":"1","balance":"4990"}]}
$ curl 'localhost:8000/executors/1'
{"id":"1","balance":5}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages