This application is a full-stack automobile trading site.
The application is spread between two repositories. This repo contains the back-end. The front-end can be found here.
The back-end is hosted on Heroku. The front-end is hosted on GitHub Pages.
I wanted to create a full-stack trading application with a database of items for sale. I wanted to include images of merchandise but this raised the issue of ensuring images were appropriately formatted to display well in resusable components.
I decided to create a listings site for automobiles, using pictures of toy cars in place of real cars. I discovered several collectors' sites that included images of Hotwheels cars in a standardised format, allowing me to generate a large pool of assets that could be rendered in procedurally generated components with minimal formatting issues.
I aimed to include the following features in the back-end:
- A MySQL database of listings data
- An API created using Express and Sequelize
- Full CRUD capabilities
- A test suite for the CRUD methods
The features of the front-end are detailed here.
To install this repo locally:
- Clone this repo.
- Set up a Docker container running MySQL. Set the password to
password. - Create a .env file in the root directory.
- Add the following environment variables to the .env file:
DB_NAME=tiny_car_list DB_USER=root DB_PASSWORD=password DB_HOST=localhost DB_PORT=3307 ADMIN_CODE=password - Create a .env.test file in the root directory.
- Add the following environment variables to the .env.test file:
DB_NAME=tiny_car_list_test DB_USER=root DB_PASSWORD=password DB_HOST=localhost DB_PORT=3307 ADMIN_CODE=password - To run the tests, run
npm test. In the unaltered repo they should pass. - If all tests pass then the API can be run. Run
npm start. - Launch Postman to interact with the API.
The live API is password-protected and will only accept Get requests without the password.
However various requests can be sent to the locally hosted API using the password password as specified in the Installation section above.
In Postman add a key of 'Authorizer' with value 'password' to the Headers. This password will then be included with your requests.
EFFECT: Creates a new listing with the provided JSON data.
METHOD: POST to localhost:4000/listing
BODY:
{
"imgref": "car000_#",
"make": "coffeeshop",
"model": "matcha",
"year": "2010",
"price": "1000",
"city": "liverpool",
"email": "[email protected]"
}
EFFECT: Fetches all listings in the database.
METHOD: GET to localhost:4000/listing
EFFECT: Fetch all listings that match a specified query
METHOD: GET to localhost:4000/listing?key=value
EXAMPLE: GET localhost:4000/listing?year=2010
EFFECT: Identifies a listing using its listingId and modifies values specified in the body. Remaining values are unchanged.
METHOD: PATCH to localhost:4000/listing/id
EXAMPLE: PATCH localhost:4000/listing/2
BODY:
{
"make": "patisserie",
"model": "latte",
"year": "2017",
"city": "paris",
}
EFFECT: Deletes a listing using its listingId.
METHOD: DELETE to localhost:4000/listing/id
EXAMPLE: DELETE localhost:4000/listing/2
The API was created using Express and Sequelize.
Dotenv was used to manage environment variables.
I used the Mocha test framework, Chai assertion library and Supertest asynchronous request library to create the test suite.
- Create a process for uploading images with new submissions to the database. Images are hosted separately from the rest of the database so a new approach will be required for this.
This application uses Open Source components. You can find their source code and license information below. Huge thanks to all of the people who contribute to this work ❤️
-
Project: Express
Copyright (c) 2009-2014 TJ Holowaychuk
Copyright (c) 2013-2014 Roman Shtylman
Copyright (c) 2014-2015 Douglas Christopher Wilson
License: MIT -
Project: Sequelize
Copyright (c) 2014-present Sequelize contributors
License: MIT -
Project: Dotenv
Copyright (c) 2015, Scott Motte
License: BSD 2-Clause -
Project: Chai
Copyright (c) 2017 Chai.js Assertion Library
License: MIT -
Project: Mocha
Copyright (c) 2011-2021 OpenJS Foundation and contributors
License: MIT -
Project: Supertest
Copyright (c) 2014 TJ Holowaychuk
License: MIT