logger = $logger; $this->ticketService = $ticketService; $this->ticketMapper = $ticketMapper; $this->matrixService = $matrixService; $this->chatService = $chatService; $this->userId = $userId; } /** * @CORS * @NoCSRFRequired * @NoAdminRequired */ public function index(): DataResponse { return new DataResponse($this->ticketService->findAll($this->userId)); } /** * @CORS * @NoCSRFRequired * @NoAdminRequired */ public function show(int $id): DataResponse { return $this->handleNotFound(function () use ($id) { return $this->ticketService->find($id, $this->userId); }); } /** * @CORS * @NoCSRFRequired * @NoAdminRequired */ public function fetchChat(int $id): DataResponse { return $this->handleNotFound(function () use ($id) { $matrixUser = $this->ticketService->getOrCreateUser($this->userId); $ticket = $this->ticketMapper->findForUser($id, $matrixUser); $this->logger->debug("fetchChat found matrix data for ticket " . print_r($ticket->jsonSerialize(), true)); // returns 404 RoomNotFoundException if no room could/should be created $chatRoom = $this->chatService->getOrCreateChatRoom($ticket); $this->logger->debug("fetchChat got chat room " . print_r($chatRoom->jsonSerialize(), true)); return array( 'matrixChatRoom' => $chatRoom->getMatrixRoomId(), 'matrixAccessToken' => $matrixUser->getMatrixToken(), 'matrixServerUrl' => $this->matrixService->getServerUrl(), ); }); } /** * @CORS * @NoCSRFRequired * @NoAdminRequired */ public function create(string $title, string $content): DataResponse { return new DataResponse($this->ticketService->create($title, $content, $this->userId)); } /** * @CORS * @NoCSRFRequired * @NoAdminRequired */ public function update(int $id): DataResponse { return new DataResponse($this->ticketService->assign($id, $this->userId)); } public function destroy(int $id): DataResponse { return $this->handleNotFound(function () use ($id) { return $this->ticketService->delete($id, $this->userId); }); } }