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 any number of Coupons in the system.
    • A Merchant can only have a maximum of 5 activated Coupons in the system at one time.
    • A Merchant cannot delete a Coupon, rather they can only activate/deactivate them.
    • At minimum a Coupon:
      • Has a name
      • Has a unique code (e.g. “BOGO50”). This code must be unique in the whole database.
      • Can be either percent-off or dollar-off value. Your database table must be able to store both types.

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.

1. Merchant Coupon Show

Returns a specific coupon and shows a count of how many times that coupon has been used.

Response

status: 200
body:

{
  "data": {
    "id": "1",
    "type": "coupon",
    "attributes": {
      "name": "Buy One Get One 50",
      ...remaining attributes go here...   
    }
  }
}

</section>


2) Iterating on Existing Endpoints


Lesson Search Results

Showing top 10 results