You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Acfs is for resource oriented access on services. So I would prefer you create a resource representing your sum (or multiple stats about one person) in the source service. Not all resources must be database models.
I would create a resource Statistic in the service providing Person with fields for your summed age:
MyService::Statistic.find1do |stats| # Would be nice to have singleton resourcesputsstats.accumulated_ageend
This allows you to implement the business logic in your service. It would be easy to change the algorithm, cache results etc. without changing the caller app. My thumb rule is: "If it contains an operator (+) it's business logic and must be implemented in the service (and represented as a resource)."
As I commented above it would be nice to have singleton resources (GET /resource instead of GET /resources/:id) as the statistic resource should be singleton and only exists at one place. I will add this to feature list but you can emulate this by choosing a fix id.
I would like to sum up an attribute of all entries in a table.
e.g.: the age of all persons in a database.
normal approach: Person.sum('age')
ACFS apprach:
sum = 0
Person.all do | person |
sum = sum + person.age
end
Acfs.run
Is it possible to have a better way for that?
The text was updated successfully, but these errors were encountered: