mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 08:17:56 +08:00
DEV: Drop WithServiceHelper
This patch removes the `with_service` helper from the code base. Instead, we can pass a block with actions directly to the `.call` method of a service. This simplifies how to use services: - use `.call` without a block to run the service and get its result object. - use `.call` with a block of actions to run the service and execute arbitrary code depending on the service outcome. It also means a service is now “self-contained” and can be used anywhere without having to include a helper or whatever.
This commit is contained in:

committed by
Loïc Guitaut

parent
c76ff5c994
commit
e94707acdf
@ -2,7 +2,7 @@
|
||||
|
||||
class Admin::Config::FlagsController < Admin::AdminController
|
||||
def toggle
|
||||
with_service(Flags::ToggleFlag) do
|
||||
Flags::ToggleFlag.call do
|
||||
on_success do
|
||||
Discourse.request_refresh!
|
||||
render(json: success_json)
|
||||
@ -26,7 +26,7 @@ class Admin::Config::FlagsController < Admin::AdminController
|
||||
end
|
||||
|
||||
def create
|
||||
with_service(Flags::CreateFlag) do
|
||||
Flags::CreateFlag.call do
|
||||
on_success do
|
||||
Discourse.request_refresh!
|
||||
render json: result.flag, serializer: FlagSerializer, used_flag_ids: Flag.used_flag_ids
|
||||
@ -40,7 +40,7 @@ class Admin::Config::FlagsController < Admin::AdminController
|
||||
end
|
||||
|
||||
def update
|
||||
with_service(Flags::UpdateFlag) do
|
||||
Flags::UpdateFlag.call do
|
||||
on_success do
|
||||
Discourse.request_refresh!
|
||||
render json: result.flag, serializer: FlagSerializer, used_flag_ids: Flag.used_flag_ids
|
||||
@ -57,7 +57,7 @@ class Admin::Config::FlagsController < Admin::AdminController
|
||||
end
|
||||
|
||||
def reorder
|
||||
with_service(Flags::ReorderFlag) do
|
||||
Flags::ReorderFlag.call do
|
||||
on_success do
|
||||
Discourse.request_refresh!
|
||||
render(json: success_json)
|
||||
@ -73,7 +73,7 @@ class Admin::Config::FlagsController < Admin::AdminController
|
||||
end
|
||||
|
||||
def destroy
|
||||
with_service(Flags::DestroyFlag) do
|
||||
Flags::DestroyFlag.call do
|
||||
on_success do
|
||||
Discourse.request_refresh!
|
||||
render(json: success_json)
|
||||
|
Reference in New Issue
Block a user