Skip to content

Commit 99a174f

Browse files
committed
refactor: move formatVisibleElements to FileElementService\n\nDelegateFormatVisibleElements logic to FileElementService to centralize file element formatting and remove duplication.
Signed-off-by: Vitor Mattos <[email protected]>
1 parent db3151a commit 99a174f

1 file changed

Lines changed: 8 additions & 45 deletions

File tree

lib/Service/File/FileListService.php

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@
1010

1111
use DateTimeInterface;
1212
use OCA\Libresign\AppInfo\Application;
13-
use OCA\Libresign\Db\FileElement;
1413
use OCA\Libresign\Db\FileMapper;
1514
use OCA\Libresign\Db\IdentifyMethod;
1615
use OCA\Libresign\Db\SignRequestMapper;
16+
use OCA\Libresign\ResponseDefinitions;
17+
use OCA\Libresign\Service\FileElementService;
1718
use OCA\Libresign\Service\IdentifyMethodService;
1819
use OCP\IAppConfig;
1920
use OCP\IL10N;
2021
use OCP\IURLGenerator;
2122
use OCP\IUser;
2223

2324
/**
24-
* Service for formatting file list responses with visible elements.
25+
* @psalm-import-type LibresignVisibleElement from ResponseDefinitions
2526
*/
2627
class FileListService {
2728
public function __construct(
2829
private SignRequestMapper $signRequestMapper,
2930
private IdentifyMethodService $identifyMethodService,
31+
private FileElementService $fileElementService,
3032
private FileMapper $fileMapper,
3133
private IURLGenerator $urlGenerator,
3234
private IAppConfig $appConfig,
@@ -117,7 +119,10 @@ private function associateAllAndFormat(IUser $user, array $files, array $signers
117119
}, false),
118120
'visibleElements'
119121
=> $visibleElements[$signer->getId()]
120-
? $this->formatVisibleElements($visibleElements[$signer->getId()])
122+
? $this->fileElementService->formatVisibleElements(
123+
$visibleElements[$signer->getId()],
124+
$file['metadata'],
125+
)
121126
: [],
122127
'identifyMethods' => array_map(fn (IdentifyMethod $identifyMethod): array => [
123128
'method' => $identifyMethod->getIdentifierKey(),
@@ -186,46 +191,4 @@ private function associateAllAndFormat(IUser $user, array $files, array $signers
186191
}
187192
return $files;
188193
}
189-
190-
/**
191-
* Format visible elements for file list response.
192-
*
193-
* @param FileElement[] $visibleElements Array of FileElement objects
194-
* @param array $metadata File metadata containing page dimensions
195-
* @param string $uuid File UUID to include in response
196-
* @return array Formatted visible elements
197-
*/
198-
public function formatVisibleElements(array $visibleElements): array {
199-
return array_map(function ($visibleElement) {
200-
$page = $visibleElement['page'];
201-
$urx = (int)$visibleElement['urx'];
202-
$ury = (int)$visibleElement['ury'];
203-
$llx = (int)$visibleElement['llx'];
204-
$lly = (int)$visibleElement['lly'];
205-
206-
$dimension = $visibleElement['metadata']['d'][$page - 1];
207-
$height = abs($ury - $lly);
208-
$width = $urx - $llx;
209-
$top = (int)$dimension['h'] - $ury;
210-
$left = $llx;
211-
212-
return [
213-
'elementId' => $visibleElement['id'],
214-
'signRequestId' => $visibleElement['sign_request_id'],
215-
'type' => $visibleElement['type'],
216-
'fileId' => $visibleElement['file_id'],
217-
'coordinates' => [
218-
'page' => $page,
219-
'urx' => $urx,
220-
'ury' => $ury,
221-
'llx' => $llx,
222-
'lly' => $lly,
223-
'left' => $left,
224-
'top' => $top,
225-
'width' => $width,
226-
'height' => $height,
227-
],
228-
];
229-
}, $visibleElements);
230-
}
231194
}

0 commit comments

Comments
 (0)