Skip to content

Backend rails app that provides REST api endpoints for rails engine project

Notifications You must be signed in to change notification settings

PhilipDeFraties/rails-engine

Repository files navigation

Rails Engine

Contents

Overview

Rails Engine is a fictitious E-Commerce application intended showcase the developer's ability to create a consumable API that can be utilized by an accompanying front-end application.

Learning Goals

  • Expose an API
  • Use serializers to format JSON responses
  • Test API exposure
  • Compose advanced ActiveRecord queries to analyze information stored in SQL databases
  • Write basic SQL statements without the assistance of an ORM

Installation and Database Setup

  % git clone git@github.com:PhilipDeFraties/rails-engine.git
  % cd rails-engine  
  % bundle install
  % rails db:{create,migrate,seed}

Schema

Testing

The program was developed through strict Test-Driven Development, utilizing RSpec for integration and unit testing. Simplecov was used to monitor test coverage. At the time of writing, test coverage is at 100%. To run the test suite and see a coverage report enter the following commands into your terminal:

  % bundle exec rspec
  % open coverage/index.html

The program is also tested via a mock front-end application, Rails Driver, with its own test suite to test the rails-engine's endpoints externally. To run the front-end program's test suite, first run % rails s in your terminal, then open a new tab in your terminal (cmd+t) and enter the following commands:

  % git clone git@github.com:turingschool-examples/rails_driver.git
  % bundle exec rspec spec/features/harness_spec.rb

All tests should be passing.

Endpoints

Merchant CRUD

Items CRUD

Merchants Relationships

  • All items belonging to merchant: GET /api/v1/merchants/:id/items

Items Relationships

  • Item's merchant GET /api/v1/items/:id/merchants

Search Endpoints

Items and Merchants can be searched by any attributes, is case insensitive and will return partial matches

  • Items search single result: GET /api/v1/items/find?=

  • Items search list of results: GET /api/v1/items/find_all?=

  • Merchants search single result: GET /api/v1/merchants/find?=

  • Merchants search list of results: GET /api/v1/merchants/find_all?=

Business Intelligence Endpoints

  • Merchants ranked by revenue with specified quantity of results: GET /api/v1/merchants/most_items?quantity=

  • Total revenue for a single merchant: GET /api/v1/merchants/:id/revenue

  • Merchants ranked by total items sold with specified quantity of results: GET /api/v1/merchants/most_items?quantity=

  • Total revenue generated by all merchants across specified date range: GET /api/v1/revenue?start=<start_date>&end=<end_date>

Gems Utilized

  • gem 'factory_bot_rails'
  • gem 'faker'
  • gem 'pry'
  • gem 'fast_jsonapi'
  • gem 'rspec-rails'
  • gem 'capybara'
  • gem 'shoulda-matchers'
  • gem 'launchy'
  • gem 'simplecov'
  • gem 'webmock'
  • gem 'vcr'
  • gem 'activerecord-import'

Future Improvements

  • Some sad paths were taken into account and tested, such as searching for an item or merchant with an undefined parameter or blank value, however no sad path has been created for an empty search result, or incompatible values entered for crud functions.

  • Currently, the search endpoints all use the same method shared by the application_record, and the only difference between a multi search and a single search is that the results for a single search come back with all matches and are reduced to the first by a ruby method in the controller. This is not ideal as it places extra strain on the database by retrieving un-needed data. Further refactoring would entail making separate single and multi finders specific to merchants and items.

Contributor

Philip DeFraties
Github | LinkedIn

About

Backend rails app that provides REST api endpoints for rails engine project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published