mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 18:21:50 +08:00
Fix READ index, READ show, POST create /tasks/:id/results endpoints
This commit is contained in:
parent
fc5cf33614
commit
7527dc7352
6 changed files with 51 additions and 22 deletions
|
@ -14,7 +14,7 @@ module Api
|
|||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: results, each_serializer: ResultSerializer,
|
||||
include: %i(asset table text)
|
||||
include: %i(text table file)
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -22,13 +22,13 @@ module Api
|
|||
throw ActionController::ParameterMissing unless @result
|
||||
render jsonapi: @result,
|
||||
serializer: ResultSerializer,
|
||||
include: %i(asset table text),
|
||||
include: %i(text table file),
|
||||
status: :created
|
||||
end
|
||||
|
||||
def show
|
||||
render jsonapi: @result, serializer: ResultSerializer,
|
||||
include: %i(asset table text)
|
||||
include: %i(text table file)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -23,8 +23,9 @@ module Api
|
|||
elsif object.asset&.file&.is_stored_on_s3?
|
||||
object.asset.presigned_url(download: true)
|
||||
else
|
||||
# TODO
|
||||
# separate api endpoint for local files download is needed
|
||||
download_asset_path(object.asset.id)
|
||||
'url'#download_asset_path(object.asset.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,8 +3,32 @@
|
|||
module Api
|
||||
module V1
|
||||
class ResultAssetSerializer < ActiveModel::Serializer
|
||||
type :result_assets
|
||||
attributes :asset_id
|
||||
type :result_files
|
||||
attributes :file_id, :file_name, :file_size, :url
|
||||
|
||||
def file_id
|
||||
object.asset&.id
|
||||
end
|
||||
|
||||
def file_name
|
||||
object.asset&.file_file_name
|
||||
end
|
||||
|
||||
def file_size
|
||||
object.asset&.file_file_size
|
||||
end
|
||||
|
||||
def url
|
||||
if !object.asset&.file_present
|
||||
nil
|
||||
elsif object.asset&.file&.is_stored_on_s3?
|
||||
object.asset.presigned_url(download: true)
|
||||
else
|
||||
# TODO
|
||||
# separate api endpoint for local files download is needed
|
||||
'url'#download_asset_path(object.asset.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,22 +4,20 @@ module Api
|
|||
module V1
|
||||
class ResultSerializer < ActiveModel::Serializer
|
||||
type :results
|
||||
attributes :name, :user_id, :archived
|
||||
attribute :my_module_id, key: :task_id
|
||||
|
||||
belongs_to :my_module, serializer: TaskSerializer
|
||||
has_one :result_asset, key: :asset,
|
||||
serializer: ResultAssetSerializer,
|
||||
class_name: 'ResultAsset',
|
||||
if: -> { object.is_asset }
|
||||
has_one :result_table, key: :table,
|
||||
serializer: ResultTableSerializer,
|
||||
class_name: 'ResultTable',
|
||||
if: -> { object.is_table }
|
||||
attributes :name, :archived
|
||||
belongs_to :user, serializer: UserSerializer
|
||||
has_one :result_text, key: :text,
|
||||
serializer: ResultTextSerializer,
|
||||
class_name: 'ResultText',
|
||||
if: -> { object.is_text }
|
||||
has_one :result_table, key: :table,
|
||||
serializer: ResultTableSerializer,
|
||||
class_name: 'ResultTable',
|
||||
if: -> { object.is_table }
|
||||
has_one :result_asset, key: :file,
|
||||
serializer: ResultAssetSerializer,
|
||||
class_name: 'ResultAsset',
|
||||
if: -> { object.is_asset }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,15 @@ module Api
|
|||
module V1
|
||||
class ResultTableSerializer < ActiveModel::Serializer
|
||||
type :result_tables
|
||||
attributes :table_id
|
||||
attributes :table_id, :table_contents
|
||||
|
||||
def table_id
|
||||
object.table&.id
|
||||
end
|
||||
|
||||
def table_contents
|
||||
object.table&.contents
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -576,9 +576,7 @@ Rails.application.routes.draw do
|
|||
path: 'tags',
|
||||
as: :tags
|
||||
resources :protocols, only: %i(index show)
|
||||
resources :results, only: %i(index create show),
|
||||
path: 'results',
|
||||
as: :results
|
||||
resources :results, only: %i(index create show)
|
||||
get 'inputs', to: 'tasks#inputs'
|
||||
get 'outputs', to: 'tasks#outputs'
|
||||
get 'activities', to: 'tasks#activities'
|
||||
|
|
Loading…
Reference in a new issue