diff --git a/appinfo/info.xml b/appinfo/info.xml
index d6aacfb..92da455 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -12,7 +12,7 @@
tools
https://gitea.rs485.network/UPschooling/Nextcloud-App/issues
-
+
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 7c3e44c..08627b1 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -2,13 +2,13 @@
return [
'resources' => [
- 'ticket_api' => ['url' => '/api/v1/ticket']
+ 'ticket_api' => ['url' => '/api/v1/tickets']
],
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
[
'name' => 'ticket_api#preflighted_cors',
- 'url' => '/api/v1/{path}',
+ 'url' => '/api/v1/tickets',
'verb' => 'OPTIONS',
'requirements' => ['path' => '.+'],
],
diff --git a/lib/Controller/TicketApiController.php b/lib/Controller/TicketApiController.php
index d2a9d6f..603ecac 100644
--- a/lib/Controller/TicketApiController.php
+++ b/lib/Controller/TicketApiController.php
@@ -8,7 +8,8 @@ use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
-class TicketApiController extends ApiController {
+class TicketApiController extends ApiController
+{
/** @var TicketService */
private $service;
@@ -17,62 +18,46 @@ class TicketApiController extends ApiController {
use Errors;
- public function __construct(IRequest $request,
- TicketService $service,
- $userId) {
+ public function __construct(IRequest $request, TicketService $service, $userId)
+ {
parent::__construct(Application::APP_ID, $request);
$this->service = $service;
$this->userId = $userId;
}
/**
- * @CORS
- * @NoCSRFRequired
* @NoAdminRequired
*/
- public function index(): DataResponse {
+ public function index(): DataResponse
+ {
return new DataResponse($this->service->findAll($this->userId));
}
/**
- * @CORS
- * @NoCSRFRequired
* @NoAdminRequired
*/
- public function show(int $id): DataResponse {
+ 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 $title, string $content): DataResponse {
+ public function create(string $title, string $content): DataResponse
+ {
return new DataResponse($this->service->create($title, $content,
$this->userId));
}
- /**
- * @CORS
- * @NoCSRFRequired
- * @NoAdminRequired
- */
- public function update(int $id, string $title,
- string $content): DataResponse {
+ 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);
});
}
- /**
- * @CORS
- * @NoCSRFRequired
- * @NoAdminRequired
- */
- public function destroy(int $id): DataResponse {
+ public function destroy(int $id): DataResponse
+ {
return $this->handleNotFound(function () use ($id) {
return $this->service->delete($id, $this->userId);
});
diff --git a/lib/Service/MatrixService.php b/lib/Service/MatrixService.php
index 795daa0..7b7c96c 100644
--- a/lib/Service/MatrixService.php
+++ b/lib/Service/MatrixService.php
@@ -31,11 +31,18 @@ class MatrixService
$this->channel = "#issue:synapse";
$this->client = new MatrixClient("http://synapse:8008");
$this->token = $this->client->login("upschooling", "secret");
- try {
- $this->room = $this->client->createRoom($this->channel, false, array());
- } catch (MatrixException $e) {
- $this->logger->error("Could not create room ".$this->channel, array('exception' => $e));
- }
+// try {
+// $this->room = $this->client->createRoom($this->channel, false, array());
+// } catch (MatrixException $createE) {
+// try {
+// $this->room = $this->client->joinRoom($this->channel);
+// } catch (MatrixException $e) {
+// $this->logger->error(
+// "Could not create room ".$this->channel,
+// array('exception' => $e, 'causedBy' => $createE)
+// );
+// }
+// }
}
/**
diff --git a/src/App.vue b/src/App.vue
index 777f94c..7047a8a 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -18,6 +18,7 @@ import AppNavigation from '@nextcloud/vue/dist/Components/AppNavigation'
import TicketList from './components/TicketList'
import Ticket from './Ticket'
import '@nextcloud/dialogs/styles/toast.scss'
+import axios from '@nextcloud/axios'
export default {
name: 'App',
@@ -27,6 +28,7 @@ export default {
AppContent,
AppNavigation,
},
+
data() {
return {
/**
@@ -36,37 +38,32 @@ export default {
*/
currentTicket: undefined,
- testTickets: [
- {
- id: 1234,
- status: 'Offen',
- title: 'Dies ist ein Ticket-Titel',
- },
- {
- id: 12345,
- status: 'Offen',
- title: 'Dies ist ein anderer Ticket-Titel',
- },
- {
- id: 123456,
- status: 'Behoben',
- title: 'Sowieso behoben',
- },
- ],
+ tickets: [],
}
},
- computed: {
- /**
- * Returns the list of ticket objects the current account has access to.
- *
- * @return {Array}
- */
- tickets() {
- // TODO: ask API (dont forget permission check in API)
- return this.testTickets
- },
+ watch: {
+ $route: 'fetchTickets',
+ },
+ created() {
+ this.fetchTickets()
},
methods: {
+ fetchTickets() {
+ axios.get(
+ 'api/v1/tickets',
+ { headers: { Accept: 'application/json' } }
+ ).then((response) => {
+ if (Array.isArray(response.data)) {
+ if (response.data.length !== 0) {
+ this.tickets.push(response.data)
+ } else {
+ console.warn('Empty ticket list :(')
+ }
+ } else {
+ console.error('API did not return array: ', response)
+ }
+ }).catch(console.error)
+ },
saveTicket(ticketId, data) {
// TODO send to API (dont forget permission check in API)
console.debug('upschooling', 'saveTicket', ticketId, data)
diff --git a/tests/Unit/Service/NoteServiceTest.php b/tests/Unit/Service/NoteServiceTest.php
index 342ceff..90f7331 100644
--- a/tests/Unit/Service/NoteServiceTest.php
+++ b/tests/Unit/Service/NoteServiceTest.php
@@ -4,21 +4,33 @@ namespace Unit\Service;
use OCA\UPschooling\Db\MatrixTicket;
use OCA\UPschooling\Db\TicketMapper;
+use OCA\UPschooling\Service\MatrixService;
use OCA\UPschooling\Service\NoteNotFound;
use OCA\UPschooling\Service\TicketService;
use OCP\AppFramework\Db\DoesNotExistException;
use PHPUnit\Framework\TestCase;
+use Psr\Log\NullLogger;
class NoteServiceTest extends TestCase {
+
+ /** @var TicketService */
private $service;
+
+ /** @var MatrixService */
+ private $matrixService;
+
+ /** @var TicketMapper */
private $mapper;
+
+ /** @var string */
private $userId = 'john';
public function setUp(): void {
$this->mapper = $this->getMockBuilder(TicketMapper::class)
->disableOriginalConstructor()
->getMock();
- $this->service = new TicketService($this->mapper);
+ $this->matrixService = new MatrixService(new NullLogger());
+ $this->service = new TicketService($this->matrixService, $this->mapper);
}
public function testUpdate() {