85 lines
1.8 KiB
PHP
85 lines
1.8 KiB
PHP
|
<?php
|
||
|
namespace OCA\Radio\Controller;
|
||
|
|
||
|
use OCP\IRequest;
|
||
|
use OCP\AppFramework\Http\DataResponse;
|
||
|
use OCP\AppFramework\ApiController;
|
||
|
|
||
|
use OCA\Radio\Service\StationService;
|
||
|
|
||
|
class StationApiController extends ApiController {
|
||
|
|
||
|
private $service;
|
||
|
private $userId;
|
||
|
|
||
|
use Errors;
|
||
|
|
||
|
public function __construct($AppName, IRequest $request,
|
||
|
StationService $service, $UserId){
|
||
|
parent::__construct($AppName, $request);
|
||
|
$this->service = $service;
|
||
|
$this->userId = $UserId;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @CORS
|
||
|
* @NoCSRFRequired
|
||
|
* @NoAdminRequired
|
||
|
*/
|
||
|
public function index() {
|
||
|
return new DataResponse($this->service->findAll($this->userId));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @CORS
|
||
|
* @NoCSRFRequired
|
||
|
* @NoAdminRequired
|
||
|
*
|
||
|
* @param int $id
|
||
|
*/
|
||
|
public function show($id) {
|
||
|
return $this->handleNotFound(function () use ($id) {
|
||
|
return $this->service->find($id, $this->userId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @CORS
|
||
|
* @NoCSRFRequired
|
||
|
* @NoAdminRequired
|
||
|
*
|
||
|
* @param string $stationid
|
||
|
*/
|
||
|
public function create($stationid) {
|
||
|
return $this->service->create($stationid, $this->userId);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @CORS
|
||
|
* @NoCSRFRequired
|
||
|
* @NoAdminRequired
|
||
|
*
|
||
|
* @param int $id
|
||
|
* @param string $stationid
|
||
|
*/
|
||
|
public function update($id, $stationid) {
|
||
|
return $this->handleNotFound(function () use ($id, $stationid) {
|
||
|
return $this->service->update($id, $stationid, $this->userId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @CORS
|
||
|
* @NoCSRFRequired
|
||
|
* @NoAdminRequired
|
||
|
*
|
||
|
* @param int $id
|
||
|
*/
|
||
|
public function destroy($id) {
|
||
|
return $this->handleNotFound(function () use ($id) {
|
||
|
return $this->service->delete($id, $this->userId);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
}
|