Skip to content

Latest commit

 

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TinyCarList Back-End 🌉

Background

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.


Motivation

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.


Installation

To install this repo locally:

  1. Clone this repo.
  2. Set up a Docker container running MySQL. Set the password to password.
  3. Create a .env file in the root directory.
  4. 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
    
  5. Create a .env.test file in the root directory.
  6. 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
    
  7. To run the tests, run npm test. In the unaltered repo they should pass.
  8. If all tests pass then the API can be run. Run npm start.
  9. Launch Postman to interact with the API.

Interacting 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.

Create a Listing (POST)

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]"  
}

Fetch All Listings (GET)

EFFECT: Fetches all listings in the database.
METHOD: GET to localhost:4000/listing

Fetch Specific Listings by Query (GET)

EFFECT: Fetch all listings that match a specified query
METHOD: GET to localhost:4000/listing?key=value EXAMPLE: GET localhost:4000/listing?year=2010

Modify a Listing (PATCH)

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",  
}

Delete a Listing (DELETE)

EFFECT: Deletes a listing using its listingId.
METHOD: DELETE to localhost:4000/listing/id
EXAMPLE: DELETE localhost:4000/listing/2


Framework

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.


Next Steps

  • 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.

Credits

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages