Giter Club home page Giter Club logo

rails_engine's Introduction

Rails Engine

This is a project designed to use Rails and ActiveRecord in order to build a JSON API which exposes the SalesEngine data schema.

  • Author: Leah K. Miller

Learning Goals

  • Learn how to build Single-Responsibility controllers to provide a well-designed and versioned API
  • Learn how to use controller tests to drive your design
  • Use Ruby and ActiveRecord to perform more complicated business intelligence

Tech Used

  • Rails
  • PostgreSQL
  • RSpec
  • FactoryBot
  • ShouldaMatchers
  • SimpleCov
  • Ruby version - ruby 2.4.5

  • I used RSpec tests to drive my development; SpecHarness is also available testing

  • Table Relationships as follows: schema

  • I wrote a blog post! Please feel free to visit: https://medium.com/@le3ah/rails-engine-a5d2e3aab1ce

  • I imported the database files using an import.rake file. Code example:

task :customer_import => :environment do
  CSV.foreach('./db/data/customers.csv', :headers => true ) do |row|
    Customer.create!(row.to_h)
  end
end```

rails_engine's People

Contributors

le3ah avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

James Cloos avatar

rails_engine's Issues

Single Finders

Each data category should offer find finders to return a single object representation. The finder should work with any of the attributes defined on the data type and always be case insensitive

Relationship Endpoints - Items

Items
GET /api/v1/items/:id/invoice_items returns a collection of associated invoice items
GET /api/v1/items/:id/merchant returns the associated merchant

Relationship Endpoints - Merchants

Merchants
GET /api/v1/merchants/:id/items returns a collection of items associated with that merchant
GET /api/v1/merchants/:id/invoices returns a collection of invoices associated with that merchant from their known orders

Relationship Endpoints - Invoices

Invoices
GET /api/v1/invoices/:id/transactions returns a collection of associated transactions
GET /api/v1/invoices/:id/invoice_items returns a collection of associated invoice items
GET /api/v1/invoices/:id/items returns a collection of associated items
GET /api/v1/invoices/:id/customer returns the associated customer
GET /api/v1/invoices/:id/merchant returns the associated merchant

Business Intelligence - All Merchants

GET /api/v1/merchants/most_revenue?quantity=x returns the top x merchants ranked by total revenue
GET /api/v1/merchants/most_items?quantity=x returns the top x merchants ranked by total number of items sold
GET /api/v1/merchants/revenue?date=x returns the total revenue for date x across all merchants
Assume the dates provided match the format of a standard ActiveRecord timestamp.

BI - Items

GET /api/v1/items/most_revenue?quantity=x returns the top x items ranked by total revenue generated
GET /api/v1/items/most_items?quantity=x returns the top x item instances ranked by total number sold
GET /api/v1/items/:id/best_day returns the date with the most sales for the given item using the invoice date. If there are multiple days with equal number of sales, return the most recent day.

Index Action

Each data category should include an index action which renders a JSON representation of all the appropriate records:
GET /api/v1/merchants.json

BI - Customers

GET /api/v1/customers/:id/favorite_merchant returns a merchant where the customer has conducted the most successful transactions

Random array

Returns a random resource.

api/v1/merchants/random.json

Business Intelligence - Single Merchant

GET /api/v1/merchants/:id/revenue returns the total revenue for that merchant across successful transactions
GET /api/v1/merchants/:id/revenue?date=x returns the total revenue for that merchant for a specific invoice date x
GET /api/v1/merchants/:id/favorite_customer returns the customer who has conducted the most total number of successful transactions.
BOSS MODE: GET /api/v1/merchants/:id/customers_with_pending_invoices returns a collection of customers which have pending (unpaid) invoices. A pending invoice has no transactions with a result of success. This means all transactions are failed. Postgres has an EXCEPT operator that might be useful. ActiveRecord also has a find_by_sql that might help.
NOTE: Failed charges should never be counted in revenue totals or statistics.

NOTE: All revenues should be reported as a float with two decimal places.

Multi-Finders

Each category should offer find_all finders which should return all matches for the given query. It should work with any of the attributes defined on the data type and always be case insensitive.

Relationship Endpoints - Customers

Customers
GET /api/v1/customers/:id/invoices returns a collection of associated invoices
GET /api/v1/customers/:id/transactions returns a collection of associated transactions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.