新增:数据集部分接口
This commit is contained in:
parent
0a13387c1c
commit
dbfbee78fa
|
@ -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.disk_directory = month_folder
|
||||||
@attachment.cloud_url = remote_path
|
@attachment.cloud_url = remote_path
|
||||||
@attachment.uuid = SecureRandom.uuid
|
@attachment.uuid = SecureRandom.uuid
|
||||||
|
@attachment.description = params[:description]
|
||||||
|
@attachment.container_id = params[:container_id]
|
||||||
|
@attachment.container_type = params[:container_type]
|
||||||
@attachment.save!
|
@attachment.save!
|
||||||
else
|
else
|
||||||
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
||||||
|
|
|
@ -17,5 +17,6 @@
|
||||||
class ProjectDataset < ApplicationRecord
|
class ProjectDataset < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
has_many :attachments, as: :container, dependent: :destroy
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
json.id attachment.uuid
|
||||||
|
json.title attachment.title
|
||||||
|
json.description attachment.description
|
||||||
|
json.filesize number_to_human_size(attachment.filesize)
|
||||||
|
json.is_pdf attachment.is_pdf?
|
||||||
|
json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)
|
||||||
|
json.created_on attachment.created_on.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
json.content_type attachment.content_type
|
||||||
|
json.creator do
|
||||||
|
json.partial! "api/v1/users/simple_user", locals: {user: attachment.author}
|
||||||
|
end
|
|
@ -1,7 +1,8 @@
|
||||||
json.id attachment.id
|
json.id attachment.uuid
|
||||||
json.title attachment.title
|
json.title attachment.title
|
||||||
|
json.description attachment.description
|
||||||
json.filesize number_to_human_size(attachment.filesize)
|
json.filesize number_to_human_size(attachment.filesize)
|
||||||
json.is_pdf attachment.is_pdf?
|
json.is_pdf attachment.is_pdf?
|
||||||
json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)
|
json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)
|
||||||
json.created_on attachment.created_on.strftime("%Y-%m-%d %H:%M")
|
json.created_on attachment.created_on.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
json.content_type attachment.content_type
|
json.content_type attachment.content_type
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
json.(@project_dataset, :id, :title, :description)
|
||||||
|
json.attachments @attachments do |at|
|
||||||
|
json.partial! "api/v1/attachments/detail", locals: {attachment: at}
|
||||||
|
end
|
|
@ -78,6 +78,7 @@ defaults format: :json do
|
||||||
|
|
||||||
# projects文件夹下的
|
# projects文件夹下的
|
||||||
scope module: :projects do
|
scope module: :projects do
|
||||||
|
resource :dataset, only: [:create, :update, :show]
|
||||||
resources :actions, module: 'actions' do
|
resources :actions, module: 'actions' do
|
||||||
collection do
|
collection do
|
||||||
post :disable
|
post :disable
|
||||||
|
|
Loading…
Reference in New Issue