scinote-web/app/controllers/repository_columns/asset_columns_controller.rb

55 lines
1.7 KiB
Ruby
Raw Normal View History

2019-10-16 19:39:15 +08:00
# frozen_string_literal: true
module RepositoryColumns
class AssetColumnsController < BaseColumnsController
include InputSanitizeHelper
before_action :load_column, only: %i(update destroy)
before_action :check_create_permissions, only: :create
before_action :check_manage_permissions, only: %i(update destroy)
def create
2019-10-16 21:07:46 +08:00
service = RepositoryColumns::CreateColumnService
.call(user: current_user, repository: @repository, team: current_team,
2019-10-17 22:43:44 +08:00
column_type: Extends::REPOSITORY_DATA_TYPES[:RepositoryAssetValue],
params: repository_column_params)
2019-10-16 19:39:15 +08:00
if service.succeed?
2019-10-25 16:39:12 +08:00
render json: service.column, status: :created, creating: true
2019-10-16 19:39:15 +08:00
else
render json: service.errors, status: :unprocessable_entity
end
end
def update
2019-10-16 21:07:46 +08:00
service = RepositoryColumns::UpdateColumnService
2019-10-16 19:39:15 +08:00
.call(user: current_user,
team: current_team,
column: @repository_column,
params: repository_column_params)
if service.succeed?
2019-11-11 16:04:36 +08:00
render json: service.column, status: :ok, editing: true
2019-10-16 19:39:15 +08:00
else
render json: service.errors, status: :unprocessable_entity
end
end
def destroy
2019-10-16 21:07:46 +08:00
service = RepositoryColumns::DeleteColumnService
2019-10-16 19:39:15 +08:00
.call(user: current_user, team: current_team, column: @repository_column)
if service.succeed?
render json: {}, status: :ok
else
render json: service.errors, status: :unprocessable_entity
end
end
private
def repository_column_params
params.require(:repository_column).permit(:name)
end
end
end