-
Notifications
You must be signed in to change notification settings - Fork 66
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
Issue# 98709 & 98710 POA Request List and Detail endpoints #19967
base: master
Are you sure you want to change the base?
Conversation
- Implement PowerOfAttorneyRequestSerializer to handle resolution attributes: - Includes `id`, `type`, `created_at`, `reason`, and conditional `creator_id` - Ensure safe handling of nil values with safe navigation (`&.`) and `try` - Add RSpec tests to validate: - Resolution serialization for decisions, expirations, and declinations - Handling of `reason` and `creator_id` conditionally - Nil resolution scenarios
- Implement `PowerOfAttorneyRequestSerializer` to standardize JSON:API output - Add request specs for controller endpoints (`index` and `show`) - Add serializer specs to ensure proper formatting of resolution details - Normalize response keys for consistency in test expectations
Generated by 🚫 Danger |
ecf8aa3
to
fe03d67
Compare
…h specs - Implement `PowerOfAttorneyRequestSerializer` to handle serialization of power of attorney requests, including nested resolution data. - Implement `PowerOfAttorneyRequestResolutionSerializer` to serialize resolution details, accommodating various resolution subtypes. - Add comprehensive specs for both serializers to ensure accurate and dynamic handling of attributes. - Adjust model factories accordingly
fe03d67
to
c7eebf8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes to serializer definitions and queries.
def index | ||
render json: POA_REQUEST_LIST_MOCK_DATA | ||
poa_requests = PowerOfAttorneyRequest.includes(:resolution) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add .limit(100)
just in case.
def index | ||
render json: POA_REQUEST_LIST_MOCK_DATA | ||
poa_requests = PowerOfAttorneyRequest.includes(:resolution) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where we want to includes the rest of the object graph to not have N+1 query like the original proof of concept spec shows. So maybe this becomes includes(resolution: :resolving)
?
end | ||
|
||
def show | ||
render json: POA_REQUEST_ITEM_MOCK_DATA | ||
poa_request = PowerOfAttorneyRequest.includes(:resolution).find(params[:id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where we want to includes the rest of the object graph to not have N+1 query like the original proof of concept spec shows. So maybe this becomes includes(resolution: :resolving)
?
attribute :created_at do |object| | ||
object.created_at.iso8601 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How was this getting serialized without the custom attribute?
attribute :resolution do |object| | ||
next nil if object.resolution.blank? | ||
|
||
AccreditedRepresentativePortal::PowerOfAttorneyRequestResolutionSerializer.new( | ||
object.resolution | ||
).serializable_hash[:data][:attributes] | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use a relationship serializer? In fact it looks like we want to follow their example here for polymorphism:
class MovieSerializer
include JSONAPI::Serializer
has_many :actors, serializer: Proc.new do |record, params|
if record.comedian?
ComedianSerializer
elsif params[:use_drama_serializer]
DramaSerializer
else
ActorSerializer
end
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't control the structure that way. The result isn't flat like how we want it to be (they get placed under "relationships"). And there doesn't seem to be a way to override the default serialization when using relationships.
# frozen_string_literal: true | ||
|
||
module AccreditedRepresentativePortal | ||
class PowerOfAttorneyRequestResolutionSerializer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow the library's guide for polymorphic relationship instead.
object.resolving.type | ||
end | ||
|
||
attribute :reason |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason will only need to be serialized on a declination in the decision serializer variant.
attribute :created_at do |object| | ||
object.created_at.iso8601 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How was this serializing without the custom attribute?
attribute :type do |object| | ||
object.resolving_type.demodulize.underscore.split('_').last | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we have the polymorphic variants, each of them can hardcode this rather than manipulate the name of the Ruby class. In the end we should get: "type": "decision"
and "type": "expiration"
.
…ved query performance - Updated `includes` to reference `resolving` instead of just `resolution` - Added a limit of 100 records in the `index` action to optimize data retrieval
This PR implements the list and detail endpoints of POA Request API:
Serializer:
• Created PowerOfAttorneyRequestSerializer and PowerOfAttorneyRequestResolutionSerializer to format the JSON output in JSON:API standard.
• Includes flattened resolution details
Controller:
• Added PowerOfAttorneyRequestsController with index and show actions.
Specs:
• Added request specs to verify:
• GET /power_of_attorney_requests returns a list of requests.
• GET /power_of_attorney_requests/:id returns the details of a specific request.
• Added serializer specs to ensure accurate formatting of response data: