--- /dev/null
+<?php
+
+namespace App\Controller\Api\V1;
+
+use App\Controller\AppController;
+use App\Network\Exception\SubscriptionNotFoundException;
+
+/**
+ * Subscriptions Controller
+ *
+ * @property \App\Model\Table\SubscriptionsTable $Subscriptions
+ */
+class SubscriptionsController extends AppController {
+
+ public $paginate = [
+ 'page' => 1,
+ 'limit' => 20,
+ 'maxLimit' => 100,
+ 'fields' => [
+ 'id', 'name'
+ ],
+ 'sortWhitelist' => [
+ 'id', 'name'
+ ]
+ ];
+
+ /**
+ * Index method
+ *
+ * @return \Cake\Network\Response|null
+ */
+ public function index() {
+ $this->request->allowMethod('get');
+
+ $subscriptions = $this->paginate($this->Subscriptions);
+
+ $pagination = $this->request->params['paging']['Subscriptions'];
+
+ $paginationResponse = [
+ 'page_count' => $pagination['pageCount'],
+ 'current_page' => $pagination['page'],
+ 'has_next_page' => $pagination['nextPage'],
+ 'has_prev_page' => $pagination['prevPage'],
+ 'count' => $pagination['count'],
+ 'limit' => $pagination['limit']
+ ];
+
+ $this->set('pagination', $paginationResponse);
+ $this->set('subscriptions', $subscriptions);
+ }
+
+ /**
+ * View method
+ *
+ * @param string $id Subscription id.
+ * @return \Cake\Network\Response|null
+ * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
+ */
+ public function view($id) {
+ $this->request->allowMethod('get');
+ try {
+ $subscription = $this->Subscriptions->get($id, [
+ 'contain' => ['Services']
+ ]);
+ }
+ catch (\Exception $e) {
+ throw new SubscriptionNotFoundException("The subscription with the id $id does not exist");
+ }
+ $this->set('subscription', $subscription);
+ $this->set('_serialize', 'subscription');
+ }
+
+ /**
+ * Add method
+ *
+ * @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise.
+ */
+ public function add() {
+ $this->request->allowMethod('post');
+
+ $subscription = $this->Subscriptions->newEntity($this->request->data);
+ if ($this->Subscriptions->save($subscription)) {
+ $this->response->statusCode(201);
+ $this->set('subscription', $subscription);
+ $this->set('_serialize', 'subscription');
+ }
+ else {
+ $this->response->statusCode(400);
+ throw new ValidationException($subscription);
+ }
+ }
+
+ /**
+ * Edit method
+ *
+ * @param string $id Subscription id.
+ * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise.
+ * @throws \Cake\Network\Exception\NotFoundException When record not found.
+ */
+ public function edit($id) {
+ $this->request->allowMethod('put');
+
+ try {
+ $subscription = $this->Subscriptions->get($id);
+ }
+ catch (\Exception $e) {
+ throw new SubscriptionNotFoundException("The subscription with the id $id does not exist");
+ }
+
+ $subscription = $this->Subscriptions->patchEntity($subscription, $this->request->data);
+ if ($this->Subscriptions->save($subscription)) {
+ $this->set('subscription', $subscription);
+ $this->set('_serialize', 'subscription');
+ }
+ else {
+ throw new ValidationException($subscription);
+ }
+ }
+
+ /**
+ * Delete method
+ *
+ * @param string $id Subscription id.
+ * @return \Cake\Network\Response|null Redirects to index.
+ * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
+ */
+ public function delete($id) {
+ $this->request->allowMethod('delete');
+ try {
+ $subscription = $this->Subscriptions->get($id);
+ }
+ catch (\Exception $e) {
+ throw new SubscriptionNotFoundException("The subscription with the id $id does not exist");
+ }
+ $this->Subscriptions->delete($subscription);
+ $this->response->statusCode(204);
+ }
+
+}