mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 03:40:49 +08:00
新增:数据集部分接口
This commit is contained in:
38
app/controllers/api/v1/projects/datasets_controller.rb
Normal file
38
app/controllers/api/v1/projects/datasets_controller.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
class Api::V1::Projects::DatasetsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above
|
||||
before_action :find_dataset, only: [:update, :show]
|
||||
|
||||
def create
|
||||
return render_error('该项目下已存在数据集!') if @project.project_dataset.present?
|
||||
@project_dataset = ProjectDataset.new(dataset_params.merge!(project_id: @project.id))
|
||||
if @project_dataset.save!
|
||||
render_ok
|
||||
else
|
||||
render_error('创建数据集失败!')
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@project_dataset.attributes = dataset_params
|
||||
if @project_dataset.save!
|
||||
render_ok
|
||||
else
|
||||
render_error("更新数据集失败!")
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@attachments = @project_dataset.attachments.includes(:author)
|
||||
end
|
||||
|
||||
private
|
||||
def dataset_params
|
||||
params.permit(:title, :description)
|
||||
end
|
||||
|
||||
def find_dataset
|
||||
@project_dataset = @project.project_dataset
|
||||
return render_not_found unless @project_dataset.present?
|
||||
end
|
||||
|
||||
end
|
||||
@@ -95,6 +95,9 @@ class AttachmentsController < ApplicationController
|
||||
@attachment.disk_directory = month_folder
|
||||
@attachment.cloud_url = remote_path
|
||||
@attachment.uuid = SecureRandom.uuid
|
||||
@attachment.description = params[:description]
|
||||
@attachment.container_id = params[:container_id]
|
||||
@attachment.container_type = params[:container_type]
|
||||
@attachment.save!
|
||||
else
|
||||
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
||||
|
||||
Reference in New Issue
Block a user