Skip to content

Commit 5739d0d

Browse files
committed
add solidwebhook service
1 parent 246d3f8 commit 5739d0d

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
namespace OCA\Solid\Service;
4+
5+
class SolidWebhookNotFound extends \Exception {
6+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace OCA\Solid\Service;
4+
5+
use Exception;
6+
7+
use OCP\AppFramework\Db\DoesNotExistException;
8+
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
9+
10+
use OCA\Solid\Db\SolidWebhook;
11+
use OCA\Solid\Db\SolidWebhookMapper;
12+
13+
class SolidWebhookService {
14+
15+
/** @var SolidWebhookMapper */
16+
private $mapper;
17+
18+
public function __construct(SolidWebhookMapper $mapper) {
19+
$this->mapper = $mapper;
20+
}
21+
22+
public function findAll(string $webId): array {
23+
return $this->mapper->findAll($webId);
24+
}
25+
26+
public function findByPath(string $path): array {
27+
return $this->mapper->findByPath($path);
28+
}
29+
30+
private function handleException(Exception $e): void {
31+
if ($e instanceof DoesNotExistException ||
32+
$e instanceof MultipleObjectsReturnedException) {
33+
throw new SolidWebhookNotFound($e->getMessage());
34+
} else {
35+
throw $e;
36+
}
37+
}
38+
39+
public function find($webId, $path) {
40+
try {
41+
return $this->mapper->find($webId, $path);
42+
} catch (Exception $e) {
43+
$this->handleException($e);
44+
}
45+
}
46+
47+
public function create($webId, $path, $url, $expiry) {
48+
$webhook = new SolidWebhook();
49+
$webhook->setWebId($webId);
50+
$webhook->setPath($path);
51+
$webHook->setUrl($url);
52+
$webHook->setExpiry($expiry);
53+
return $this->mapper->insert($note);
54+
}
55+
56+
public function delete($webId, $path) {
57+
try {
58+
$webhook = $this->mapper->find($webId, $path);
59+
$this->mapper->delete($webhook);
60+
return $webhook;
61+
} catch (Exception $e) {
62+
$this->handleException($e);
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)