Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Y24-190-3: Support Limber with BulkTransfers on v2 API #4425

Open
wants to merge 15 commits into
base: develop-Y24-190
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ RSpec/MultipleMemoizedHelpers:
- 'spec/models/tube_rack_spec.rb'
- 'spec/models/work_completion_spec.rb'
- 'spec/requests/api/v2/bait_library_layouts_spec.rb'
- 'spec/requests/api/v2/bulk_transfers_spec.rb'
- 'spec/requests/api/v2/custom_metadatum_collections_spec.rb'
- 'spec/requests/api/v2/heron/plates_spec.rb'
- 'spec/requests/api/v2/heron/tube_racks_spec.rb'
Expand Down Expand Up @@ -1424,6 +1425,7 @@ RSpec/NestedGroups:
- 'spec/models/tube_rack_spec.rb'
- 'spec/models/well_spec.rb'
- 'spec/requests/api/v2/bait_library_layouts_spec.rb'
- 'spec/requests/api/v2/bulk_transfers_spec.rb'
- 'spec/requests/api/v2/custom_metadatum_collections_spec.rb'
- 'spec/requests/api/v2/heron/plates_spec.rb'
- 'spec/requests/api/v2/heron/tube_racks_spec.rb'
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/api/v2/bulk_transfers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Api
module V2
# Provides a JSON API controller for Bulk Transfers.
# See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation.
class BulkTransfersController < JSONAPI::ResourceController
# By default JSONAPI::ResourceController provides most the standard
# behaviour, and in many cases this file may be left empty.
end
end
end
6 changes: 3 additions & 3 deletions app/models/bulk_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# of individual transfers. Designed for use via the API
#
# @example Example usage
# BultTransfer.create!({
# BulkTransfer.create!({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well caught

# well_transfers: [
# {
# source_uuid: source_plate1.uuid, source_location: 'A1',
Expand Down Expand Up @@ -39,6 +39,8 @@ class BulkTransfer < ApplicationRecord

attr_accessor :well_transfers

private

def build_transfers!
ActiveRecord::Base.transaction do
each_transfer do |source, destination, transfers|
Expand All @@ -52,7 +54,6 @@ def build_transfers!
end
end
end
private :build_transfers!

def each_transfer # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
well_transfers
Expand All @@ -70,5 +71,4 @@ def each_transfer # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
yield(source, destination, transfers)
end
end
private :each_transfer
end
106 changes: 106 additions & 0 deletions app/resources/api/v2/bulk_transfer_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# frozen_string_literal: true

module Api
module V2
# Provides a JSON:API representation of {BulkTransfer} which allows the transfer of multiple wells from source
# plates to destination plates. The plates and wells to transfer are specified in the {#well_transfers} attribute.
# Creation of this resource via a `POST` request will perform the specified transfers.
# After creation, the transfers can be accessed via the {#transfers} relationship.
#
# @note This resource cannot be modified after creation: its endpoint will not accept `PATCH` requests.
# @note Access this resource via the `/api/v2/bulk_transfers/` endpoint.
#
# @example POST request
# POST /api/v2/bulk_transfers/
# {
# "data": {
# "type": "bulk_transfers",
# "attributes": {
# "well_transfers": [
# {
# "source_uuid": "src_plate1_uuid",
# "source_location": "A1",
# "destination_uuid": "dest_plate1_uuid",
# "destination_location": "A1"
# },
# {
# "source_uuid": "src_plate1_uuid",
# "source_location": "B1",
# "destination_uuid": "dest_plate2_uuid",
# "destination_location": "A1"
# },
# {
# "source_uuid": "src_plate2_uuid",
# "source_location": "A1",
# "destination_uuid": "dest_plate1_uuid",
# "destination_location": "B1"
# },
# {
# "source_uuid": "src_plate2_uuid",
# "source_location": "B1",
# "destination_uuid": "dest_plate2_uuid",
# "destination_location": "B1"
# }
# ],
# "user_uuid": "user_uuid"
# }
# }
# }
#
# @example GET request for all BulkTransfer resources
# GET /api/v2/bulk_transfers/
#
# @example GET request for a BulkTransfer with ID 123
# GET /api/v2/bulk_transfers/123/
#
# For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/)
# or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation
# of the JSON:API standard.
class BulkTransferResource < BaseResource
###
# Attributes
###

# @!attribute [w] user_uuid
# This is declared for convenience where the user is not available to set as a relationship.
# Setting this attribute alongside the `user` relationship will prefer the relationship value.
# @deprecated Use the `user` relationship instead.
# @param value [String] The UUID of the user who initiated the creation of the bulk transfers.
# @return [Void]
# @see #user
attribute :user_uuid, writeonly: true

def user_uuid=(value)
@model.user = User.with_uuid(value).first
end

# @!attribute [r] uuid
# @return [String] The UUID of the bulk transfers operation.
attribute :uuid, readonly: true

# @!attribute [w] well_transfers
# An array of well transfers to perform. Each transfer is a hash with the following:
# - `source_uuid` [String] The UUID of the source plate.
# - `source_location` [String] The location on the source plate.
# - `destination_uuid` [String] The UUID of the destination plate.
# - `destination_location` [String] The location on the destination plate.
# @return [Void]
attribute :well_transfers, writeonly: true

###
# Relationships
###

# @!attribute [r] transfers
# The transfers that were created as a result of this bulk transfer.
# @return [Array<TransferResource>] An array of created transfers.
has_many :transfers, readonly: true

# @!attribute [rw] user
# Setting this relationship alongside the `user_uuid` attribute will override the attribute value.
# @return [UserResource] The user who initiated the creation of the bulk transfers.
# @note This relationship is required.
has_one :user
end
end
end
14 changes: 7 additions & 7 deletions app/resources/api/v2/tube_from_tube_creation_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ module V2
# The created child will have the specified purpose and can be accessed via the {#child} relationship.
#
# @note This resource cannot be modified after creation: its endpoint will not accept `PATCH` requests.
# @note Access this resource via the `/api/v2/tube_from_tube_creation/` endpoint.
# @note Access this resource via the `/api/v2/tube_from_tube_creations/` endpoint.
#
# @example POST request with child purpose and parent tube specified by UUID (deprecated)
# POST /api/v2/tube_from_tube_creation/
# POST /api/v2/tube_from_tube_creations/
# {
# "data": {
# "type": "tube_from_tube_creation",
# "type": "tube_from_tube_creations",
# "attributes": {
# "child_purpose_uuid": "11111111-2222-3333-4444-555555666666",
# "parent_uuid": "33333333-4444-5555-6666-777777888888",
Expand All @@ -24,10 +24,10 @@ module V2
# }
#
# @example POST request with child purpose and parent tube specified by relationship
# POST /api/v2/tube_from_tube_creation/
# POST /api/v2/tube_from_tube_creations/
# {
# "data": {
# "type": "tube_from_tube_creation",
# "type": "tube_from_tube_creations",
# "attributes": {},
# "relationships": {
# "child_purpose": {
Expand All @@ -44,10 +44,10 @@ module V2
# }
#
# @example GET request for all TubeFromTubeCreation resources
# GET /api/v2/tube_from_tube_creation/
# GET /api/v2/tube_from_tube_creations/
#
# @example GET request for a TubeFromTubeCreation with ID 123
# GET /api/v2/tube_from_tube_creation/123/
# GET /api/v2/tube_from_tube_creations/123/
#
# For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/)
# or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
end

jsonapi_resources :barcode_printers
jsonapi_resources :bulk_transfers, except: %i[update]
jsonapi_resources :comments
jsonapi_resources :custom_metadatum_collections
jsonapi_resources :labware
Expand Down
40 changes: 40 additions & 0 deletions spec/factories/bulk_transfers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

FactoryBot.define do
factory :bulk_transfer do
transient do
source_plates { create_list(:plate, 2) }
destination_plates { create_list(:plate, 2) }
end

user
well_transfers do
[
{
'source_uuid' => source_plates[0].uuid,
'source_location' => 'A1',
'destination_uuid' => destination_plates[0].uuid,
'destination_location' => 'A1'
},
{
'source_uuid' => source_plates[0].uuid,
'source_location' => 'B1',
'destination_uuid' => destination_plates[1].uuid,
'destination_location' => 'A1'
},
{
'source_uuid' => source_plates[1].uuid,
'source_location' => 'A1',
'destination_uuid' => destination_plates[0].uuid,
'destination_location' => 'B1'
},
{
'source_uuid' => source_plates[1].uuid,
'source_location' => 'B1',
'destination_uuid' => destination_plates[1].uuid,
'destination_location' => 'B1'
}
]
end
end
end
Loading
Loading