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

View File

@ -42,18 +42,18 @@ class StationController extends Controller {
/**
* @NoAdminRequired
*/
public function create(string $title, string $content): DataResponse {
return new DataResponse($this->service->create($title, $content,
$this->userId));
public function create(string $stationuuid, string $name, string $favicon, string $url_resolved): DataResponse {
return new DataResponse($this->service->create($stationuuid, $name,
$favicon, $url_resolved, $this->userId));
}
/**
* @NoAdminRequired
*/
public function update(int $id, string $title,
string $content): DataResponse {
return $this->handleNotFound(function () use ($id, $title, $content) {
return $this->service->update($id, $title, $content, $this->userId);
public function update(int $id, string $stationuuid,
string $name, string $favicon, string $url_resolved): DataResponse {
return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $url_resolved) {
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;
class Station extends Entity implements JsonSerializable {
protected $title;
protected $content;
protected $stationuuid;
protected $name;
protected $favicon;
protected $url_resolved;
protected $userId;
public function jsonSerialize(): array {
return [
'id' => $this->id,
'title' => $this->title,
'content' => $this->content
'stationuuid' => $this->stationuuid,
'name' => $this->name,
'favicon' => $this->favicon,
'url_resolved' => $this->url_resolved
];
}
}

View File

@ -27,17 +27,25 @@ class Version000000Date20181013124731 extends SimpleMigrationStep {
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('title', 'string', [
$table->addColumn('stationuuid', 'string', [
'notnull' => true,
'length' => 200
'length' => 200,
]);
$table->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 200,
]);
$table->addColumn('content', 'text', [
$table->addColumn('name', 'text', [
'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']);

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->setTitle($title);
$station->setContent($content);
$station->setStationUuid($stationuuid);
$station->setName($name);
$station->setFavicon($favicon);
$station->setUrlResolved($url_resolved);
$station->setUserId($userId);
return $this->mapper->insert($station);
}
public function update($id, $title, $content, $userId) {
public function update($id, $stationuuid, $name, $userId) {
try {
$station = $this->mapper->find($id, $userId);
$station->setTitle($title);
$station->setContent($content);
$station->setStationUuid($stationuuid);
$station->setName($name);
$station->setFavicon($favicon);
$station->setUrlResolved($url_resolved);
return $this->mapper->update($station);
} catch (Exception $e) {
$this->handleException($e);

View File

@ -93,12 +93,14 @@ export default {
*/
async doFavor(station) {
try {
station = {
const newStation = {
id: -1,
title: 'test',
content: 'testhallo',
stationuuid: station.stationuuid,
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)
// const index = this.stations.findIndex((match) => match.id === this.currentStationId)
// this.$set(this.stations, index, response.data)