implementing db backend ...
This commit is contained in:
parent
ee1a3bfc59
commit
1253c560f3
52
controller/stationcontroller.php
Normal file
52
controller/stationcontroller.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace OCA\OwnNotes\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
|
||||
use OCA\OwnNotes\Service\NoteService;
|
||||
|
||||
class NoteController extends Controller {
|
||||
|
||||
private $service;
|
||||
private $userId;
|
||||
|
||||
use Errors;
|
||||
|
||||
public function __construct($AppName, IRequest $request,
|
||||
NoteService $service, $UserId){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->service = $service;
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function favorites() {
|
||||
return new DataResponse($this->service->findAll($this->userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $content
|
||||
*/
|
||||
public function fav($id) {
|
||||
return $this->service->create($id, $this->userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function unfav($id) {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->delete($id, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
BIN
img/fav_hover.png
Normal file
BIN
img/fav_hover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
51
service/streamservice.php
Normal file
51
service/streamservice.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace OCA\OwnNotes\Service;
|
||||
|
||||
use Exception;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
|
||||
use OCA\OwnNotes\Db\Note;
|
||||
use OCA\OwnNotes\Db\NoteMapper;
|
||||
|
||||
|
||||
class NoteService {
|
||||
|
||||
private $mapper;
|
||||
|
||||
public function __construct(NoteMapper $mapper){
|
||||
$this->mapper = $mapper;
|
||||
}
|
||||
|
||||
public function findAll($userId) {
|
||||
return $this->mapper->findAll($userId);
|
||||
}
|
||||
|
||||
private function handleException ($e) {
|
||||
if ($e instanceof DoesNotExistException ||
|
||||
$e instanceof MultipleObjectsReturnedException) {
|
||||
throw new NotFoundException($e->getMessage());
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function fav($id, $userId) {
|
||||
$station = new Station();
|
||||
$station->setId($id);
|
||||
$station->setUserId($userId);
|
||||
return $this->mapper->insert($station);
|
||||
}
|
||||
|
||||
public function unfav($id, $userId) {
|
||||
try {
|
||||
$station = $this->mapper->find($id, $userId);
|
||||
$this->mapper->delete($station);
|
||||
return $station;
|
||||
} catch(Exception $e) {
|
||||
$this->handleException($e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user