Compare commits
No commits in common. "e66350b72662fc6ba80d30c4063a30308e9e0fc3" and "34a2b8cab17618646067845912e7e730249cf0c2" have entirely different histories.
e66350b726
...
34a2b8cab1
|
@ -1,23 +0,0 @@
|
||||||
# Copyright 2017 Aviral Dasgupta
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
charset=utf-8
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
indent_style = tab
|
|
||||||
indent_size = 2
|
|
||||||
trim_trailing_whitespace = true
|
|
1
composer.lock
generated
1
composer.lock
generated
|
@ -27,6 +27,7 @@
|
||||||
"phpunit/php-code-coverage": "^7.0",
|
"phpunit/php-code-coverage": "^7.0",
|
||||||
"phpunit/phpunit": "^8.5"
|
"phpunit/phpunit": "^8.5"
|
||||||
},
|
},
|
||||||
|
"default-branch": true,
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace OCA\UPschooling\Controller;
|
namespace OCA\UPschooling\Controller;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use OCA\UPschooling\Exceptions\TicketNotFoundException;
|
use OCA\UPschooling\Service\NoteNotFound;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ trait Errors {
|
||||||
protected function handleNotFound(Closure $callback): DataResponse {
|
protected function handleNotFound(Closure $callback): DataResponse {
|
||||||
try {
|
try {
|
||||||
return new DataResponse($callback());
|
return new DataResponse($callback());
|
||||||
} catch (TicketNotFoundException $e) {
|
} catch (NoteNotFound $e) {
|
||||||
$message = ['message' => $e->getMessage()];
|
$message = ['message' => $e->getMessage()];
|
||||||
return new DataResponse($message, Http::STATUS_NOT_FOUND);
|
return new DataResponse($message, Http::STATUS_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,11 @@ class TicketApiController extends ApiController
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function update(int $id): DataResponse
|
public function update(int $id, string $title, string $content): DataResponse
|
||||||
{
|
{
|
||||||
return new DataResponse($this->service->assign($id, $this->userId));
|
return $this->handleNotFound(function () use ($id, $title, $content) {
|
||||||
|
return $this->service->update($id, $title, $content, $this->userId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(int $id): DataResponse
|
public function destroy(int $id): DataResponse
|
||||||
|
|
|
@ -15,22 +15,6 @@ class TicketMapper extends QBMapper
|
||||||
parent::__construct($db, 'upschooling_tickets', MatrixTicket::class);
|
parent::__construct($db, 'upschooling_tickets', MatrixTicket::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id
|
|
||||||
* @return Entity|MatrixTicket
|
|
||||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
|
||||||
* @throws DoesNotExistException
|
|
||||||
*/
|
|
||||||
public function findTicket(int $id): MatrixTicket
|
|
||||||
{
|
|
||||||
/* @var $qb IQueryBuilder */
|
|
||||||
$qb = $this->db->getQueryBuilder();
|
|
||||||
$qb->select('*')
|
|
||||||
->from('upschooling_tickets')
|
|
||||||
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
|
|
||||||
return $this->findEntity($qb);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @param string $userId
|
* @param string $userId
|
||||||
|
@ -38,19 +22,14 @@ class TicketMapper extends QBMapper
|
||||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
||||||
* @throws DoesNotExistException
|
* @throws DoesNotExistException
|
||||||
*/
|
*/
|
||||||
public function findForUser(int $id, MatrixUser $matrixUser): MatrixTicket
|
public function find(int $id, MatrixUser $matrixUser): MatrixTicket
|
||||||
{
|
{
|
||||||
/* @var $qb IQueryBuilder */
|
/* @var $qb IQueryBuilder */
|
||||||
$qb = $this->db->getQueryBuilder();
|
$qb = $this->db->getQueryBuilder();
|
||||||
$qb->select('*')
|
$qb->select('*')
|
||||||
->from('upschooling_tickets')
|
->from('upschooling_tickets')
|
||||||
->where(
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
|
||||||
$qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)),
|
->andWhere($qb->expr()->in($matrixUser->getMatrixUser(), ['matrix_assisted_user', 'matrix_helper_user']));
|
||||||
$qb->expr()->orX(
|
|
||||||
$qb->expr()->eq('matrix_assisted_user', $qb->createNamedParameter($matrixUser->getMatrixUser(), IQueryBuilder::PARAM_STR)),
|
|
||||||
$qb->expr()->eq('matrix_helper_user', $qb->createNamedParameter($matrixUser->getMatrixUser(), IQueryBuilder::PARAM_STR))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return $this->findEntity($qb);
|
return $this->findEntity($qb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,18 +37,13 @@ class TicketMapper extends QBMapper
|
||||||
* @param string $userId
|
* @param string $userId
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function findAllForUser(MatrixUser $matrixUser): array
|
public function findAll(MatrixUser $matrixUser): array
|
||||||
{
|
{
|
||||||
/* @var $qb IQueryBuilder */
|
/* @var $qb IQueryBuilder */
|
||||||
$qb = $this->db->getQueryBuilder();
|
$qb = $this->db->getQueryBuilder();
|
||||||
$qb->select('*')
|
$qb->select('*')
|
||||||
->from('upschooling_tickets')
|
->from('upschooling_tickets')
|
||||||
->where(
|
->where($qb->expr()->in($matrixUser->getMatrixUser(), ['matrix_assisted_user', 'matrix_helper_user']));
|
||||||
$qb->expr()->orX(
|
|
||||||
$qb->expr()->eq('matrix_assisted_user', $qb->createNamedParameter($matrixUser->getMatrixUser(), IQueryBuilder::PARAM_STR)),
|
|
||||||
$qb->expr()->eq('matrix_helper_user', $qb->createNamedParameter($matrixUser->getMatrixUser(), IQueryBuilder::PARAM_STR))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return $this->findEntities($qb);
|
return $this->findEntities($qb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace OCA\UPschooling\Exceptions;
|
|
||||||
|
|
||||||
use OC\OCS\Exception;
|
|
||||||
use OC\OCS\Result;
|
|
||||||
|
|
||||||
class TicketNotFoundException extends Exception
|
|
||||||
{
|
|
||||||
public function __construct($ticketId)
|
|
||||||
{
|
|
||||||
parent::__construct(new Result(null, 404, 'Ticket with id ' . $ticketId . ' not found'));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,16 +11,11 @@ use OCA\UPschooling\Db\MatrixUser;
|
||||||
use OCA\UPschooling\Db\TicketMapper;
|
use OCA\UPschooling\Db\TicketMapper;
|
||||||
use OCA\UPschooling\Db\UserMapper;
|
use OCA\UPschooling\Db\UserMapper;
|
||||||
use OCA\UPschooling\Exceptions\RoomNotFoundException;
|
use OCA\UPschooling\Exceptions\RoomNotFoundException;
|
||||||
use OCA\UPschooling\Exceptions\TicketNotFoundException;
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||||
use OCP\IUserManager;
|
|
||||||
|
|
||||||
class TicketService {
|
class TicketService {
|
||||||
|
|
||||||
/** @var IUserManager $userManager */
|
|
||||||
private $userManager;
|
|
||||||
|
|
||||||
/** @var MatrixService */
|
/** @var MatrixService */
|
||||||
private $matrix;
|
private $matrix;
|
||||||
|
|
||||||
|
@ -30,37 +25,19 @@ class TicketService {
|
||||||
/** @var UserMapper */
|
/** @var UserMapper */
|
||||||
private $userMapper;
|
private $userMapper;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(MatrixService $matrix, TicketMapper $ticketMapper, UserMapper $userMapper) {
|
||||||
IUserManager $userManager,
|
|
||||||
MatrixService $matrix,
|
|
||||||
TicketMapper $ticketMapper,
|
|
||||||
UserMapper $userMapper
|
|
||||||
) {
|
|
||||||
$this->userManager = $userManager;
|
|
||||||
$this->matrix = $matrix;
|
$this->matrix = $matrix;
|
||||||
$this->ticketMapper = $ticketMapper;
|
$this->ticketMapper = $ticketMapper;
|
||||||
$this->userMapper = $userMapper;
|
$this->userMapper = $userMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findAll(string $userId): array {
|
public function findAll(string $userId): array {
|
||||||
$dbTickets = $this->ticketMapper->findAllForUser($this->getOrCreateUser($userId));
|
$dbTickets = $this->ticketMapper->findAll($this->getOrCreateUser($userId));
|
||||||
return array_map(function ($ticket) { return $this->resolveTicket($ticket); }, $dbTickets);
|
return array_map(function ($ticket) { return $this->resolveTicket($ticket); }, $dbTickets);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws MatrixRequestException
|
|
||||||
* @throws MatrixHttpLibException
|
|
||||||
* @throws MultipleObjectsReturnedException
|
|
||||||
* @throws \OCP\DB\Exception
|
|
||||||
* @throws TicketNotFoundException
|
|
||||||
* @throws MatrixException
|
|
||||||
*/
|
|
||||||
public function find($id, $userId): array {
|
public function find($id, $userId): array {
|
||||||
try {
|
return $this->resolveTicket($this->ticketMapper->find($id, $this->getOrCreateUser($userId)));
|
||||||
return $this->resolveTicket($this->ticketMapper->findForUser($id, $this->getOrCreateUser($userId)));
|
|
||||||
} catch (DoesNotExistException $e) {
|
|
||||||
throw new TicketNotFoundException($id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create($title, $content, $userId): array {
|
public function create($title, $content, $userId): array {
|
||||||
|
@ -82,19 +59,6 @@ class TicketService {
|
||||||
return $this->resolveTicket($this->ticketMapper->insert($ticket));
|
return $this->resolveTicket($this->ticketMapper->insert($ticket));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function assign($id, $userId): array{
|
|
||||||
$matrixUser = $this->getOrCreateUser($userId);
|
|
||||||
$ticket = $this->ticketMapper->findTicket($id);
|
|
||||||
$roomID = $ticket->getMatrixRoom();
|
|
||||||
$helperName = $this->userManager->get($userId)->getDisplayName();
|
|
||||||
$this->matrix->setProperty($roomID, "upschooling.ticket", array(
|
|
||||||
"matrixHelperUser" => $matrixUser->getMatrixUser(),
|
|
||||||
"matrixHelperName" => $helperName,
|
|
||||||
));
|
|
||||||
$ticket->setMatrixHelperUser($matrixUser->getMatrixUser());
|
|
||||||
return $this->resolveTicket($this->ticketMapper->update($ticket));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update($id, $title, $content, $userId) {
|
public function update($id, $title, $content, $userId) {
|
||||||
throw new Exception("Not implemented");
|
throw new Exception("Not implemented");
|
||||||
}
|
}
|
||||||
|
@ -104,7 +68,6 @@ class TicketService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* matrixTicketContent has all the syncronized data
|
|
||||||
* @param MatrixTicket $ticket the database object.
|
* @param MatrixTicket $ticket the database object.
|
||||||
* @return array a JSON serializable representation of the resolved ticket, for the frontend.
|
* @return array a JSON serializable representation of the resolved ticket, for the frontend.
|
||||||
*/
|
*/
|
||||||
|
@ -116,17 +79,12 @@ class TicketService {
|
||||||
$title = array_get($matrixTicketContent, "title", "Untitled");
|
$title = array_get($matrixTicketContent, "title", "Untitled");
|
||||||
$description = array_get($matrixTicketContent, "description", "");
|
$description = array_get($matrixTicketContent, "description", "");
|
||||||
$lastModified = $this->matrix->getLastEventDate($ticket->getMatrixRoom());
|
$lastModified = $this->matrix->getLastEventDate($ticket->getMatrixRoom());
|
||||||
$matrixHelperUser = array_get($matrixTicketContent, "matrixHelperUser", "nicht zugewiesen");
|
|
||||||
$matrixHelperName = array_get($matrixTicketContent, "matrixHelperName", $matrixHelperUser);
|
|
||||||
$expirationDate = array_get($matrixTicketContent, "expirationDate", "");
|
|
||||||
return array(
|
return array(
|
||||||
'ticketId' => $ticketId,
|
'ticketId' => $ticketId,
|
||||||
'status' => $ticket->getStatus(),
|
'status' => $ticket->getStatus(),
|
||||||
'lastModified' => $lastModified,
|
'lastModified' => $lastModified,
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'matrixHelperName' => $matrixHelperName,
|
|
||||||
'expirationDate' => $expirationDate
|
|
||||||
);
|
);
|
||||||
} catch (MatrixException | RoomNotFoundException $e) {
|
} catch (MatrixException | RoomNotFoundException $e) {
|
||||||
return array(
|
return array(
|
||||||
|
|
14
src/App.vue
14
src/App.vue
|
@ -61,16 +61,14 @@ export default {
|
||||||
this.tickets.push(response.data)
|
this.tickets.push(response.data)
|
||||||
}
|
}
|
||||||
}).catch(console.error)
|
}).catch(console.error)
|
||||||
axios.get(
|
axios.post(
|
||||||
'api/v1/tickets/1',
|
'api/v1/tickets',
|
||||||
|
{ title: 'Zweites Ticket', content: 'Zweites Beispiel' },
|
||||||
{ headers: { 'Content-Type': 'application/json', Accept: 'application/json' } },
|
{ headers: { 'Content-Type': 'application/json', Accept: 'application/json' } },
|
||||||
).catch(console.error)
|
|
||||||
axios.put(
|
|
||||||
'api/v1/tickets/1',
|
|
||||||
{},
|
|
||||||
{ headers: { 'Content-Type': 'application/json', Accept: 'application/json' } }
|
|
||||||
).then((response) => {
|
).then((response) => {
|
||||||
console.error('added a helper to ticket 2')
|
if (this.ticketsFetched === false) {
|
||||||
|
this.tickets.push(response.data)
|
||||||
|
}
|
||||||
}).catch(console.error)
|
}).catch(console.error)
|
||||||
},
|
},
|
||||||
fetchTickets() {
|
fetchTickets() {
|
||||||
|
|
|
@ -35,7 +35,7 @@ class TicketApiControllerTest extends TestCase
|
||||||
$this->equalTo($this->userId))
|
$this->equalTo($this->userId))
|
||||||
->will($this->returnValue($note));
|
->will($this->returnValue($note));
|
||||||
|
|
||||||
$result = $this->controller->update(3);
|
$result = $this->controller->update(3, 'title', 'content');
|
||||||
|
|
||||||
$this->assertEquals($note, $result->getData());
|
$this->assertEquals($note, $result->getData());
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class TicketApiControllerTest extends TestCase
|
||||||
->method('update')
|
->method('update')
|
||||||
->will($this->throwException(new NoteNotFound()));
|
->will($this->throwException(new NoteNotFound()));
|
||||||
|
|
||||||
$result = $this->controller->update(3);
|
$result = $this->controller->update(3, 'title', 'content');
|
||||||
|
|
||||||
$this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus());
|
$this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus());
|
||||||
}*/
|
}*/
|
||||||
|
|
Loading…
Reference in a new issue