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-2: Support Limber labware metadata in API v2 #4268

Merged
Merged
1 change: 0 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,6 @@ RSpec/NamedSubject:
- 'spec/models/work_order_spec.rb'
- 'spec/resources/api/v2/aliquot_resource_spec.rb'
- 'spec/resources/api/v2/comment_resource_spec.rb'
- 'spec/resources/api/v2/custom_metadatum_collection_resource_spec.rb'
- 'spec/resources/api/v2/lane_resource_spec.rb'
- 'spec/resources/api/v2/lot_resource_spec.rb'
- 'spec/resources/api/v2/lot_type_resource_spec.rb'
Expand Down
42 changes: 26 additions & 16 deletions app/resources/api/v2/custom_metadatum_collection_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,41 @@ module V2
# Provides a JSON API representation of custom_metadatum_collection
# See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation
class CustomMetadatumCollectionResource < BaseResource
# Constants...

# immutable # uncomment to make the resource immutable

# model_name / model_hint if required

default_includes :uuid_object, :custom_metadata

# Associations:

###
# Attributes
attribute :uuid, readonly: true
attribute :metadata
###

# This is required for POST
# @!attribute [r] uuid
# @return [String] The UUID of the collection.
attribute :uuid
BenTopping marked this conversation as resolved.
Show resolved Hide resolved

# @!attribute [rw] user_id
# @return [Int] The ID of the user who created this collection. Can only and must be set on creation.
attribute :user_id

# @!attribute [rw] asset_id
# @return [Int] The ID of the labware the metadata corresponds to. Can only and must be set on creation.
attribute :asset_id

# Filters
# @!attribute [rw] metadata
# @return [Hash] All metadata in this collection.
attribute :metadata

###
# Allowable fields (defining read/write permissions for POST and PATCH)
###

# Custom methods
# These shouldn't be used for business logic, and a more about
# I/O and isolating implementation details.
# @return [Array<Symbol>] Fields that can be created in a POST request.
def self.creatable_fields(context)
super - %i[uuid]
end

# Class method overrides
# @return [Array<Symbol>] Fields that can be updated in a PATCH request.
def self.updatable_fields(context)
super - %i[uuid user_id asset_id] # PATCH should only update metadata
end
end
end
end
32 changes: 25 additions & 7 deletions app/resources/api/v2/user_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,40 @@ module V2
# Provides a JSON API representation of user
# See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation
class UserResource < BaseResource
# Constants...

immutable # comment to make the resource mutable

# model_name / model_hint if required

default_includes :uuid_object
immutable

###
# Attributes
###

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

# @!attribute [r] login
# @return [String] the user's login identifier.
attribute :login, readonly: true

# @!attribute [r] first_name
# @return [String] the user's first/given name.
attribute :first_name, readonly: true

# @!attribute [r] last_name
# @return [String] the user's last/surname.
attribute :last_name, readonly: true

###
# Filters
###

# @!method user_code
# A filter to return only users with the given user code.
# The given user code will be compared with the swipecodes and barcodes for users until matches are found.
filter :user_code, apply: lambda { |records, value, _options| records.with_user_code(*value) }

# @!method uuid
# A filter to return only users with the given UUID.
filter :uuid, apply: lambda { |records, value, _options| records.with_uuid(*value) }
end
end
end
3 changes: 2 additions & 1 deletion lib/tasks/devour.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
# We prettify are json to make it both easier to read and diff
json_formatting = { indent: ' ', object_nl: "\n", space: ' ', array_nl: "\n" }

non_resource_symbols = %i[BaseResource Concerns SharedBehaviour]

Check warning on line 9 in lib/tasks/devour.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/devour.rake#L9

Added line #L9 was not covered by tests
config =
Api::V2
.constants
.reject { |resource_key| resource_key == :BaseResource }
.reject { |resource_key| non_resource_symbols.include?(resource_key) }

Check warning on line 13 in lib/tasks/devour.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/devour.rake#L13

Added line #L13 was not covered by tests
.sort
.map do |resource_key|
resource = Api::V2.const_get(resource_key)
Expand Down
Loading
Loading