2021-03-08 15:19:04 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-03-08 15:19:04 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-03-08 15:19:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
use App\Events\Subscription\SubscriptionWasCreated;
|
2021-04-13 01:52:17 +02:00
|
|
|
use App\Events\Subscription\SubscriptionWasUpdated;
|
2021-03-25 11:55:59 +01:00
|
|
|
use App\Factory\SubscriptionFactory;
|
2023-01-05 12:09:25 +01:00
|
|
|
use App\Filters\SubscriptionFilters;
|
2021-03-25 11:55:59 +01:00
|
|
|
use App\Http\Requests\Subscription\CreateSubscriptionRequest;
|
|
|
|
use App\Http\Requests\Subscription\DestroySubscriptionRequest;
|
|
|
|
use App\Http\Requests\Subscription\EditSubscriptionRequest;
|
|
|
|
use App\Http\Requests\Subscription\ShowSubscriptionRequest;
|
|
|
|
use App\Http\Requests\Subscription\StoreSubscriptionRequest;
|
|
|
|
use App\Http\Requests\Subscription\UpdateSubscriptionRequest;
|
|
|
|
use App\Models\Subscription;
|
|
|
|
use App\Repositories\SubscriptionRepository;
|
|
|
|
use App\Transformers\SubscriptionTransformer;
|
2021-03-08 15:19:04 +01:00
|
|
|
use App\Utils\Ninja;
|
2021-04-11 05:52:37 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2021-03-08 15:19:04 +01:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
class SubscriptionController extends BaseController
|
2021-03-08 15:19:04 +01:00
|
|
|
{
|
2021-04-11 05:52:37 +02:00
|
|
|
use MakesHash;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
protected $entity_type = Subscription::class;
|
2021-03-08 15:19:04 +01:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
protected $entity_transformer = SubscriptionTransformer::class;
|
2021-03-08 15:19:04 +01:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
protected $subscription_repo;
|
2021-03-08 15:19:04 +01:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
public function __construct(SubscriptionRepository $subscription_repo)
|
2021-03-08 15:19:04 +01:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
$this->subscription_repo = $subscription_repo;
|
2021-03-08 15:19:04 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:29:59 +01:00
|
|
|
/**
|
2021-03-25 11:55:59 +01:00
|
|
|
* Show the list of Subscriptions.
|
2022-06-21 11:57:17 +02:00
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2021-03-08 22:29:59 +01:00
|
|
|
*
|
|
|
|
* @OA\Get(
|
2021-03-25 11:55:59 +01:00
|
|
|
* path="/api/v1/subscriptions",
|
|
|
|
* operationId="getSubscriptions",
|
|
|
|
* tags={"subscriptions"},
|
|
|
|
* summary="Gets a list of subscriptions",
|
|
|
|
* description="Lists subscriptions.",
|
2022-06-21 11:57:17 +02:00
|
|
|
*
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-03-08 22:29:59 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
2021-03-25 11:55:59 +01:00
|
|
|
* description="A list of subscriptions",
|
2021-03-08 22:29:59 +01:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
2021-03-25 11:55:59 +01:00
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
2021-03-08 22:29:59 +01:00
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
2023-01-04 03:09:47 +01:00
|
|
|
public function index(SubscriptionFilters $filters): \Illuminate\Http\Response
|
2021-03-08 15:19:04 +01:00
|
|
|
{
|
2023-01-04 03:09:47 +01:00
|
|
|
$subscriptions = Subscription::filter($filters);
|
2021-03-08 15:19:04 +01:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
return $this->listResponse($subscriptions);
|
2021-03-08 15:19:04 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 07:06:03 +01:00
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2021-03-25 11:55:59 +01:00
|
|
|
* @param CreateSubscriptionRequest $request The request
|
2021-03-09 07:06:03 +01:00
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2021-03-09 07:06:03 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
2021-03-25 11:55:59 +01:00
|
|
|
* path="/api/v1/subscriptions/create",
|
|
|
|
* operationId="getSubscriptionsCreate",
|
|
|
|
* tags={"subscriptions"},
|
|
|
|
* summary="Gets a new blank subscriptions object",
|
2021-03-09 07:06:03 +01:00
|
|
|
* description="Returns a blank object with default values",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-03-09 07:06:03 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
2021-03-25 11:55:59 +01:00
|
|
|
* description="A blank subscriptions object",
|
2021-03-09 07:06:03 +01:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
2021-03-25 11:55:59 +01:00
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
2021-03-09 07:06:03 +01:00
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
2021-03-25 11:55:59 +01:00
|
|
|
public function create(CreateSubscriptionRequest $request): \Illuminate\Http\Response
|
2021-03-08 15:19:04 +01:00
|
|
|
{
|
2021-03-25 11:55:59 +01:00
|
|
|
$subscription = SubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
2021-03-08 15:19:04 +01:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
return $this->itemResponse($subscription);
|
2021-03-08 15:19:04 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 11:30:34 +01:00
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2021-03-25 11:55:59 +01:00
|
|
|
* @param StoreSubscriptionRequest $request The request
|
2021-03-09 11:30:34 +01:00
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2021-03-09 11:30:34 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
2021-03-25 11:55:59 +01:00
|
|
|
* path="/api/v1/subscriptions",
|
|
|
|
* operationId="storeSubscription",
|
|
|
|
* tags={"subscriptions"},
|
|
|
|
* summary="Adds a subscriptions",
|
|
|
|
* description="Adds an subscriptions to the system",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-03-09 11:30:34 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
2021-03-25 11:55:59 +01:00
|
|
|
* description="Returns the saved subscriptions object",
|
2021-03-09 11:30:34 +01:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
2021-03-25 11:55:59 +01:00
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
2021-03-09 11:30:34 +01:00
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
2021-03-25 11:55:59 +01:00
|
|
|
public function store(StoreSubscriptionRequest $request): \Illuminate\Http\Response
|
2021-03-08 15:19:04 +01:00
|
|
|
{
|
2021-03-25 11:55:59 +01:00
|
|
|
$subscription = $this->subscription_repo->save($request->all(), SubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
2021-03-08 15:19:04 +01:00
|
|
|
|
2021-05-06 23:12:07 +02:00
|
|
|
event(new SubscriptionWasCreated($subscription, $subscription->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
2021-03-08 15:19:04 +01:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
return $this->itemResponse($subscription);
|
2021-03-08 15:19:04 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 11:30:34 +01:00
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2021-03-25 11:55:59 +01:00
|
|
|
* @param ShowSubscriptionRequest $request The request
|
|
|
|
* @param Invoice $subscription The invoice
|
2021-03-09 11:30:34 +01:00
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2021-03-09 11:30:34 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
2021-03-25 11:55:59 +01:00
|
|
|
* path="/api/v1/subscriptions/{id}",
|
|
|
|
* operationId="showSubscription",
|
|
|
|
* tags={"subscriptions"},
|
|
|
|
* summary="Shows an subscriptions",
|
|
|
|
* description="Displays an subscriptions by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-03-09 11:30:34 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
2021-03-25 11:55:59 +01:00
|
|
|
* description="The Subscription Hashed ID",
|
2021-03-09 11:30:34 +01:00
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
2021-03-25 11:55:59 +01:00
|
|
|
* description="Returns the Subscription object",
|
2021-03-09 11:30:34 +01:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
2021-03-25 11:55:59 +01:00
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
2021-03-09 11:30:34 +01:00
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
2021-03-25 11:55:59 +01:00
|
|
|
public function show(ShowSubscriptionRequest $request, Subscription $subscription): \Illuminate\Http\Response
|
2021-03-08 15:19:04 +01:00
|
|
|
{
|
2021-03-25 11:55:59 +01:00
|
|
|
return $this->itemResponse($subscription);
|
2021-03-08 15:19:04 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 11:30:34 +01:00
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2021-03-25 11:55:59 +01:00
|
|
|
* @param EditSubscriptionRequest $request The request
|
|
|
|
* @param Invoice $subscription The invoice
|
2021-03-09 11:30:34 +01:00
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2021-03-09 11:30:34 +01:00
|
|
|
*
|
|
|
|
* @OA\Get(
|
2021-03-25 11:55:59 +01:00
|
|
|
* path="/api/v1/subscriptions/{id}/edit",
|
|
|
|
* operationId="editSubscription",
|
|
|
|
* tags={"subscriptions"},
|
|
|
|
* summary="Shows an subscriptions for editting",
|
|
|
|
* description="Displays an subscriptions by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-03-09 11:30:34 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
2021-03-25 11:55:59 +01:00
|
|
|
* description="The Subscription Hashed ID",
|
2021-03-09 11:30:34 +01:00
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the invoice object",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
2021-03-25 11:55:59 +01:00
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
2021-03-09 11:30:34 +01:00
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
2021-03-25 11:55:59 +01:00
|
|
|
public function edit(EditSubscriptionRequest $request, Subscription $subscription): \Illuminate\Http\Response
|
2021-03-08 15:19:04 +01:00
|
|
|
{
|
2021-03-25 11:55:59 +01:00
|
|
|
return $this->itemResponse($subscription);
|
2021-03-08 15:19:04 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 11:30:34 +01:00
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2021-03-25 11:55:59 +01:00
|
|
|
* @param UpdateSubscriptionRequest $request The request
|
|
|
|
* @param Subscription $subscription The invoice
|
2021-03-09 11:30:34 +01:00
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2021-03-09 11:30:34 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Put(
|
2021-03-25 11:55:59 +01:00
|
|
|
* path="/api/v1/subscriptions/{id}",
|
|
|
|
* operationId="updateSubscription",
|
|
|
|
* tags={"subscriptions"},
|
|
|
|
* summary="Updates an subscriptions",
|
|
|
|
* description="Handles the updating of an subscriptions by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-03-09 11:30:34 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
2021-03-25 11:55:59 +01:00
|
|
|
* description="The Subscription Hashed ID",
|
2021-03-09 11:30:34 +01:00
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
2021-03-25 11:55:59 +01:00
|
|
|
* description="Returns the subscriptions object",
|
2021-03-09 11:30:34 +01:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
2021-03-25 11:55:59 +01:00
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
2021-03-09 11:30:34 +01:00
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
2021-03-25 11:55:59 +01:00
|
|
|
public function update(UpdateSubscriptionRequest $request, Subscription $subscription)
|
2021-03-08 15:19:04 +01:00
|
|
|
{
|
2021-03-25 11:55:59 +01:00
|
|
|
if ($request->entityIsDeleted($subscription)) {
|
2021-03-08 15:19:04 +01:00
|
|
|
return $request->disallowUpdate();
|
|
|
|
}
|
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
$subscription = $this->subscription_repo->save($request->all(), $subscription);
|
2021-03-08 15:19:04 +01:00
|
|
|
|
2021-05-06 23:12:07 +02:00
|
|
|
event(new SubscriptionWasUpdated($subscription, $subscription->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
2021-04-13 01:52:17 +02:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
return $this->itemResponse($subscription);
|
2021-03-08 15:19:04 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 11:30:34 +01:00
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2021-03-25 11:55:59 +01:00
|
|
|
* @param DestroySubscriptionRequest $request
|
|
|
|
* @param Subscription $invoice
|
2021-03-09 11:30:34 +01:00
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2021-03-09 11:30:34 +01:00
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
* @OA\Delete(
|
2021-03-25 11:55:59 +01:00
|
|
|
* path="/api/v1/subscriptions/{id}",
|
|
|
|
* operationId="deleteSubscription",
|
|
|
|
* tags={"subscriptions"},
|
|
|
|
* summary="Deletes a subscriptions",
|
|
|
|
* description="Handles the deletion of an subscriptions by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-03-09 11:30:34 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
2021-03-25 11:55:59 +01:00
|
|
|
* description="The Subscription Hashed ID",
|
2021-03-09 11:30:34 +01:00
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns a HTTP status",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
2021-03-25 11:55:59 +01:00
|
|
|
public function destroy(DestroySubscriptionRequest $request, Subscription $subscription): \Illuminate\Http\Response
|
2021-03-08 15:19:04 +01:00
|
|
|
{
|
2021-03-25 11:55:59 +01:00
|
|
|
$this->subscription_repo->delete($subscription);
|
2021-03-08 15:19:04 +01:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
return $this->itemResponse($subscription->fresh());
|
2021-03-08 15:19:04 +01:00
|
|
|
}
|
2021-04-11 05:52:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform bulk actions on the list view.
|
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Support\Collection
|
2021-04-11 05:52:37 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/subscriptions/bulk",
|
|
|
|
* operationId="bulkSubscriptions",
|
|
|
|
* tags={"subscriptions"},
|
|
|
|
* summary="Performs bulk actions on an array of subscriptions",
|
|
|
|
* description="",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-04-11 05:52:37 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/index"),
|
|
|
|
* @OA\RequestBody(
|
|
|
|
* description="User credentials",
|
|
|
|
* required=true,
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="array",
|
|
|
|
* @OA\Items(
|
|
|
|
* type="integer",
|
|
|
|
* description="Array of hashed IDs to be bulk 'actioned",
|
|
|
|
* example="[0,1,2,3]",
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="The Subscription response",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function bulk()
|
|
|
|
{
|
|
|
|
$action = request()->input('action');
|
|
|
|
|
|
|
|
$ids = request()->input('ids');
|
|
|
|
$subscriptions = Subscription::withTrashed()->find($this->transformKeys($ids));
|
|
|
|
|
|
|
|
$subscriptions->each(function ($subscription, $key) use ($action) {
|
|
|
|
if (auth()->user()->can('edit', $subscription)) {
|
|
|
|
$this->subscription_repo->{$action}($subscription);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return $this->listResponse(Subscription::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
|
|
|
}
|
2021-03-08 15:19:04 +01:00
|
|
|
}
|