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 an API v2 endpoint for PooledPlateCreations #4355

Merged
12 changes: 12 additions & 0 deletions app/controllers/api/v2/pooled_plate_creations_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 Pooled Plate Creations
# See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation
class PooledPlateCreationsController < JSONAPI::ResourceController
# By default JSONAPI::ResourceController provides most the standard
# behaviour, and in many cases this file may be left empty.
end
end
end
4 changes: 2 additions & 2 deletions app/models/plate_creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PlateCreation < AssetCreation

# This is the child that is created from the parent. It cannot be assigned before validation.
belongs_to :parent, class_name: 'Plate'
attr_accessor :barcode
attr_accessor :sanger_barcode

def record_creation_of_children
parent.events.create_plate!(child_purpose, child, user)
Expand Down Expand Up @@ -34,7 +34,7 @@ def children
private :children

def create_children!
self.child = child_purpose.create!(barcode: barcode)
self.child = child_purpose.create!(sanger_barcode: sanger_barcode)
end
private :create_children!
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/pooled_plate_creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Creating an instance of this class causes a child plate, with the specified plate type, to be created from
# the parent.
class PooledPlateCreation < AssetCreation
attr_accessor :barcode
attr_accessor :sanger_barcode

has_many :parent_associations, foreign_key: 'asset_creation_id', class_name: 'AssetCreation::ParentAssociation'

Expand Down
93 changes: 93 additions & 0 deletions app/resources/api/v2/pooled_plate_creation_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# frozen_string_literal: true

module Api
module V2
# @todo This documentation does not yet include a detailed description of what this resource represents.
# @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters.
# @todo This documentation does not yet include any example usage of the API via cURL or similar.
#
# @note This resource cannot be modified after creation: its endpoint will not accept `PATCH` requests.
# @note Access this resource via the `/api/v2/pooled_plate_creation/` endpoint.
#
# Provides a JSON:API representation of {PooledPlateCreation}.
#
# 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 PooledPlateCreationResource < BaseResource
###
# Attributes
###

# @!attribute [w] child_purpose_uuid
# @param value [String] The UUID of a child purpose to use in the creation of the child plate.
# @return [Void]
attribute :child_purpose_uuid

def child_purpose_uuid=(value)
@model.child_purpose = Purpose.with_uuid(value).first
end

# @!attribute [w] parent_uuids
# This is declared for convenience where parents are not available to set as a relationship.
# Setting this attribute alongside the `parents` relationship will prefer the relationship value.
# @deprecated Use the `parents` relationship instead.
# @param value [Array<String>] The UUIDs of labware that will be the parents for the created plate.
# @return [Void]
# @see #parents
attribute :parent_uuids

def parent_uuids=(value)
@model.parents = value.map { |uuid| Labware.with_uuid(uuid).first }
end

# @!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 this pooled plate.
# @return [Void]
# @see #user
attribute :user_uuid

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

# @!attribute [r] uuid
# @return [String] The UUID of the state change.
attribute :uuid, readonly: true

###
# Relationships
###

# @!attribute [r] child
# @return [PlateResource] The child plate which was created.
has_one :child, class_name: 'Plate'

# @!attribute [rw] parents
# Setting this relationship alongside the `parent_uuids` attribute will override the attribute value.
# @return [Array<LabwareResource>] An array of the parents of the plate being created.
# @note This relationship is required.
has_many :parents, class_name: 'Labware'

# @!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 pooled plate.
# @note This relationship is required.
has_one :user

def self.creatable_fields(context)
# UUID is set by the system.
super - %i[uuid]
end

def fetchable_fields
# The tube_attributes attribute is only available during resource creation.
# UUIDs for relationships are not fetchable. They should be accessed via the relationship itself.
super - %i[child_purpose_uuid parent_uuids user_uuid]
end
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
jsonapi_resources :plate_templates
jsonapi_resources :plates
jsonapi_resources :poly_metadata
jsonapi_resources :pooled_plate_creations, except: %i[update]
jsonapi_resources :pre_capture_pools
jsonapi_resources :primer_panels
jsonapi_resources :projects
Expand Down
2 changes: 1 addition & 1 deletion features/api/plate_creations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: Access plate creations through the API
And the WTSI single sign-on service recognises "I-am-authenticated" as "John Smith"

Given I am using the latest version of the API
And I have a "full" authorised user with the key "cucumber"
And I have a "full" authorised user with the key "cucumber"

Given a user with UUID "99999999-8888-7777-6666-555555555555" exists

Expand Down
12 changes: 12 additions & 0 deletions spec/factories/pooled_plate_creation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

FactoryBot.define do
factory :pooled_plate_creation do
# Without this, create_children! tries to go to Baracoda for a barcode.
sanger_barcode { create(:plate_barcode) }

child_purpose { |target| target.association(:plate_purpose) }
parents { |target| [target.association(:plate), target.association(:tube)] }
user { |target| target.association(:user) }
end
end
2 changes: 1 addition & 1 deletion spec/factories/pulldown_factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

factory(:plate_creation) do
user
barcode { create(:sequencescape22).barcode }
sanger_barcode { create(:sequencescape22) }
parent factory: %i[full_plate], well_count: 2
child_purpose factory: %i[plate_purpose]

Expand Down
Loading
Loading