-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'epic/campaigns' into refactor/campaigns-design-review-G…
…IVE-1343
- Loading branch information
Showing
11 changed files
with
398 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Give\Campaigns\Routes; | ||
|
||
use Exception; | ||
use Give\API\RestRoute; | ||
use Give\Campaigns\Models\Campaign; | ||
use Give\Campaigns\ValueObjects\CampaignRoute; | ||
use WP_REST_Request; | ||
use WP_REST_Response; | ||
use WP_REST_Server; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class MergeCampaigns implements RestRoute | ||
{ | ||
/** | ||
* @unreleased | ||
*/ | ||
public function registerRoute() | ||
{ | ||
register_rest_route( | ||
CampaignRoute::NAMESPACE, | ||
CampaignRoute::CAMPAIGN . '/merge', | ||
[ | ||
[ | ||
'methods' => WP_REST_Server::EDITABLE, | ||
'callback' => [$this, 'handleRequest'], | ||
'permission_callback' => function () { | ||
return current_user_can('manage_options'); | ||
}, | ||
], | ||
'args' => [ | ||
'id' => [ | ||
'type' => 'integer', | ||
'required' => true, | ||
], | ||
'campaignsToMergeIds' => [ | ||
'type' => 'array', | ||
'required' => true, | ||
'items' => [ | ||
'type' => 'integer', | ||
], | ||
], | ||
], | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @throws Exception | ||
*/ | ||
public function handleRequest(WP_REST_Request $request): WP_REST_Response | ||
{ | ||
$destinationCampaign = Campaign::find($request->get_param('id')); | ||
$campaignsToMerge = Campaign::query()->whereIn('id', $request->get_param('campaignsToMergeIds'))->getAll(); | ||
|
||
$campaignsMerged = $destinationCampaign->merge(...$campaignsToMerge); | ||
|
||
return new WP_REST_Response($campaignsMerged); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.