forked from Gitlink/forgeplus
55 lines
1.6 KiB
Ruby
55 lines
1.6 KiB
Ruby
class Api::V1::Projects::ProjectTemplatesController < Api::V1::BaseController
|
|
before_action :require_public_and_member_above, only: [:index, :show]
|
|
|
|
def index
|
|
@project_templates = ProjectTemplate.where(project_id: @project.id)
|
|
@project_templates = @project_templates.where(type: params[:type]) if params[:type].present?
|
|
@project_templates = @project_templates.order(created_at: :asc)
|
|
@project_templates = kaminari_paginate(@project_templates)
|
|
end
|
|
|
|
def show
|
|
@project_template = ProjectTemplate.find_by_id(params[:id])
|
|
if @project_template.blank?
|
|
render_not_found("模板不存在!")
|
|
end
|
|
end
|
|
|
|
before_action :require_operate_above, only: [:create, :update, :destroy]
|
|
|
|
def create
|
|
@project_template = ProjectTemplate.new(project_template_params)
|
|
@project_template.project_id = @project.id
|
|
if @project_template.save!
|
|
render_ok
|
|
else
|
|
render_error("创建模板失败!")
|
|
end
|
|
end
|
|
|
|
def update
|
|
@project_template = ProjectTemplate.find_by_id(params[:id])
|
|
return render_not_found("模板不存在!") if @project_template.blank?
|
|
if @project_template.update!(project_template_params)
|
|
render_ok
|
|
else
|
|
render_error("更新模板失败!")
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@project_template = ProjectTemplate.find_by_id(params[:id])
|
|
return render_not_found("模板不存在!") if @project_template.blank?
|
|
if @project_template.destroy!
|
|
render_ok
|
|
else
|
|
render_error("删除模板失败!")
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def project_template_params
|
|
params.require(:project_template).permit(:type, :name, :content)
|
|
end
|
|
end |