implementing favorite stations db backend
This commit is contained in:
parent
ebf8da0198
commit
caaa3e9ad6
@ -23,8 +23,10 @@
|
||||
|
||||
return [
|
||||
'resources' => [
|
||||
'station' => ['url' => '/stations'],
|
||||
'station_api' => ['url' => '/api/0.1/stations']
|
||||
'favorite' => ['url' => '/api/favorites'],
|
||||
'favorite_api' => ['url' => '/api/0.1/favorites'],
|
||||
'recent' => ['url' => '/api/recents'],
|
||||
'recent_api' => ['url' => '/api/0.1/recents']
|
||||
],
|
||||
'routes' => [
|
||||
|
||||
|
@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\Radio\Controller;
|
||||
|
||||
use OCA\Radio\AppInfo\Application;
|
||||
use OCA\Radio\Service\StationService;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
class StationApiController extends ApiController {
|
||||
/** @var StationService */
|
||||
private $service;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
use Errors;
|
||||
|
||||
public function __construct(IRequest $request,
|
||||
StationService $service,
|
||||
$userId) {
|
||||
parent::__construct(Application::APP_ID, $request);
|
||||
$this->service = $service;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function index(): DataResponse {
|
||||
return new DataResponse($this->service->findAll($this->userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function show(int $id): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->find($id, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function create(string $stationuuid, string $name, string $favicon, string $urlresolved): DataResponse {
|
||||
return new DataResponse($this->service->create($stationuuid, $name,
|
||||
$favicon, $urlresolved, $this->userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function update(int $id, string $title,
|
||||
string $content): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $urlresolved) {
|
||||
return $this->service->update($id, $stationuuid, $name, $favicon, $urlresolved, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function destroy(int $id): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->delete($id, $this->userId);
|
||||
});
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\Radio\Controller;
|
||||
|
||||
use OCA\Radio\AppInfo\Application;
|
||||
use OCA\Radio\Service\StationService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
class StationController extends Controller {
|
||||
/** @var StationService */
|
||||
private $service;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
public function __construct(IRequest $request,
|
||||
StationService $service,
|
||||
$userId) {
|
||||
parent::__construct(Application::APP_ID, $request);
|
||||
$this->service = $service;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function index(): DataResponse {
|
||||
return new DataResponse($this->service->findAll($this->userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function show(int $id): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->find($id, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function create(string $stationuuid, string $name, string $favicon, string $urlresolved = "lol"): DataResponse {
|
||||
return new DataResponse($this->service->create($stationuuid, $name,
|
||||
$favicon, $urlresolved, $this->userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function update(int $id, string $stationuuid,
|
||||
string $name, string $favicon, string $urlresolved): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $urlresolved) {
|
||||
return $this->service->update($id, $stationuuid, $name, $favicon, $urlresolved, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function destroy(int $id): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->delete($id, $this->userId);
|
||||
});
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ use OCP\IDBConnection;
|
||||
|
||||
class StationMapper extends QBMapper {
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'radio', Station::class);
|
||||
parent::__construct($db, 'favorites', Station::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -24,7 +24,7 @@ class StationMapper extends QBMapper {
|
||||
/* @var $qb IQueryBuilder */
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('radio')
|
||||
->from('favorites')
|
||||
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
|
||||
return $this->findEntity($qb);
|
||||
@ -38,7 +38,7 @@ class StationMapper extends QBMapper {
|
||||
/* @var $qb IQueryBuilder */
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('radio')
|
||||
->from('favorites')
|
||||
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ class Version000000Date20181013124731 extends SimpleMigrationStep {
|
||||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
if (!$schema->hasTable('radio')) {
|
||||
$table = $schema->createTable('radio');
|
||||
if (!$schema->hasTable('favorites')) {
|
||||
$table = $schema->createTable('favorites');
|
||||
$table->addColumn('id', 'integer', [
|
||||
'autoincrement' => true,
|
||||
'notnull' => true,
|
||||
@ -40,7 +40,7 @@ class Version000000Date20181013124731 extends SimpleMigrationStep {
|
||||
$table->addColumn('urlresolved', 'text');
|
||||
|
||||
$table->setPrimaryKey(['id']);
|
||||
$table->addIndex(['user_id'], 'radio_user_id_index');
|
||||
$table->addIndex(['user_id'], 'favorites_user_id_index');
|
||||
}
|
||||
return $schema;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ export default {
|
||||
*/
|
||||
async doFavor(station) {
|
||||
try {
|
||||
await axios.post(generateUrl('/apps/radio/stations'), station)
|
||||
await axios.post(generateUrl('/apps/radio/api/favorites'), station)
|
||||
} catch (e) {
|
||||
showError(t('radio', 'Could not favor station'))
|
||||
}
|
||||
@ -172,7 +172,7 @@ export default {
|
||||
const searchQuery = vm.$route.params.query
|
||||
queryURI = queryBase + '/byname/' + searchQuery
|
||||
} else if (menuState === 'FAVORITES') {
|
||||
queryURI = generateUrl('/apps/radio/stations')
|
||||
queryURI = generateUrl('/apps/radio/api/favorites')
|
||||
}
|
||||
|
||||
await axios.get(queryURI, {
|
||||
@ -211,7 +211,7 @@ export default {
|
||||
this.$store.dispatch('getVolumeState')
|
||||
},
|
||||
async loadFavorites() {
|
||||
await axios.get(generateUrl('/apps/radio/stations'))
|
||||
await axios.get(generateUrl('/apps/radio/api/favorites'))
|
||||
.then(function(response) {
|
||||
this.favorites = response.data
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user