mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-08 04:47:22 +08:00
Merge branch 'features/api-improvements' into ma_SCI_11768
This commit is contained in:
commit
7cb1fb487d
6 changed files with 23 additions and 11 deletions
3
Gemfile
3
Gemfile
|
@ -29,8 +29,7 @@ gem 'omniauth-rails_csrf_protection', '~> 1.0'
|
||||||
gem 'omniauth-saml'
|
gem 'omniauth-saml'
|
||||||
|
|
||||||
# Gems for API implementation
|
# Gems for API implementation
|
||||||
gem 'active_model_serializers', '~> 0.10.7'
|
gem 'active_model_serializers', '~> 0.10.15'
|
||||||
gem 'jsonapi-renderer', '~> 0.2.2'
|
|
||||||
gem 'json-jwt'
|
gem 'json-jwt'
|
||||||
gem 'jwt', '~> 1.5'
|
gem 'jwt', '~> 1.5'
|
||||||
gem 'kaminari'
|
gem 'kaminari'
|
||||||
|
|
|
@ -88,7 +88,7 @@ GEM
|
||||||
erubi (~> 1.4)
|
erubi (~> 1.4)
|
||||||
rails-dom-testing (~> 2.0)
|
rails-dom-testing (~> 2.0)
|
||||||
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
||||||
active_model_serializers (0.10.14)
|
active_model_serializers (0.10.15)
|
||||||
actionpack (>= 4.1)
|
actionpack (>= 4.1)
|
||||||
activemodel (>= 4.1)
|
activemodel (>= 4.1)
|
||||||
case_transform (>= 0.2)
|
case_transform (>= 0.2)
|
||||||
|
@ -768,7 +768,7 @@ PLATFORMS
|
||||||
x86_64-linux
|
x86_64-linux
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
active_model_serializers (~> 0.10.7)
|
active_model_serializers (~> 0.10.15)
|
||||||
activerecord-import
|
activerecord-import
|
||||||
activerecord-session_store
|
activerecord-session_store
|
||||||
acts_as_list
|
acts_as_list
|
||||||
|
@ -817,7 +817,6 @@ DEPENDENCIES
|
||||||
jsbundling-rails
|
jsbundling-rails
|
||||||
json-jwt
|
json-jwt
|
||||||
json_matchers
|
json_matchers
|
||||||
jsonapi-renderer (~> 0.2.2)
|
|
||||||
jwt (~> 1.5)
|
jwt (~> 1.5)
|
||||||
kaminari
|
kaminari
|
||||||
listen
|
listen
|
||||||
|
|
|
@ -141,7 +141,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def permitted_includes
|
def permitted_includes
|
||||||
%w(inventory_cells)
|
%w(inventory_cells parents children)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Api
|
||||||
|
module V1
|
||||||
|
class ConnectedInventoryItemSerializer < InventoryItemSerializer
|
||||||
|
belongs_to :repository, key: :inventory, serializer: InventorySerializer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -13,6 +13,10 @@ module Api
|
||||||
serializer: InventorySerializer,
|
serializer: InventorySerializer,
|
||||||
class_name: 'Repository',
|
class_name: 'Repository',
|
||||||
if: -> { instance_options[:show_repository] }
|
if: -> { instance_options[:show_repository] }
|
||||||
|
has_many :parent_repository_rows, key: :parents,
|
||||||
|
serializer: Api::V1::ConnectedInventoryItemSerializer
|
||||||
|
has_many :child_repository_rows, key: :children,
|
||||||
|
serializer: Api::V1::ConnectedInventoryItemSerializer
|
||||||
|
|
||||||
include TimestampableModel
|
include TimestampableModel
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,6 +44,8 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
|
||||||
{ repository_row: row, repository_column: file_column })
|
{ repository_row: row, repository_column: file_column })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@child_inventory_item = create(:repository_row, repository: @valid_inventory, created_by: @user)
|
||||||
|
@child_connection = create(:repository_row_connection, parent: @valid_inventory.repository_rows.first, child: @child_inventory_item, created_by: @user)
|
||||||
|
|
||||||
@valid_headers =
|
@valid_headers =
|
||||||
{ 'Authorization': 'Bearer ' + generate_token(@user.id),
|
{ 'Authorization': 'Bearer ' + generate_token(@user.id),
|
||||||
|
@ -88,7 +90,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
|
||||||
get api_v1_team_inventory_items_path(
|
get api_v1_team_inventory_items_path(
|
||||||
team_id: @team1.id,
|
team_id: @team1.id,
|
||||||
inventory_id: @team1.repositories.first.id,
|
inventory_id: @team1.repositories.first.id,
|
||||||
include: 'inventory_cells'
|
include: 'inventory_cells,parents,children'
|
||||||
), headers: @valid_headers
|
), headers: @valid_headers
|
||||||
expect { hash_body = json }.not_to raise_exception
|
expect { hash_body = json }.not_to raise_exception
|
||||||
expect(hash_body[:data]).to match_array(
|
expect(hash_body[:data]).to match_array(
|
||||||
|
@ -105,7 +107,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
|
||||||
ActiveModelSerializers::SerializableResource
|
ActiveModelSerializers::SerializableResource
|
||||||
.new(@valid_inventory.repository_rows.order(:id).limit(10),
|
.new(@valid_inventory.repository_rows.order(:id).limit(10),
|
||||||
each_serializer: Api::V1::InventoryItemSerializer,
|
each_serializer: Api::V1::InventoryItemSerializer,
|
||||||
include: :inventory_cells)
|
include: %w(inventory_cells parents children))
|
||||||
.to_json
|
.to_json
|
||||||
)['included']
|
)['included']
|
||||||
)
|
)
|
||||||
|
@ -121,9 +123,8 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
|
||||||
expect(hash_body[:data]).to match_array(
|
expect(hash_body[:data]).to match_array(
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
ActiveModelSerializers::SerializableResource
|
ActiveModelSerializers::SerializableResource
|
||||||
.new(@valid_inventory.repository_rows.limit(100),
|
.new(@valid_inventory.repository_rows.order(:id).limit(100),
|
||||||
each_serializer: Api::V1::InventoryItemSerializer,
|
each_serializer: Api::V1::InventoryItemSerializer)
|
||||||
include: :inventory_cells)
|
|
||||||
.to_json
|
.to_json
|
||||||
)['data']
|
)['data']
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue