Refactor `User#follow` into a service
Why are we doing this work
As a follow-up for !97349 (comment 1104027190) and !97349 (comment 1104027193),
we should refactor User#follow
into a service. There are multiple benefits for this:
- We have more flexibility with error handling, as we no longer have to rely on
ActiveModel#errors
to hold error messages. - We can associate an HTTP status code with each error
- We have better separation of concerns as we
User
shouldn't be concerned with creatingUserFollowUser
records
Implementation plan
- Create
app/services/users/follow_service.rb
- Move the logic from
User#follow
into this service - Delete
User#follow
- Replace usages of
User#follow
withUsers::FollowService
Edited by Christina Lohr