Giter Club home page Giter Club logo

deposits_exercise's Introduction

Deposits Exercise

Assignment

Requirements

A tradeline on a credit report represents an account, such as a credit card or car loan.

In the codebase, the following exists:

  • The Tradeline model, which can be used to store tradelines in the database.
  • A Tradeline controller, which serves both the index and show routes for tradelines.
  • Basic rspec tests on the controller with a tradeline FactoryBot.

Add in the ability to create deposits for a specific tradeline using a JSON API call. You should store the deposit date (this is most likely a future date), and amount. Expose the outstanding balance for a given tradeline in the JSON output for TradelinesController#show, and TradelinesController#index. The oustanding balance should be calculated as the amount minus all of the deposit amounts.

In addition:

  • A deposit should not be able to be created that exceeds the outstanding balance of a tradeline.
  • You should return validation errors if a deposit cannot be created.
  • Expose endpoints for seeing all deposits for a given tradeline, as well as seeing an individual deposit.

Feel free to add any gems to the Gemfile, and touch any of the existing code. For example, if you prefer to use PostgreSQL or MySQL over the included SQLite, or a serializer of your choice, please go ahead. This is not required, but you can be as creative as you want.

This exercise is purely API based, and will not have any frontend components. Please do not spend more than 3 hours on this.

Setup

The exercise requires Ruby 3.3.0. Simply clone the repo, and run bundle to get started. This will install Rails 7.1.2, and the other specified gems.

Submission

Please do not fork the repo; if forked accidentally, please delete the fork. For review, either of the following methods for submission are preferred:

  • Cloning the repository and then uploading it under your Github account for review.
  • Zipping up the directory.

My Process

Planning

  1. Create Deposit model
    • generate model & run migration
    • set up associations with Tradeline
    • create index, show, and create routes (see Routes section)
    • serializer?
  2. Add outstanding balance to Tradeline responses
    • add serializer?
  3. Add validation for deposit amount with error handling
    • for amount > outstanding balance
    • for date in the past

Gems to add

  • jsonapi-serializer for response formatting
  • shoulda-matchers for testing relationships.. and validations?

Routes

  • Tradelines

    • GET /tradelines
      • include outstanding balance
    • GET /tradelines/:id
      • include outstanding balance
  • Deposits

    • GET /tradelines/:tradeline_id/deposits
    • GET /tradelines/:tradeline_id/deposits/:id
    • POST /tradelines/:tradeline_id/deposits
      • request includes date and amount
      • happy path: returns deposit with id, date, amount, and tradeline_id
      • error path: returns error message

Issues I've run into

  • When setting up Tradeline and Deposit associations, I cannot run test for models
    • Errors state pending migrations (screenshot)
    • What I tried:
      • 'rails db:migrate' shows no pending migrations
      • 'rails db:migrate:status' shows all migrations are up
      • checked in Rails console, and the tables exist
      • 'rails db:reset' but same error as running test occurs
    • Problem and Solution:
      • I was set up a migration for the Deposit model, but I created a reference to "account", not "tradeline".
      • I ran 'rails db:rollback' to remove the migration, and then created a new migration with the correct reference.
  • When creating a custom validation for the deposit amount, test fails
    • Inital custom validation is commented out in the Deposit model
    • Test Error: ArgumentError:You need to supply at least one validation
    • What I tried/Solution:
      • use validate numericality of :amount, less_than_or_equal_to: :maximum_balance

Things I'd like to refactor or include if I had more time

  • Add sad path testing and error handling (more 404s) for all requests
  • Refactor calidation for deposit amount
    • Try to figure out custom validation for deposit amount (as mentioned above)
    • Or validate inside the controller
      • This would prevent needing to call on the tradeline to check the outstanding balance inside of the Deposit model.
  • Creating controller tests following Afra's example

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.