Fetch ticket list from API
This commit is contained in:
parent
70d59ebece
commit
1f14932b28
|
@ -12,7 +12,7 @@
|
|||
<category>tools</category>
|
||||
<bugs>https://gitea.rs485.network/UPschooling/Nextcloud-App/issues</bugs>
|
||||
<dependencies>
|
||||
<nextcloud min-version="15" max-version="22"/>
|
||||
<nextcloud min-version="20" max-version="22"/>
|
||||
</dependencies>
|
||||
<navigations>
|
||||
<navigation>
|
||||
|
|
|
@ -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' => '.+'],
|
||||
],
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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)
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
49
src/App.vue
49
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)
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue