This is a small system that allows to place and fullfill orders for customers and contractors. A customer places a bid on a specific product with the correspoding sum. The system publishes the bid to the registered contractors. Interested contractors see it. The quickest one takes the bid. The system marks the bid as completed, charges a roaylty from the sum, and transfers funds from the customer to the contractor.
The system consists from 4 MySQL databases, a PHP backend that provides a REST API, and a JS client.
The database are named customers, contractors, bids and fulfillments. Each database has a table with the same name as the database. See the migrations/sql directory for it's database schemas.
The server provides the following REST API
- GET /api/customers/profile
Gets the the profile of a registered customer. Requires the cst_session_id
cookie being set. Responses with:
{
"id":"5",
"amount":"500.00"
}
- POST /api/customers/register
Registers a new customer and sets the cst_session_id
cookie. Returns the 201 code in case of success.
- GET /api/contractors/profile
Gets the the profile of a registered contractor. Requires the cnt_session_id
cookie being set. Responses with:
{
"id":"5",
"amount":"500.00"
}
- POST /api/contractors/register
Registers a new contractor and sets the cnt_session_id
cookie. Returns the 201 code in case of success.
- GET /api/bids
Returns a list of current available bids for a registered contractor.
uires the cnt_session_id
cookie being set. Responses with:
[{
"id": "3",
"product": "Pancakes",
"amount": "8",
"price": "178.34",
"customer_id": "6",
"place_time": "2015-12-27 18:52:36"
}, {
"id": "2",
"product": "Oranges",
"amount": "76",
"price": "178.66",
"customer_id": "3",
"place_time": "2015-12-26 22:08:31"
}]
- GET /api/bid/{id}
Returns a bid by the specified id for a registered contractor.
Requires the cnt_session_id
cookie being set. Responses with:
{
"id": "2",
"product": "Oranges",
"amount": "76",
"price": "178.66",
"customer_id": "3",
"place_time": "2015-12-26 22:08:31"
}
- POST /api/bid{id}/take
Takes a bid with the specified id by a registered contractor.
Requires the cnt_session_id
cookie being set. Returns the 404 error
code if the bid has already been taken. Return the 409 error code if
the bid's customer doesn't have enough funds.
- POST /api/bid/{id}/place
Places a new bid by a registered customer. Requires the cst_session_id
cookie being set. If the customer doesn't have enough funds then
responses with the 409 error code. Request format is:
{
"product" : "Coffee",
"amount" : 10,
"price" : 50.5
}
- POST /api/logout
Logs out the current contractor, customer or both.
UI provides 2 modes (for a customer and for a contractor). The main page offers to register as either. After registering a session is registered for the user and it redirected to the corresponding page. The session lives while the user doesn't log out or doesn't register again.
See provision/provision.sh
- Clone the repo
git clone git@github.com:arteam/orders-system.git
- Change to root
su
- Create databases and migrate schemas
export OS_USER='some user'
export OS_PASSWORD='some pass'
cd migrations/
./create_db
./migrate
- Create app config
mkdir /etc/orders-system/
vim /etc/orders-system/conf.ini
[bids]
dbname=bids
user=
pass=
[customers]
dbname=customers
user=
pass=
[contractors]
dbname=contractors
user=
pass=
[fulfillments]
dbname=fulfillments
user=
pass=
originHost=localhost
royalty=0.15
logFile=/var/log/orders-system.log
chown 600 /etc/orders-system/conf.ini
- Exit from root
exit
- Install app dependencies
cd ../
composer install
bower install
- Setup the web server
Buil-in PHP Web server
cd public/
php -S localhost:8000
or via NGINX
vim /etc/nginx/sites-available/default
server {
listen 80 default_server;
index index.html index.htm index.php;
root /home/user/apps/orders-system/public;
server_name 127.0.0.1;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}