mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-18 02:28:08 +00:00
First draft of API to add items to a collection (#37222)
This commit is contained in:
41
app/controllers/api/v1_alpha/collection_items_controller.rb
Normal file
41
app/controllers/api/v1_alpha/collection_items_controller.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1Alpha::CollectionItemsController < Api::BaseController
|
||||
include Authorization
|
||||
|
||||
before_action :check_feature_enabled
|
||||
|
||||
before_action -> { doorkeeper_authorize! :write, :'write:collections' }
|
||||
|
||||
before_action :require_user!
|
||||
|
||||
before_action :set_collection
|
||||
before_action :set_account, only: [:create]
|
||||
|
||||
after_action :verify_authorized
|
||||
|
||||
def create
|
||||
authorize @collection, :update?
|
||||
authorize @account, :feature?
|
||||
|
||||
@item = AddAccountToCollectionService.new.call(@collection, @account)
|
||||
|
||||
render json: @item, serializer: REST::CollectionItemSerializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_collection
|
||||
@collection = Collection.find(params[:collection_id])
|
||||
end
|
||||
|
||||
def set_account
|
||||
return render(json: { error: '`account_id` parameter is missing' }, status: 422) if params[:account_id].blank?
|
||||
|
||||
@account = Account.find(params[:account_id])
|
||||
end
|
||||
|
||||
def check_feature_enabled
|
||||
raise ActionController::RoutingError unless Mastodon::Feature.collections_enabled?
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user