From cb42b86136d7987e96f89ed6250cc9540d14c77d Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 11 Aug 2024 19:24:24 +0200 Subject: [PATCH] Include confirmation status --- app/models/guest.rb | 8 ++++++++ app/serializers/serializable_guest.rb | 6 +++++- db/migrate/20240811170021_add_status_to_guest.rb | 5 +++++ db/schema.rb | 3 ++- db/seeds.rb | 3 ++- 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20240811170021_add_status_to_guest.rb diff --git a/app/models/guest.rb b/app/models/guest.rb index 927a589..cc4f615 100644 --- a/app/models/guest.rb +++ b/app/models/guest.rb @@ -1,6 +1,14 @@ class Guest < ApplicationRecord acts_as_taggable_on :affinity_groups, :unbreakable_bonds belongs_to :group + + enum status: { + considered: 0, + invited: 10, + confirmed: 20, + declined: 30 + } + def full_name "#{first_name} #{last_name}" end diff --git a/app/serializers/serializable_guest.rb b/app/serializers/serializable_guest.rb index 3311d8b..647c106 100644 --- a/app/serializers/serializable_guest.rb +++ b/app/serializers/serializable_guest.rb @@ -1,7 +1,7 @@ class SerializableGuest < JSONAPI::Serializable::Resource type 'guest' - attributes :id, :email, :group_id + attributes :id, :email, :group_id, :status attribute :name do "#{@object.first_name} #{@object.last_name}" @@ -10,4 +10,8 @@ class SerializableGuest < JSONAPI::Serializable::Resource attribute :group_name do @object.group.name end + + attribute :status do + @object.status.capitalize + end end diff --git a/db/migrate/20240811170021_add_status_to_guest.rb b/db/migrate/20240811170021_add_status_to_guest.rb new file mode 100644 index 0000000..cd7be5b --- /dev/null +++ b/db/migrate/20240811170021_add_status_to_guest.rb @@ -0,0 +1,5 @@ +class AddStatusToGuest < ActiveRecord::Migration[7.1] + def change + add_column :guests, :status, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 47376a1..c4145db 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[7.1].define(version: 2024_08_11_154115) do +ActiveRecord::Schema[7.1].define(version: 2024_08_11_170021) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -45,6 +45,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_08_11_154115) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.uuid "group_id", null: false + t.integer "status", default: 0 t.index ["group_id"], name: "index_guests_on_group_id" end diff --git a/db/seeds.rb b/db/seeds.rb index 53c3376..391d6e1 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -60,6 +60,7 @@ NUMBER_OF_GUESTS.times do last_name: Faker::Name.last_name, email: Faker::Internet.email, phone: Faker::PhoneNumber.cell_phone, - group: groups.sample + group: groups.sample, + status: Guest.statuses.keys.sample ) end -- 2.47.1