Skip to content

Commit

Permalink
fix: TemplateFieldService can use either Node or file ID
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Jul 9, 2024
1 parent 0c5d85f commit 25a479a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/Service/TemplateFieldService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@
namespace OCA\Richdocuments\Service;

use OCA\Richdocuments\AppConfig;
use OCA\Richdocuments\TemplateManager;
use OCP\Files\Node;
use OCP\Http\Client\IClientService;

class TemplateFieldService {
private IClientService $clientService;
private AppConfig $appConfig;
private TemplateManager $templateManager;

public function __construct(
IClientService $clientService,
AppConfig $appConfig
AppConfig $appConfig,
TemplateManager $templateManager
) {
$this->clientService = $clientService;
$this->appConfig = $appConfig;
$this->templateManager = $templateManager;
}

public function extractFields(Node $file): ?array {
// TODO: Won't work until Collabora's endpoint is ready
public function extractFields(Node|int $file): ?array {
if (is_int($file)) {
$file = $this->templateManager->get($file);
}

$collaboraUrl = $this->appConfig->getCollaboraUrlInternal();
$httpClient = $this->clientService->newClient();

Expand All @@ -36,11 +43,16 @@ public function extractFields(Node $file): ?array {

return [$response->getBody()];
} catch (\Exception $e) {
// handle exception
return null;
}
}

public function fillFields(Node $file, array $fieldValues): void {
public function fillFields(Node|int $file, array $fieldValues): void {
if (is_int($file)) {
$file = $this->templateManager->get($file);
}

$collaboraUrl = $this->appConfig->getCollaboraUrlInternal();
$httpClient = $this->clientService->newClient();

Expand Down

0 comments on commit 25a479a

Please sign in to comment.