Compare commits

...

11 commits

4 changed files with 41 additions and 7 deletions

View file

@ -54,11 +54,9 @@ class TicketApiController extends ApiController
/**
* @NoAdminRequired
*/
public function update(int $id, string $title, string $content): DataResponse
public function update(int $id): DataResponse
{
return $this->handleNotFound(function () use ($id, $title, $content) {
return $this->service->update($id, $title, $content, $this->userId);
});
return new DataResponse($this->service->assign($id, $this->userId));
}
public function destroy(int $id): DataResponse

View file

@ -14,9 +14,13 @@ use OCA\UPschooling\Exceptions\RoomNotFoundException;
use OCA\UPschooling\Exceptions\TicketNotFoundException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IUserManager;
class TicketService {
/** @var IUserManager $userManager */
private $userManager;
/** @var MatrixService */
private $matrix;
@ -26,7 +30,13 @@ class TicketService {
/** @var UserMapper */
private $userMapper;
public function __construct(MatrixService $matrix, TicketMapper $ticketMapper, UserMapper $userMapper) {
public function __construct(
IUserManager $userManager,
MatrixService $matrix,
TicketMapper $ticketMapper,
UserMapper $userMapper
) {
$this->userManager = $userManager;
$this->matrix = $matrix;
$this->ticketMapper = $ticketMapper;
$this->userMapper = $userMapper;
@ -72,6 +82,19 @@ class TicketService {
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) {
throw new Exception("Not implemented");
}
@ -81,6 +104,7 @@ class TicketService {
}
/**
* matrixTicketContent has all the syncronized data
* @param MatrixTicket $ticket the database object.
* @return array a JSON serializable representation of the resolved ticket, for the frontend.
*/
@ -92,12 +116,17 @@ class TicketService {
$title = array_get($matrixTicketContent, "title", "Untitled");
$description = array_get($matrixTicketContent, "description", "");
$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(
'ticketId' => $ticketId,
'status' => $ticket->getStatus(),
'lastModified' => $lastModified,
'title' => $title,
'description' => $description,
'matrixHelperName' => $matrixHelperName,
'expirationDate' => $expirationDate
);
} catch (MatrixException | RoomNotFoundException $e) {
return array(

View file

@ -65,6 +65,13 @@ export default {
'api/v1/tickets/1',
{ 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) => {
console.error('added a helper to ticket 2')
}).catch(console.error)
},
fetchTickets() {
axios.get(

View file

@ -36,7 +36,7 @@ class NoteApiControllerTest extends TestCase
$this->equalTo($this->userId))
->will($this->returnValue($note));
$result = $this->controller->update(3, 'title', 'content');
$result = $this->controller->update(3);
$this->assertEquals($note, $result->getData());
}
@ -49,7 +49,7 @@ class NoteApiControllerTest extends TestCase
->method('update')
->will($this->throwException(new NoteNotFound()));
$result = $this->controller->update(3, 'title', 'content');
$result = $this->controller->update(3);
$this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus());
}