Merge branch 'features/api-improvements' into ma_SCI_11768

This commit is contained in:
Martin Artnik 2025-04-08 10:13:14 +02:00 committed by GitHub
commit 7cb1fb487d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 23 additions and 11 deletions

View file

@ -29,8 +29,7 @@ gem 'omniauth-rails_csrf_protection', '~> 1.0'
gem 'omniauth-saml'
# Gems for API implementation
gem 'active_model_serializers', '~> 0.10.7'
gem 'jsonapi-renderer', '~> 0.2.2'
gem 'active_model_serializers', '~> 0.10.15'
gem 'json-jwt'
gem 'jwt', '~> 1.5'
gem 'kaminari'

View file

@ -88,7 +88,7 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 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)
activemodel (>= 4.1)
case_transform (>= 0.2)
@ -768,7 +768,7 @@ PLATFORMS
x86_64-linux
DEPENDENCIES
active_model_serializers (~> 0.10.7)
active_model_serializers (~> 0.10.15)
activerecord-import
activerecord-session_store
acts_as_list
@ -817,7 +817,6 @@ DEPENDENCIES
jsbundling-rails
json-jwt
json_matchers
jsonapi-renderer (~> 0.2.2)
jwt (~> 1.5)
kaminari
listen

View file

@ -141,7 +141,7 @@ module Api
end
def permitted_includes
%w(inventory_cells)
%w(inventory_cells parents children)
end
end
end

View file

@ -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

View file

@ -13,6 +13,10 @@ module Api
serializer: InventorySerializer,
class_name: '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
end

View file

@ -44,6 +44,8 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
{ repository_row: row, repository_column: file_column })
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 =
{ '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(
team_id: @team1.id,
inventory_id: @team1.repositories.first.id,
include: 'inventory_cells'
include: 'inventory_cells,parents,children'
), headers: @valid_headers
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match_array(
@ -105,7 +107,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
ActiveModelSerializers::SerializableResource
.new(@valid_inventory.repository_rows.order(:id).limit(10),
each_serializer: Api::V1::InventoryItemSerializer,
include: :inventory_cells)
include: %w(inventory_cells parents children))
.to_json
)['included']
)
@ -121,9 +123,8 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
expect(hash_body[:data]).to match_array(
JSON.parse(
ActiveModelSerializers::SerializableResource
.new(@valid_inventory.repository_rows.limit(100),
each_serializer: Api::V1::InventoryItemSerializer,
include: :inventory_cells)
.new(@valid_inventory.repository_rows.order(:id).limit(100),
each_serializer: Api::V1::InventoryItemSerializer)
.to_json
)['data']
)