implementing favorite stations db backend

This commit is contained in:
Jonas Heinrich 2020-11-06 09:11:30 +01:00
parent d29fc6c8f6
commit c835b6d1b8
6 changed files with 48 additions and 30 deletions

View File

@ -50,9 +50,9 @@ class StationApiController extends ApiController {
* @NoCSRFRequired * @NoCSRFRequired
* @NoAdminRequired * @NoAdminRequired
*/ */
public function create(string $title, string $content): DataResponse { public function create(string $stationuuid, string $name, string $favicon, string $url_resolved): DataResponse {
return new DataResponse($this->service->create($title, $content, return new DataResponse($this->service->create($stationuuid, $name,
$this->userId)); $favicon, $url_resolved, $this->userId));
} }
/** /**
@ -62,8 +62,8 @@ class StationApiController extends ApiController {
*/ */
public function update(int $id, string $title, public function update(int $id, string $title,
string $content): DataResponse { string $content): DataResponse {
return $this->handleNotFound(function () use ($id, $title, $content) { return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $url_resolved) {
return $this->service->update($id, $title, $content, $this->userId); return $this->service->update($id, $stationuuid, $name, $favicon, $url_resolved, $this->userId);
}); });
} }

View File

@ -42,18 +42,18 @@ class StationController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function create(string $title, string $content): DataResponse { public function create(string $stationuuid, string $name, string $favicon, string $url_resolved): DataResponse {
return new DataResponse($this->service->create($title, $content, return new DataResponse($this->service->create($stationuuid, $name,
$this->userId)); $favicon, $url_resolved, $this->userId));
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function update(int $id, string $title, public function update(int $id, string $stationuuid,
string $content): DataResponse { string $name, string $favicon, string $url_resolved): DataResponse {
return $this->handleNotFound(function () use ($id, $title, $content) { return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $url_resolved) {
return $this->service->update($id, $title, $content, $this->userId); return $this->service->update($id, $stationuuid, $name, $favicon, $url_resolved, $this->userId);
}); });
} }

View File

@ -7,15 +7,19 @@ use JsonSerializable;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
class Station extends Entity implements JsonSerializable { class Station extends Entity implements JsonSerializable {
protected $title; protected $stationuuid;
protected $content; protected $name;
protected $favicon;
protected $url_resolved;
protected $userId; protected $userId;
public function jsonSerialize(): array { public function jsonSerialize(): array {
return [ return [
'id' => $this->id, 'id' => $this->id,
'title' => $this->title, 'stationuuid' => $this->stationuuid,
'content' => $this->content 'name' => $this->name,
'favicon' => $this->favicon,
'url_resolved' => $this->url_resolved
]; ];
} }
} }

View File

@ -27,17 +27,25 @@ class Version000000Date20181013124731 extends SimpleMigrationStep {
'autoincrement' => true, 'autoincrement' => true,
'notnull' => true, 'notnull' => true,
]); ]);
$table->addColumn('title', 'string', [ $table->addColumn('stationuuid', 'string', [
'notnull' => true, 'notnull' => true,
'length' => 200 'length' => 200,
]); ]);
$table->addColumn('user_id', 'string', [ $table->addColumn('user_id', 'string', [
'notnull' => true, 'notnull' => true,
'length' => 200, 'length' => 200,
]); ]);
$table->addColumn('content', 'text', [ $table->addColumn('name', 'text', [
'notnull' => true, 'notnull' => true,
'default' => '' 'length' => 200,
]);
$table->addColumn('favicon', 'text', [
'notnull' => true,
'length' => 200,
]);
$table->addColumn('url_resolved', 'text', [
'notnull' => true,
'length' => 200,
]); ]);
$table->setPrimaryKey(['id']); $table->setPrimaryKey(['id']);

View File

@ -45,19 +45,23 @@ class StationService {
} }
} }
public function create($title, $content, $userId) { public function create($stationuuid, $name, $favicon, $url_resolved, $userId) {
$station = new Station(); $station = new Station();
$station->setTitle($title); $station->setStationUuid($stationuuid);
$station->setContent($content); $station->setName($name);
$station->setFavicon($favicon);
$station->setUrlResolved($url_resolved);
$station->setUserId($userId); $station->setUserId($userId);
return $this->mapper->insert($station); return $this->mapper->insert($station);
} }
public function update($id, $title, $content, $userId) { public function update($id, $stationuuid, $name, $userId) {
try { try {
$station = $this->mapper->find($id, $userId); $station = $this->mapper->find($id, $userId);
$station->setTitle($title); $station->setStationUuid($stationuuid);
$station->setContent($content); $station->setName($name);
$station->setFavicon($favicon);
$station->setUrlResolved($url_resolved);
return $this->mapper->update($station); return $this->mapper->update($station);
} catch (Exception $e) { } catch (Exception $e) {
$this->handleException($e); $this->handleException($e);

View File

@ -93,12 +93,14 @@ export default {
*/ */
async doFavor(station) { async doFavor(station) {
try { try {
station = { const newStation = {
id: -1, id: -1,
title: 'test', stationuuid: station.stationuuid,
content: 'testhallo', name: station.name,
favicon: station.favicon,
url_resolved: station.url_resolved,
} }
const response = await axios.post(generateUrl('/apps/radio/stations'), station) const response = await axios.post(generateUrl('/apps/radio/stations'), newStation)
console.log(response) console.log(response)
// const index = this.stations.findIndex((match) => match.id === this.currentStationId) // const index = this.stations.findIndex((match) => match.id === this.currentStationId)
// this.$set(this.stations, index, response.data) // this.$set(this.stations, index, response.data)