Coupon Codes BE Requirements

Back to Coupon Codes Home

Database Notes

Regardless of which setup option you choose, you will need to make database migrations to complete this project. Our initial database setup happens when running rails db:seed because we’re using a Postgres database dump file. You might run into issues if you reset your database (i.e. drop it and recreate it). Typically, Rails doesn’t allow you to run your seeds file before you run database migrations, but you will have to do that on your project since your seeding step sets up the preliminary database. If you need to reset your database, run the following in this order:

rails db:{drop,create}
rails runner ActiveRecord::Tasks::DatabaseTasks.load_seed
rails db:migrate

Functionality Overview

  • A Coupon belongs to a Merchant
  • An Invoice optionally belongs to a Coupon. An invoice may only have one coupon.
    • Note: When creating this new association on Invoice, your existing tests will fail unless the association is optional. Use these guides as a reference.
    • You are not required to build functionality for a user applying a coupon to an invoice, but can instead use test data, Rails console or seed data to add coupons to existing invoices to verify behavior.
  • You should build full CRUD functionality for coupons with criteria/restrictions defined below:
    • A merchant can have a maximum of 5 activated coupons in the system at one time.
    • A merchant cannot delete a coupon, rather they can activate/deactivate them.
    • A Coupon has a name, unique code (e.g. “BOGO50”), and either percent-off or dollar-off value. The coupon’s code must be unique in the whole database.
  • If a coupon’s dollar value (ex. “$10 off”) exceeds the total cost of that merchant’s items on the invoice, the grand total for that merchant’s items should then be $0. (In other words, the merchant will never owe money to a customer.)
  • A coupon code from a Merchant only applies to Items sold by that Merchant.

1) CRUD Endpoints

Below is the expected JSON response for each request. We have also outlined a few examples of Sad Paths you may consider adding in. In your project, you should take time to implement at least 2 sad paths total, but you are not limited to the examples we provide.


2) Iterating on Existing Endpoints


Lesson Search Results

Showing top 10 results