Skip to content

Commit 2ab661e

Browse files
committed
feat: implement feedback template
1 parent a004e58 commit 2ab661e

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

app/controllers/api/v1/feedbacks_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def index
1717
feedbacks = Feedback.recent.includes(:feedback_votes)
1818
feedbacks = feedbacks.by_category(params[:category]) if params[:category].present?
1919
feedbacks = feedbacks.where(status: params[:status]) if params[:status].present?
20+
feedbacks = feedbacks.by_source(params[:source]) if params[:source].present?
2021

2122
result = paginate(feedbacks)
2223
items = result[:data].map { |f| feedback_data(f, user: current_user) }
@@ -63,7 +64,7 @@ def set_feedback
6364
end
6465

6566
def feedback_params
66-
params.require(:feedback).permit(:category, :title, :description, :rating)
67+
params.require(:feedback).permit(:category, :title, :description, :rating, :source)
6768
end
6869

6970
def feedback_data(feedback, user: nil)
@@ -77,6 +78,7 @@ def feedback_data(feedback, user: nil)
7778
status: feedback.status,
7879
votes_count: feedback.votes_count,
7980
user_voted: voted,
81+
source: feedback.source,
8082
created_at: feedback.created_at
8183
}
8284
end

app/models/feedback.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class Feedback < ApplicationRecord
1111
CATEGORIES = %w[bug feature improvement performance other].freeze
1212
STATUSES = %w[open in_review resolved closed].freeze
13+
SOURCES = %w[prostaff scrims].freeze
1314

1415
belongs_to :user, optional: true
1516
belongs_to :organization, optional: true
@@ -20,8 +21,10 @@ class Feedback < ApplicationRecord
2021
validates :description, presence: true, length: { maximum: 4000 }
2122
validates :rating, inclusion: { in: 1..5 }, allow_nil: true
2223
validates :status, inclusion: { in: STATUSES }
24+
validates :source, inclusion: { in: SOURCES }
2325

24-
scope :open, -> { where(status: 'open') }
25-
scope :recent, -> { order(created_at: :desc) }
26+
scope :open, -> { where(status: 'open') }
27+
scope :recent, -> { order(created_at: :desc) }
2628
scope :by_category, ->(cat) { where(category: cat) }
29+
scope :by_source, ->(src) { where(source: src) }
2730
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class AddSourceToFeedbacks < ActiveRecord::Migration[7.1]
4+
def change
5+
add_column :feedbacks, :source, :string, null: false, default: 'prostaff'
6+
add_index :feedbacks, :source
7+
end
8+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2026_04_07_100001) do
13+
ActiveRecord::Schema[7.2].define(version: 2026_04_07_200001) do
1414
create_schema "auth"
1515
create_schema "extensions"
1616
create_schema "graphql"
@@ -207,8 +207,10 @@
207207
t.datetime "created_at", null: false
208208
t.datetime "updated_at", null: false
209209
t.integer "votes_count", default: 0, null: false
210+
t.string "source", default: "prostaff", null: false
210211
t.index ["category"], name: "index_feedbacks_on_category"
211212
t.index ["organization_id"], name: "index_feedbacks_on_organization_id"
213+
t.index ["source"], name: "index_feedbacks_on_source"
212214
t.index ["status"], name: "index_feedbacks_on_status"
213215
t.index ["user_id"], name: "index_feedbacks_on_user_id"
214216
end

0 commit comments

Comments
 (0)