mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-02-23 11:16:05 +01:00
91 lines
2.5 KiB
PHP
91 lines
2.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Cachet.
|
|
*
|
|
* (c) Alt Three Services Limited
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
|
|
|
use CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand;
|
|
use CachetHQ\Cachet\Bus\Commands\Subscriber\UnsubscribeSubscriberCommand;
|
|
use CachetHQ\Cachet\Bus\Commands\Subscriber\UnsubscribeSubscriptionCommand;
|
|
use CachetHQ\Cachet\Models\Subscriber;
|
|
use CachetHQ\Cachet\Models\Subscription;
|
|
use GrahamCampbell\Binput\Facades\Binput;
|
|
use Illuminate\Contracts\Config\Repository;
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Support\Facades\Request;
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
|
|
|
/**
|
|
* This is the subscriber controller class.
|
|
*
|
|
* @author James Brooks <james@alt-three.com>
|
|
* @author Graham Campbell <graham@alt-three.com>
|
|
*/
|
|
class SubscriberController extends AbstractApiController
|
|
{
|
|
/**
|
|
* Get all subscribers.
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function getSubscribers()
|
|
{
|
|
$subscribers = Subscriber::paginate(Binput::get('per_page', 20));
|
|
|
|
return $this->paginator($subscribers, Request::instance());
|
|
}
|
|
|
|
/**
|
|
* Create a new subscriber.
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function postSubscribers()
|
|
{
|
|
$verified = Binput::get('verify', app(Repository::class)->get('setting.skip_subscriber_verification'));
|
|
|
|
try {
|
|
$subscriber = dispatch(new SubscribeSubscriberCommand(Binput::get('email'), $verified, Binput::get('components')));
|
|
} catch (QueryException $e) {
|
|
throw new BadRequestHttpException();
|
|
}
|
|
|
|
return $this->item($subscriber);
|
|
}
|
|
|
|
/**
|
|
* Delete a subscriber.
|
|
*
|
|
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function deleteSubscriber(Subscriber $subscriber)
|
|
{
|
|
dispatch(new UnsubscribeSubscriberCommand($subscriber));
|
|
|
|
return $this->noContent();
|
|
}
|
|
|
|
/**
|
|
* Delete a subscriber.
|
|
*
|
|
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function deleteSubscription(Subscription $subscriber)
|
|
{
|
|
dispatch(new UnsubscribeSubscriptionCommand($subscriber));
|
|
|
|
return $this->noContent();
|
|
}
|
|
}
|