Fetch ticket list from API
This commit is contained in:
parent
70d59ebece
commit
1f14932b28
|
@ -12,7 +12,7 @@
|
||||||
<category>tools</category>
|
<category>tools</category>
|
||||||
<bugs>https://gitea.rs485.network/UPschooling/Nextcloud-App/issues</bugs>
|
<bugs>https://gitea.rs485.network/UPschooling/Nextcloud-App/issues</bugs>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<nextcloud min-version="15" max-version="22"/>
|
<nextcloud min-version="20" max-version="22"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<navigations>
|
<navigations>
|
||||||
<navigation>
|
<navigation>
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'resources' => [
|
'resources' => [
|
||||||
'ticket_api' => ['url' => '/api/v1/ticket']
|
'ticket_api' => ['url' => '/api/v1/tickets']
|
||||||
],
|
],
|
||||||
'routes' => [
|
'routes' => [
|
||||||
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
||||||
[
|
[
|
||||||
'name' => 'ticket_api#preflighted_cors',
|
'name' => 'ticket_api#preflighted_cors',
|
||||||
'url' => '/api/v1/{path}',
|
'url' => '/api/v1/tickets',
|
||||||
'verb' => 'OPTIONS',
|
'verb' => 'OPTIONS',
|
||||||
'requirements' => ['path' => '.+'],
|
'requirements' => ['path' => '.+'],
|
||||||
],
|
],
|
||||||
|
|
|
@ -8,7 +8,8 @@ use OCP\AppFramework\ApiController;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
||||||
class TicketApiController extends ApiController {
|
class TicketApiController extends ApiController
|
||||||
|
{
|
||||||
/** @var TicketService */
|
/** @var TicketService */
|
||||||
private $service;
|
private $service;
|
||||||
|
|
||||||
|
@ -17,62 +18,46 @@ class TicketApiController extends ApiController {
|
||||||
|
|
||||||
use Errors;
|
use Errors;
|
||||||
|
|
||||||
public function __construct(IRequest $request,
|
public function __construct(IRequest $request, TicketService $service, $userId)
|
||||||
TicketService $service,
|
{
|
||||||
$userId) {
|
|
||||||
parent::__construct(Application::APP_ID, $request);
|
parent::__construct(Application::APP_ID, $request);
|
||||||
$this->service = $service;
|
$this->service = $service;
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @CORS
|
|
||||||
* @NoCSRFRequired
|
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function index(): DataResponse {
|
public function index(): DataResponse
|
||||||
|
{
|
||||||
return new DataResponse($this->service->findAll($this->userId));
|
return new DataResponse($this->service->findAll($this->userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @CORS
|
|
||||||
* @NoCSRFRequired
|
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function show(int $id): DataResponse {
|
public function show(int $id): DataResponse
|
||||||
|
{
|
||||||
return $this->handleNotFound(function () use ($id) {
|
return $this->handleNotFound(function () use ($id) {
|
||||||
return $this->service->find($id, $this->userId);
|
return $this->service->find($id, $this->userId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function create(string $title, string $content): DataResponse
|
||||||
* @CORS
|
{
|
||||||
* @NoCSRFRequired
|
|
||||||
* @NoAdminRequired
|
|
||||||
*/
|
|
||||||
public function create(string $title, string $content): DataResponse {
|
|
||||||
return new DataResponse($this->service->create($title, $content,
|
return new DataResponse($this->service->create($title, $content,
|
||||||
$this->userId));
|
$this->userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function update(int $id, string $title, string $content): DataResponse
|
||||||
* @CORS
|
{
|
||||||
* @NoCSRFRequired
|
|
||||||
* @NoAdminRequired
|
|
||||||
*/
|
|
||||||
public function update(int $id, string $title,
|
|
||||||
string $content): DataResponse {
|
|
||||||
return $this->handleNotFound(function () use ($id, $title, $content) {
|
return $this->handleNotFound(function () use ($id, $title, $content) {
|
||||||
return $this->service->update($id, $title, $content, $this->userId);
|
return $this->service->update($id, $title, $content, $this->userId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function destroy(int $id): DataResponse
|
||||||
* @CORS
|
{
|
||||||
* @NoCSRFRequired
|
|
||||||
* @NoAdminRequired
|
|
||||||
*/
|
|
||||||
public function destroy(int $id): DataResponse {
|
|
||||||
return $this->handleNotFound(function () use ($id) {
|
return $this->handleNotFound(function () use ($id) {
|
||||||
return $this->service->delete($id, $this->userId);
|
return $this->service->delete($id, $this->userId);
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,11 +31,18 @@ class MatrixService
|
||||||
$this->channel = "#issue:synapse";
|
$this->channel = "#issue:synapse";
|
||||||
$this->client = new MatrixClient("http://synapse:8008");
|
$this->client = new MatrixClient("http://synapse:8008");
|
||||||
$this->token = $this->client->login("upschooling", "secret");
|
$this->token = $this->client->login("upschooling", "secret");
|
||||||
try {
|
// try {
|
||||||
$this->room = $this->client->createRoom($this->channel, false, array());
|
// $this->room = $this->client->createRoom($this->channel, false, array());
|
||||||
} catch (MatrixException $e) {
|
// } catch (MatrixException $createE) {
|
||||||
$this->logger->error("Could not create room ".$this->channel, array('exception' => $e));
|
// 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)
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
51
src/App.vue
51
src/App.vue
|
@ -18,6 +18,7 @@ import AppNavigation from '@nextcloud/vue/dist/Components/AppNavigation'
|
||||||
import TicketList from './components/TicketList'
|
import TicketList from './components/TicketList'
|
||||||
import Ticket from './Ticket'
|
import Ticket from './Ticket'
|
||||||
import '@nextcloud/dialogs/styles/toast.scss'
|
import '@nextcloud/dialogs/styles/toast.scss'
|
||||||
|
import axios from '@nextcloud/axios'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
|
@ -27,6 +28,7 @@ export default {
|
||||||
AppContent,
|
AppContent,
|
||||||
AppNavigation,
|
AppNavigation,
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
|
@ -36,37 +38,32 @@ export default {
|
||||||
*/
|
*/
|
||||||
currentTicket: undefined,
|
currentTicket: undefined,
|
||||||
|
|
||||||
testTickets: [
|
tickets: [],
|
||||||
{
|
|
||||||
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',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
watch: {
|
||||||
/**
|
$route: 'fetchTickets',
|
||||||
* Returns the list of ticket objects the current account has access to.
|
},
|
||||||
*
|
created() {
|
||||||
* @return {Array}
|
this.fetchTickets()
|
||||||
*/
|
|
||||||
tickets() {
|
|
||||||
// TODO: ask API (dont forget permission check in API)
|
|
||||||
return this.testTickets
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
methods: {
|
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) {
|
saveTicket(ticketId, data) {
|
||||||
// TODO send to API (dont forget permission check in API)
|
// TODO send to API (dont forget permission check in API)
|
||||||
console.debug('upschooling', 'saveTicket', ticketId, data)
|
console.debug('upschooling', 'saveTicket', ticketId, data)
|
||||||
|
|
|
@ -4,21 +4,33 @@ namespace Unit\Service;
|
||||||
|
|
||||||
use OCA\UPschooling\Db\MatrixTicket;
|
use OCA\UPschooling\Db\MatrixTicket;
|
||||||
use OCA\UPschooling\Db\TicketMapper;
|
use OCA\UPschooling\Db\TicketMapper;
|
||||||
|
use OCA\UPschooling\Service\MatrixService;
|
||||||
use OCA\UPschooling\Service\NoteNotFound;
|
use OCA\UPschooling\Service\NoteNotFound;
|
||||||
use OCA\UPschooling\Service\TicketService;
|
use OCA\UPschooling\Service\TicketService;
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
|
|
||||||
class NoteServiceTest extends TestCase {
|
class NoteServiceTest extends TestCase {
|
||||||
|
|
||||||
|
/** @var TicketService */
|
||||||
private $service;
|
private $service;
|
||||||
|
|
||||||
|
/** @var MatrixService */
|
||||||
|
private $matrixService;
|
||||||
|
|
||||||
|
/** @var TicketMapper */
|
||||||
private $mapper;
|
private $mapper;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
private $userId = 'john';
|
private $userId = 'john';
|
||||||
|
|
||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
$this->mapper = $this->getMockBuilder(TicketMapper::class)
|
$this->mapper = $this->getMockBuilder(TicketMapper::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$this->service = new TicketService($this->mapper);
|
$this->matrixService = new MatrixService(new NullLogger());
|
||||||
|
$this->service = new TicketService($this->matrixService, $this->mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdate() {
|
public function testUpdate() {
|
||||||
|
|
Loading…
Reference in a new issue