-
Notifications
You must be signed in to change notification settings - Fork 0
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
Question About the Use Cases #2
Comments
It would be more suitable to have one API to have one responsibility in general, though some may want to combine APIs and fetch data with a single API call for the sake of performance. This use case may be uncommon in real life. It would be nice if we can add more common use cases to improve the documentation. Any ideas? |
Since modern usage for people uses serializers to format different/complicated APIs (of course GraphQL already solve this problem 🥺), but we don't want to create so many serializers which can be hard to manage, I think can be a good use case for API? https://github.com/jsonapi-serializer/jsonapi-serializer class UserSerializer
include JSONAPI::Serializer
include CaseRegister
register_case(:money_info) do |object|
attribute :value { object.money }
attribute :rate { object.gain_money_rate }
end
register_case(:notification_info) do |object|
attribute :msg_count { object.new_msgs_count }
attribute :last_recieved_at { object.last_recieved_at }
end
...
...
end
# Example
render json: UserSerializer.new(@user).invoke_case(:money_info)
# Or
render json: UserSerializer.new(@user, options: { invoke_case: params[:need] }) I don't think we could do it this way, this is just a popup idea Not sure if this is a good use case lol, but just a thought 😆 |
class UserSerializer
include JSONAPI::Serializer
include CaseRegister
attribute :money
attribute :gain_money_rate
attribute :new_msgs_count
attribute :last_received_at
register_case('money_info') do
fields = @fieldsets[self.class.record_type.to_sym] ||= []
fields << :money
fields << :gain_money_rate
end
register_case('notification_info') do
fields = @fieldsets[self.class.record_type.to_sym] ||= []
fields << :new_msgs_count
fields << :last_received_at
end
end
class UsersController < ApplicationController
def show
serializer = UserSerializer.new(@user)
params[:needs].each{|need| serializer.invoke_case(need) }
render json: serializer.serializable_hash
end
end I can not tell whether it is a good design pattern or not since I do not use |
I have a question about a use case in this example
https://github.com/khiav223577/case_register#isolate-methods
Wouldn't it be more generic to have separated API to handle those cases since they actually have completely different responses 🤔, and might not need any switch case after all
Something like
The text was updated successfully, but these errors were encountered: