Homies and money moves
This commit is contained in:
2
app/controllers/homies_controller.rb
Normal file
2
app/controllers/homies_controller.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class HomiesController < ApplicationController::API
|
||||
end
|
||||
23
app/controllers/money_moves_controller.rb
Normal file
23
app/controllers/money_moves_controller.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class MoneyMovesController < ApplicationController::API
|
||||
def list
|
||||
json_response(MoneyMove.find(:all).order(:created_at))
|
||||
end
|
||||
|
||||
def create
|
||||
money_move = MoneyMove.new(money_move_params)
|
||||
if money_move.save
|
||||
json_response(money_move)
|
||||
else
|
||||
error_response(:bad_request)
|
||||
end
|
||||
end
|
||||
|
||||
def money_move_params
|
||||
params.require(:money_moves).permit(
|
||||
:description,
|
||||
:amount,
|
||||
:from_homie_id,
|
||||
:to_homie_id
|
||||
)
|
||||
end
|
||||
end
|
||||
0
app/models/concerns/error_response.rb
Normal file
0
app/models/concerns/error_response.rb
Normal file
5
app/models/concerns/json_response.rb
Normal file
5
app/models/concerns/json_response.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module Response
|
||||
def json_response(object, status = :ok)
|
||||
render json: object, status: status
|
||||
end
|
||||
end
|
||||
4
app/models/homie.rb
Normal file
4
app/models/homie.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class Homie < ApplicationRecord
|
||||
has_many :money_moves_from, class_name: 'MoneyMove', column: :from_homie_id
|
||||
has_many :money_moves_to, class_name: 'MoneyMove', column: :to_homie_id
|
||||
end
|
||||
4
app/models/money_move.rb
Normal file
4
app/models/money_move.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class MoneyMove < ApplicationRecord
|
||||
belongs_to :from_homie, class_name: 'Homie'
|
||||
belongs_to :to_homie, class_name: 'Homie'
|
||||
end
|
||||
@@ -23,10 +23,10 @@ default: &default
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
username: "docker",
|
||||
password: "docker",
|
||||
host: localhost,
|
||||
port: 5431,
|
||||
username: "docker"
|
||||
password: "docker"
|
||||
host: localhost
|
||||
port: 5432
|
||||
database: roraccounting_development
|
||||
|
||||
# The specified database role being used to connect to postgres.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Rails.application.routes.draw do
|
||||
resources :money_moves
|
||||
resources :homies
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
end
|
||||
|
||||
10
db/migrate/20190620194110_create_homies.rb
Normal file
10
db/migrate/20190620194110_create_homies.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class CreateHomies < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :homies do |t|
|
||||
t.text :name, null: false
|
||||
t.integer :importance, null: false, default: 5
|
||||
t.text :about
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
11
db/migrate/20190620200006_create_money_moves.rb
Normal file
11
db/migrate/20190620200006_create_money_moves.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class CreateMoneyMoves < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :money_moves do |t|
|
||||
t.text :description
|
||||
t.decimal :amount, precision: 12, scale: 3
|
||||
t.integer :from_homie_id, null: false
|
||||
t.integer :to_homie_id, null: false
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
35
db/schema.rb
Normal file
35
db/schema.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_06_20_200006) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
create_table "homies", force: :cascade do |t|
|
||||
t.text "name", null: false
|
||||
t.integer "importance", default: 5, null: false
|
||||
t.text "about"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "money_moves", force: :cascade do |t|
|
||||
t.text "description"
|
||||
t.decimal "amount", precision: 12, scale: 3
|
||||
t.integer "from_homie_id", null: false
|
||||
t.integer "to_homie_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
end
|
||||
7
test/controllers/homies_controller_test.rb
Normal file
7
test/controllers/homies_controller_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class HomiesControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/controllers/money_moves_controller_test.rb
Normal file
7
test/controllers/money_moves_controller_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class MoneyMovesControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
9
test/fixtures/homies.yml
vendored
Normal file
9
test/fixtures/homies.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
name: MyText
|
||||
importance: 1
|
||||
|
||||
two:
|
||||
name: MyText
|
||||
importance: 1
|
||||
13
test/fixtures/money_moves.yml
vendored
Normal file
13
test/fixtures/money_moves.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
description: MyText
|
||||
amount: 9.99
|
||||
from_homie: one
|
||||
to_homie: one
|
||||
|
||||
two:
|
||||
description: MyText
|
||||
amount: 9.99
|
||||
from_homie: two
|
||||
to_homie: two
|
||||
7
test/models/homie_test.rb
Normal file
7
test/models/homie_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class HomieTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/money_move_test.rb
Normal file
7
test/models/money_move_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class MoneyMoveTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user