From 0737717bc91b111d40d0e3b733aa29b4f9855cf1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:50:28 +0530 Subject: [PATCH] chore(CE): add feedback model (#403) Co-authored-by: afthab vp --- server/app/models/feedback.rb | 14 ++++++++++++ server/app/models/visual_component.rb | 2 ++ .../20241007070931_create_feedbacks.rb | 14 ++++++++++++ server/db/schema.rb | 13 ++++++++++- server/spec/models/feedback_spec.rb | 22 +++++++++++++++++++ server/spec/models/visual_component_spec.rb | 1 + 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 server/app/models/feedback.rb create mode 100644 server/db/migrate/20241007070931_create_feedbacks.rb create mode 100644 server/spec/models/feedback_spec.rb diff --git a/server/app/models/feedback.rb b/server/app/models/feedback.rb new file mode 100644 index 00000000..c6ed57ae --- /dev/null +++ b/server/app/models/feedback.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class Feedback < ApplicationRecord + validates :data_app_id, presence: true + validates :visual_component_id, presence: true + validates :model_id, presence: true + validates :reaction, presence: true + + belongs_to :data_app + belongs_to :visual_component + belongs_to :model + + enum reaction: { positive: 0, negative: 1 } +end diff --git a/server/app/models/visual_component.rb b/server/app/models/visual_component.rb index 0dc6211b..661414ac 100644 --- a/server/app/models/visual_component.rb +++ b/server/app/models/visual_component.rb @@ -11,4 +11,6 @@ class VisualComponent < ApplicationRecord belongs_to :workspace belongs_to :data_app belongs_to :model + + has_many :feedbacks, dependent: :destroy end diff --git a/server/db/migrate/20241007070931_create_feedbacks.rb b/server/db/migrate/20241007070931_create_feedbacks.rb new file mode 100644 index 00000000..e1cfdb49 --- /dev/null +++ b/server/db/migrate/20241007070931_create_feedbacks.rb @@ -0,0 +1,14 @@ +class CreateFeedbacks < ActiveRecord::Migration[7.1] + def change + create_table :feedbacks do |t| + t.integer :workspace_id, null: false + t.integer :data_app_id, null: false + t.integer :visual_component_id, null: false + t.integer :model_id, null: false + t.integer :reaction, null: false + t.text :feedback_content + + t.timestamps + end + end +end diff --git a/server/db/schema.rb b/server/db/schema.rb index 270aebed..d36c7f39 100644 --- a/server/db/schema.rb +++ b/server/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_09_23_150740) do +ActiveRecord::Schema[7.1].define(version: 2024_10_07_070931) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -51,6 +51,17 @@ create_table "data_migrations", primary_key: "version", id: :string, force: :cascade do |t| end + create_table "feedbacks", force: :cascade do |t| + t.integer "workspace_id", null: false + t.integer "data_app_id", null: false + t.integer "visual_component_id", null: false + t.integer "model_id", null: false + t.integer "reaction", null: false + t.text "feedback_content" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "models", force: :cascade do |t| t.string "name" t.integer "workspace_id" diff --git a/server/spec/models/feedback_spec.rb b/server/spec/models/feedback_spec.rb new file mode 100644 index 00000000..138b3e1a --- /dev/null +++ b/server/spec/models/feedback_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe Feedback, type: :model do + describe "associations" do + it { should belong_to(:data_app) } + it { should belong_to(:visual_component) } + it { should belong_to(:model) } + end + + describe "validations" do + it { should validate_presence_of(:data_app_id) } + it { should validate_presence_of(:visual_component_id) } + it { should validate_presence_of(:model_id) } + it { should validate_presence_of(:reaction) } + end + + describe "enum" do + it { should define_enum_for(:reaction).with_values(positive: 0, negative: 1) } + end +end diff --git a/server/spec/models/visual_component_spec.rb b/server/spec/models/visual_component_spec.rb index a7c467cb..7ce604d6 100644 --- a/server/spec/models/visual_component_spec.rb +++ b/server/spec/models/visual_component_spec.rb @@ -13,4 +13,5 @@ it { should belong_to(:workspace) } it { should belong_to(:data_app) } it { should belong_to(:model) } + it { should have_many(:feedbacks).dependent(:destroy) } end