From 5e2d5c3b28f795b318be4563b5bda03fba2f4a71 Mon Sep 17 00:00:00 2001
From: Sebastian Kippe
Date: Sat, 19 Dec 2020 13:28:47 +0100
Subject: [PATCH] Add paid_at date to donations
---
app/controllers/admin/donations_controller.rb | 2 +-
app/controllers/donations_controller.rb | 2 +-
app/models/donation.rb | 3 +++
app/views/admin/donations/_form.html.erb | 7 +++++++
app/views/admin/donations/index.html.erb | 2 ++
app/views/admin/donations/show.html.erb | 5 +++++
app/views/donations/index.html.erb | 2 +-
db/migrate/20201219121808_add_paid_at_to_donations.rb | 5 +++++
db/schema.rb | 3 ++-
9 files changed, 27 insertions(+), 4 deletions(-)
create mode 100644 db/migrate/20201219121808_add_paid_at_to_donations.rb
diff --git a/app/controllers/admin/donations_controller.rb b/app/controllers/admin/donations_controller.rb
index 6aa0b36..7b00bac 100644
--- a/app/controllers/admin/donations_controller.rb
+++ b/app/controllers/admin/donations_controller.rb
@@ -69,6 +69,6 @@ class Admin::DonationsController < Admin::BaseController
# Only allow a list of trusted parameters through.
def donation_params
- params.require(:donation).permit(:user_id, :amount_sats, :amount_eur, :amount_usd, :public_name)
+ params.require(:donation).permit(:user_id, :amount_sats, :amount_eur, :amount_usd, :public_name, :paid_at)
end
end
diff --git a/app/controllers/donations_controller.rb b/app/controllers/donations_controller.rb
index d5d74bc..74ee81c 100644
--- a/app/controllers/donations_controller.rb
+++ b/app/controllers/donations_controller.rb
@@ -4,6 +4,6 @@ class DonationsController < ApplicationController
# GET /donations
# GET /donations.json
def index
- @donations = current_user.donations
+ @donations = current_user.donations.completed
end
end
diff --git a/app/models/donation.rb b/app/models/donation.rb
index 183e7fc..30f13a0 100644
--- a/app/models/donation.rb
+++ b/app/models/donation.rb
@@ -7,4 +7,7 @@ class Donation < ApplicationRecord
# Hooks
# TODO before_create :store_fiat_value
+
+ #Scopes
+ scope :completed, -> { where.not(paid_at: nil) }
end
diff --git a/app/views/admin/donations/_form.html.erb b/app/views/admin/donations/_form.html.erb
index 09f124c..038d129 100644
--- a/app/views/admin/donations/_form.html.erb
+++ b/app/views/admin/donations/_form.html.erb
@@ -45,6 +45,13 @@
+
<%= form.submit %>
diff --git a/app/views/admin/donations/index.html.erb b/app/views/admin/donations/index.html.erb
index ef69627..6f4c674 100644
--- a/app/views/admin/donations/index.html.erb
+++ b/app/views/admin/donations/index.html.erb
@@ -9,6 +9,7 @@
in EUR |
in USD |
Public name |
+
Date |
|
@@ -21,6 +22,7 @@
<%= donation.amount_eur %> |
<%= donation.amount_usd %> |
<%= donation.public_name %> |
+
<%= donation.paid_at ? donation.paid_at.strftime("%Y-%m-%d") : "" %> |
<%= link_to 'Show', admin_donation_path(donation) %> |
<%= link_to 'Edit', edit_admin_donation_path(donation) %> |
<%= link_to 'Destroy', admin_donation_path(donation), method: :delete, data: { confirm: 'Are you sure?' } %> |
diff --git a/app/views/admin/donations/show.html.erb b/app/views/admin/donations/show.html.erb
index b6bc85a..12bc37e 100644
--- a/app/views/admin/donations/show.html.erb
+++ b/app/views/admin/donations/show.html.erb
@@ -25,5 +25,10 @@
<%= @donation.public_name %>
+
+ Date:
+ <%= @donation.paid_at %>
+
+
<%= link_to 'Edit', edit_admin_donation_path(@donation) %> |
<%= link_to 'Back', admin_donations_path %>
diff --git a/app/views/donations/index.html.erb b/app/views/donations/index.html.erb
index f2a3e8d..0dadba5 100644
--- a/app/views/donations/index.html.erb
+++ b/app/views/donations/index.html.erb
@@ -12,7 +12,7 @@
<% @donations.each do |donation| %>
- <%= donation.created_at.strftime("%B %d, %Y") %>
+ <%= donation.paid_at.strftime("%B %d, %Y") %>
<%= sats_to_btc donation.amount_sats %> BTC
diff --git a/db/migrate/20201219121808_add_paid_at_to_donations.rb b/db/migrate/20201219121808_add_paid_at_to_donations.rb
new file mode 100644
index 0000000..ce690c5
--- /dev/null
+++ b/db/migrate/20201219121808_add_paid_at_to_donations.rb
@@ -0,0 +1,5 @@
+class AddPaidAtToDonations < ActiveRecord::Migration[6.0]
+ def change
+ add_column :donations, :paid_at, :datetime
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 49ae73a..db024da 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2020_12_17_161544) do
+ActiveRecord::Schema.define(version: 2020_12_19_121808) do
create_table "donations", force: :cascade do |t|
t.integer "user_id"
@@ -20,6 +20,7 @@ ActiveRecord::Schema.define(version: 2020_12_17_161544) do
t.string "public_name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
+ t.datetime "paid_at"
t.index ["user_id"], name: "index_donations_on_user_id"
end