mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-03 19:24:48 +08:00
Update GET /inventory_items, GET /inventory_items/:id endpoints
This commit is contained in:
parent
9e78de6ef2
commit
d235dd7807
4 changed files with 23 additions and 15 deletions
|
@ -16,9 +16,10 @@ module Api
|
||||||
repository_cells: Extends::REPOSITORY_SEARCH_INCLUDES
|
repository_cells: Extends::REPOSITORY_SEARCH_INCLUDES
|
||||||
).page(params.dig(:page, :number))
|
).page(params.dig(:page, :number))
|
||||||
.per(params.dig(:page, :size))
|
.per(params.dig(:page, :size))
|
||||||
|
incl = params[:include] == 'inventory_cells' ? :inventory_cells : nil
|
||||||
render jsonapi: items,
|
render jsonapi: items,
|
||||||
each_serializer: InventoryItemSerializer,
|
each_serializer: InventoryItemSerializer,
|
||||||
include: :inventory_cells
|
include: incl
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -7,12 +7,6 @@ module Api
|
||||||
attributes :id, :value_type, :value
|
attributes :id, :value_type, :value
|
||||||
attribute :repository_column_id, key: :column_id
|
attribute :repository_column_id, key: :column_id
|
||||||
|
|
||||||
def value_type
|
|
||||||
type_id = RepositoryColumn
|
|
||||||
.data_types[object.repository_column.data_type]
|
|
||||||
I18n.t("api.v1.inventory_data_types.t#{type_id}")
|
|
||||||
end
|
|
||||||
|
|
||||||
def value
|
def value
|
||||||
value =
|
value =
|
||||||
case object.value_type
|
case object.value_type
|
||||||
|
|
|
@ -7,7 +7,8 @@ module Api
|
||||||
attributes :name
|
attributes :name
|
||||||
has_many :repository_cells, key: :inventory_cells,
|
has_many :repository_cells, key: :inventory_cells,
|
||||||
serializer: InventoryCellSerializer,
|
serializer: InventoryCellSerializer,
|
||||||
class_name: 'RepositoryCell'
|
class_name: 'RepositoryCell',
|
||||||
|
unless: -> { object.repository_cells.empty? }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,6 +75,24 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
|
||||||
include: :inventory_cells)
|
include: :inventory_cells)
|
||||||
.as_json[:data]
|
.as_json[:data]
|
||||||
)
|
)
|
||||||
|
expect(hash_body).not_to include('included')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'Response with correct inventory items, included cells' do
|
||||||
|
hash_body = nil
|
||||||
|
get api_v1_team_inventory_items_path(
|
||||||
|
team_id: @teams.first.id,
|
||||||
|
inventory_id: @teams.first.repositories.first.id,
|
||||||
|
include: 'inventory_cells'
|
||||||
|
), headers: @valid_headers
|
||||||
|
expect { hash_body = json }.not_to raise_exception
|
||||||
|
expect(hash_body[:data]).to match(
|
||||||
|
ActiveModelSerializers::SerializableResource
|
||||||
|
.new(@valid_inventory.repository_rows.limit(10),
|
||||||
|
each_serializer: Api::V1::InventoryItemSerializer,
|
||||||
|
include: :inventory_cells)
|
||||||
|
.as_json[:data]
|
||||||
|
)
|
||||||
expect(hash_body[:included]).to match(
|
expect(hash_body[:included]).to match(
|
||||||
ActiveModelSerializers::SerializableResource
|
ActiveModelSerializers::SerializableResource
|
||||||
.new(@valid_inventory.repository_rows.limit(10),
|
.new(@valid_inventory.repository_rows.limit(10),
|
||||||
|
@ -98,13 +116,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
|
||||||
include: :inventory_cells)
|
include: :inventory_cells)
|
||||||
.as_json[:data]
|
.as_json[:data]
|
||||||
)
|
)
|
||||||
expect(hash_body[:included]).to match(
|
expect(hash_body).not_to include('included')
|
||||||
ActiveModelSerializers::SerializableResource
|
|
||||||
.new(@valid_inventory.repository_rows.limit(100),
|
|
||||||
each_serializer: Api::V1::InventoryItemSerializer,
|
|
||||||
include: :inventory_cells)
|
|
||||||
.as_json[:included]
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'When invalid request, user in not member of the team' do
|
it 'When invalid request, user in not member of the team' do
|
||||||
|
|
Loading…
Reference in a new issue