Create an application that connects buyers and sellers for transactions in a silent auction format.
To contribute or utilize this project, clone and download the git repository. Run npm install to download the necessary dependencies. Type npm run server in the command line to start the server on localhost:4200. Familiarize yourself with the file-structure and enjoy!
https://bw-silent-auction.herokuapp.com/
POST /api/buyers/login
POST /api/sellers/login
Example request body:
{
"username": "alex",
"password": "password"
}
No authentication required. Returns an Object with user and token key:value pairs. Example response body:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
"user": {
"id": 9,
"username": "alex",
"email": "[email protected]",
"first_name": "Alex",
"last_name": "Gordon"
}
}
Required fields: username, password
POST /api/buyers/register
POST /api/sellers/register
Example request body:
{
"username": "alex",
"password": "password",
"email": "[email protected]",
"first_name": "Alex",
"last_name": "Gordon"
}
No authentication required, returns a User object
Required fields: username, password, email, first_name, last_name
GET /api/products
Requires authentication. Request header should be structured as follows:
jwt = JSON web token issued at login
{
"authorization": "jwt"
}
Returns an array of all products from database. Example response body:
[
{
"id": 1,
"seller_id": 3,
"title": "Playstation 4",
"desccription": "The fourth installment of the best console to date",
"starting_price": 189.95,
"image": null,
"duration": 7,
"active": true,
"created_at": "2019-09-22 11:42:12"
},
{
"id": 2,
"seller_id": 5,
"title": "iPhone 11",
"description": "The greatest iPhone yet",
"starting_price": 1150.95,
"image": null,
"duration": 5,
"active": true,
"created_at": "2019-09-23 22:37:57"
},
]
POST /api/products
Requires authentication.
req.header.authorization = token;
Example request body:
{
"seller_id": 5,
"title": "iPhone 11",
"description": "The greatest iPhone yet",
"image": file,
"starting_price": 1150.95,
"duration": 5
}
Required fields: seller_id, title, description, starting_price
Returns the new Product object. Example response body:
{
"id": 2,
"seller_id": 5,
"title": "iPhone 11",
"description": "The greatest iPhone yet",
"starting_price": 1150.95,
"image": url,
"duration": 5,
"active": true,
"created_at": "2019-09-23 22:37:57"
}
GET /api/products/:id
Requires authentication.
req.header.authorization = token;
Returns the Product object with all bids for that product. Example response body:
{
"id": 2,
"seller_id": 5,
"title": "iPhone 11",
"description": "The greatest iPhone yet",
"starting_price": 1150.95,
"image": null,
"duration": 5,
"active": true,
"created_at": "2019-09-23 22:37:57",
"bids": [
{
"id": 2,
"product_id": 2,
"buyer_id": 2,
"bid_amount": 1165.95,
"details": {
"id": 2,
"username": "camalv",
"email": "[email protected]",
"first_name": "Cameron",
"last_name": "Alvarado"
},
},
{
"id": 3,
"product_id": 2,
"buyer_id": 3,
"bid_amount": 1170.95,
"details": {
"id": 3,
"username": "dmaack123",
"email": "[email protected]",
"first_name": "Dominique",
"last_name": "Maack"
},
},
{
"id": 12,
"product_id": 2,
"buyer_id": 4,
"bid_amount": 1180.95,
"details": {
"id": 4,
"username": "chaonyc",
"email": "[email protected]",
"first_name": "Chao",
"last_name": "Ji"
},
},
];
}
GET /api/products/:id/bids
Requires authentication.
req.header.authorization = token;
Returns an Array of all bids placed on a specific product. Example response body:
[
{
"id": 2,
"product_id": 2,
"buyer_id": 2,
"bid_amount": 1165.95
},
{
"id": 3,
"product_id": 2,
"buyer_id": 3,
"bid_amount": 1170.95
},
{
"id": 12,
"product_id": 2,
"buyer_id": 4,
"bid_amount": 1180.95
}
]
POST /api/products/:id/bids
Requires authentication.
req.header.authorization = token;
Example request body:
{
"buyer_id": 6,
"bid_amount": 1190.95
}
Required fields: buyer_id, bid_amount
GET /api/sellers/:id/auctions
Requires authentication.
req.header.authorization = token;
Returns an Array of all products previously posted by a specific seller. Example response body:
[
{
"id": 2,
"seller_id": 5,
"title": "iPhone 11",
"description": "The greatest iPhone yet",
"starting_price": 1150.95,
"image": null,
"duration": 7,
"active": true,
"created_at": "2019-09-23 22:37:57"
},
]
DEL /api/products/:id
Requires authorization
PUT /api/products/:id
Requires authorization
Requires at least one field to update.
Cannot edit created_at, id, seller_id.
DEL /api/buyers/:id
Requires authorization.
200 OK- The request has succeeded
201 Created- The request succeeded and the new resource has been created
400 Bad Request- The server could not understand the request due to invalid syntax
- The most likely cause is an improper request body
401 Unauthorized- No authentication header was provided with the request
404 Not found- The server could not find the requested resource
500 Internal server error- The server has encountered a situation it doesn't know how to handle