Giter Site home page Giter Site logo

0xleopard / bank-app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lapinskap/bank-app

0.0 0.0 0.0 272 KB

Bank App: Ruby on Rails 5 Application with haml and API

Home Page: https://vast-shelf-72416.herokuapp.com/

Ruby 73.45% JavaScript 4.22% CSS 1.00% HTML 21.33%

bank-app's Introduction

bank-app

Ruby on Rails 5 Application with HAML and PostgreSQL

Table of contents

General info

Simple banking application written in Rails 5 where a user can perform withdrawals and deposit transactions. The purpose is to document the current practices in terms of organizing javascript, api code (Rails) and command patterns for business rules.

Bank account belongs to a client, a client can have many bank accounts.

I was learning how to create CRUD in Rails.

Screenshots

Example screenshot

When we click "Add new transaction" a charming Modal appears to our eyes:

Example screenshot

Example screenshot

Technologies

  • Ruby on Rails 5
  • HAML
  • jQuery
  • PostgreSQL database

Setup

$ git clone https://github.com/lapinskap/bank-app
$ cd bank-app
$ bundle install
$ rails s

Operations in terminal

Add a client:

$ rails console
$ Client.create!(first_name: "Juan", middle_name: "Pablo", last_name: "Fernandez", client_number: "42034823") 
$ client = Client.last
$ exit

Rails model will change clients name to uppercase letters

Create Bank Account:

$ rails console
$ BankAccount.create!(client: client, account_number: "000000001")
$ exit

client: client <- client name defined while creating a client

default balance is $0.00

Delete history of transactions:

$ rails console
$ AccountTransaction.destroy_all

or delete last transaction:

$ AccountTransaction.last.destroy!
$ exit

$ rails s

Code Examples

Module example

app/models/account_transaction.rb

class AccountTransaction < ApplicationRecord
  belongs_to :bank_account

  TRANSACTION_TYPES = ["withdraw","deposit"]

  validates :bank_account, presence: true
  validates :amount, presence: true, numericality: true
  validates :transaction_number, presence: true, uniqueness: true
  validates :transaction_type, presence: true, inclusion: { in: TRANSACTION_TYPES}

  before_validation :load_defaults

  def load_defaults
    if self.new_record?
      self.transaction_number = SecureRandom.uuid
    end
  end
end

Validate new transaction

app/operations/bank_accounts/validate_new_transaction.rb

module BankAccounts
    class ValidateNewTransaction
        def initialize(amount: , transaction_type: , bank_account_id: )
            @amount = amount.try(:to_i) 
            @transaction_type = transaction_type
            @bank_account_id = bank_account_id
            @bank_account = BankAccount.where(id: @bank_account_id).first
            @errors = []
        end

        def execute!
            validate_existence_of_account!

            if @transaction_type == "withdraw" and @bank_account.present?
                validate_withdrawal!
            end
            @errors
        end

        private

        def validate_withdrawal!
            if @bank_account.balance - @amount < 0.00
                @errors << "Not enough money"
            end
        end

        def validate_existence_of_account!
            if @bank_account.blank?
                @errors << "Account not found"
            end

        end
    end
end

HAML example

<div class="container">
 <div class="row">
  <div class="col-md-12"></div>
 </div>
</div>

%div.container
 %div.row
  %div.col-md-12

.container
 .row
  .col-md-12

Features

List of features ready and TODOs for future development

  • HAML files
  • Ajax calls

To-do list:

  • Add styles!
  • Solve the problem with the lack of javascript precompile in heroku server

Status

Project is: in progress

Inspiration

An idea for an application that I liked very much - Inspired by devlogs youtube videos - I decided that I want to do my own version of "simple banking app". It seems easy for me to expand in the future.

Contact

Created by @lapinskap - feel free to contact me!

bank-app's People

Contributors

lapinskap avatar

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.