about summary refs log tree commit diff
path: root/app/controllers/api/v1
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2022-08-26 18:09:33 -0500
committerStarfall <us@starfall.systems>2022-08-26 18:09:33 -0500
commitb581e6b6d4a5ba9ed4ae17427b7f2d5d158be4e5 (patch)
tree06c3f6859d5cee4794d678a0aa57d15c31036ce4 /app/controllers/api/v1
parent3871928aa4f660cdf1a0c451ac3396052b59ddea (diff)
parent978dd7e73c911441503ff803ffdce544ce50a33d (diff)
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'app/controllers/api/v1')
-rw-r--r--app/controllers/api/v1/filters/statuses_controller.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/app/controllers/api/v1/filters/statuses_controller.rb b/app/controllers/api/v1/filters/statuses_controller.rb
new file mode 100644
index 000000000..b6bed306f
--- /dev/null
+++ b/app/controllers/api/v1/filters/statuses_controller.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+class Api::V1::Filters::StatusesController < Api::BaseController
+  before_action -> { doorkeeper_authorize! :read, :'read:filters' }, only: [:index, :show]
+  before_action -> { doorkeeper_authorize! :write, :'write:filters' }, except: [:index, :show]
+  before_action :require_user!
+
+  before_action :set_status_filters, only: :index
+  before_action :set_status_filter, only: [:show, :destroy]
+
+  def index
+    render json: @status_filters, each_serializer: REST::FilterStatusSerializer
+  end
+
+  def create
+    @status_filter = current_account.custom_filters.find(params[:filter_id]).statuses.create!(resource_params)
+
+    render json: @status_filter, serializer: REST::FilterStatusSerializer
+  end
+
+  def show
+    render json: @status_filter, serializer: REST::FilterStatusSerializer
+  end
+
+  def destroy
+    @status_filter.destroy!
+    render_empty
+  end
+
+  private
+
+  def set_status_filters
+    filter = current_account.custom_filters.includes(:statuses).find(params[:filter_id])
+    @status_filters = filter.statuses
+  end
+
+  def set_status_filter
+    @status_filter = CustomFilterStatus.includes(:custom_filter).where(custom_filter: { account: current_account }).find(params[:id])
+  end
+
+  def resource_params
+    params.permit(:status_id)
+  end
+end