Skip to content

Commit 12c6705

Browse files
committed
feat: migration tous les services entrepôt vers le nouveau ApiClient
1 parent 0b92b3c commit 12c6705

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+639
-669
lines changed

src/Controller/ContactController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function contact(Request $request): JsonResponse
7575
];
7676

7777
if ($user instanceof User) {
78-
$userApi = $this->userApiService->getMe();
78+
$userApi = $this->userApiService->getMe()->json();
7979
$supportMailParams['userId'] = $userApi['_id'];
8080
}
8181

@@ -116,7 +116,7 @@ public function datastoreCreateRequest(Request $request): JsonResponse
116116
$supervisor = []; // Liste des community dont l'utilisateur courant est "supervisor"
117117
$member = []; // Liste des community dont l'utilisateur courant est simple membre
118118
if ($user instanceof User) {
119-
$userApi = $this->userApiService->getMe();
119+
$userApi = $this->userApiService->getMe()->json();
120120
foreach ($userApi['communities_member'] as $communityMember) {
121121
$community = $communityMember['community'];
122122
if ($userApi['_id'] === $community['supervisor']) {

src/Controller/Entrepot/AnnexeController.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public function getList(
6868
}
6969

7070
$apiResponse = $this->annexeApiService->getList($datastoreId, $query);
71-
$response = new JsonResponse($apiResponse['content'], Response::HTTP_OK);
72-
$this->setPaginatedHeaders($response, $apiResponse['headers'] ?? []);
71+
$response = new JsonResponse($apiResponse->content, Response::HTTP_OK);
72+
$this->setPaginatedHeaders($response, $apiResponse->headers);
7373

7474
return $response;
7575
} catch (ApiException $ex) {
@@ -90,7 +90,7 @@ public function modify(string $datastoreId, string $annexeId, Request $request):
9090
$data['paths'] ?? null,
9191
$data['labels'] ?? null,
9292
$data['published'] ?? null
93-
)
93+
)->json()
9494
);
9595
} catch (ApiException $ex) {
9696
throw new CartesApiException($ex->getMessage(), $ex->getStatusCode(), $ex->getDetails());
@@ -120,7 +120,7 @@ public function add(string $datastoreId, Request $request): JsonResponse
120120
public function getFileContent(string $datastoreId, string $annexeId): Response
121121
{
122122
try {
123-
$fileContent = $this->annexeApiService->download($datastoreId, $annexeId);
123+
$fileContent = $this->annexeApiService->download($datastoreId, $annexeId)->text();
124124

125125
$response = new Response($fileContent);
126126
$response->headers->set('Content-Type', Utils::guess_content_type($fileContent));
@@ -179,7 +179,7 @@ public function addThumbnail(string $datastoreId, Request $request): JsonRespons
179179
$annexes = $this->annexeApiService->getAll($datastoreId, null, null, $labels);
180180

181181
if (count($annexes)) { // Elle existe, on la supprime sinon le path ne change pas
182-
$this->annexeApiService->remove($datastoreId, $annexes[0]['_id']);
182+
$this->annexeApiService->remove($datastoreId, $annexes[0]['_id'])->wait();
183183
}
184184

185185
$annexe = $this->annexeApiService->add($datastoreId, $file->getRealPath(), [$path], $labels);
@@ -191,7 +191,7 @@ public function addThumbnail(string $datastoreId, Request $request): JsonRespons
191191
return new JsonResponse($annexe);
192192
}
193193

194-
$xmlFileContent = $this->metadataApiService->downloadFile($datastoreId, $metadata['_id']);
194+
$xmlFileContent = $this->metadataApiService->downloadFile($datastoreId, $metadata['_id'])->text();
195195
$cswMetadata = $this->metadataHelper->fromXml($xmlFileContent);
196196
$cswMetadata->thumbnailUrl = $annexe['url'];
197197

@@ -215,7 +215,7 @@ public function deleteThumbnail(string $datastoreId, string $datasheetName, stri
215215
return $response;
216216
}
217217

218-
$xmlFileContent = $this->metadataApiService->downloadFile($datastoreId, $metadata['_id']);
218+
$xmlFileContent = $this->metadataApiService->downloadFile($datastoreId, $metadata['_id'])->text();
219219
$cswMetadata = $this->metadataHelper->fromXml($xmlFileContent);
220220
$cswMetadata->thumbnailUrl = null;
221221

@@ -229,7 +229,7 @@ public function deleteThumbnail(string $datastoreId, string $datasheetName, stri
229229
public function deleteAnnexe(string $datastoreId, string $annexeId): JsonResponse
230230
{
231231
try {
232-
$this->annexeApiService->remove($datastoreId, $annexeId);
232+
$this->annexeApiService->remove($datastoreId, $annexeId)->wait();
233233

234234
return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);
235235
} catch (ApiException $ex) {

src/Controller/Entrepot/CommunityController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
public function get(string $communityId): JsonResponse
3636
{
3737
try {
38-
$community = $this->communityApiService->get($communityId);
38+
$community = $this->communityApiService->get($communityId)->json();
3939
$community['is_sandbox'] = $this->sandboxService->isSandboxCommunity($community['_id']);
4040

4141
return new JsonResponse($community);
@@ -49,7 +49,7 @@ public function modify(string $communityId, Request $request): JsonResponse
4949
{
5050
try {
5151
$data = json_decode($request->getContent(), true);
52-
$community = $this->communityApiService->modifyCommunity($communityId, $data);
52+
$community = $this->communityApiService->modifyCommunity($communityId, $data)->json();
5353
$community['is_sandbox'] = $this->sandboxService->isSandboxCommunity($community['_id']);
5454

5555
return new JsonResponse($community);
@@ -74,7 +74,7 @@ public function getMembers(string $communityId): JsonResponse
7474
public function updateMember(string $communityId, Request $request): JsonResponse
7575
{
7676
try {
77-
$me = $this->userApiService->getMe();
77+
$me = $this->userApiService->getMe()->json();
7878

7979
// Suis-je membre de cette communaute
8080
$communityMember = array_values(array_filter($me['communities_member'], function ($member) use ($communityId) {
@@ -106,7 +106,7 @@ public function updateMember(string $communityId, Request $request): JsonRespons
106106
// Verification des droits
107107
$this->_checkRights($rights);
108108

109-
$this->communityApiService->addOrModifyUserRights($communityId, $userId, ['rights' => $rights]);
109+
$this->communityApiService->addOrModifyUserRights($communityId, $userId, ['rights' => $rights])->wait();
110110

111111
return new JsonResponse([
112112
'user' => $userId,
@@ -121,7 +121,7 @@ public function updateMember(string $communityId, Request $request): JsonRespons
121121
public function removeMember(string $communityId, Request $request): JsonResponse
122122
{
123123
try {
124-
$me = $this->userApiService->getMe();
124+
$me = $this->userApiService->getMe()->json();
125125

126126
// Suis-je membre de cette communaute
127127
$communityMember = array_values(array_filter($me['communities_member'], function ($member) use ($communityId) {
@@ -139,7 +139,7 @@ public function removeMember(string $communityId, Request $request): JsonRespons
139139
throw new CartesApiException("Vous n'avez pas les droits pour supprimer un membre de cette communauté", JsonResponse::HTTP_BAD_REQUEST);
140140
}
141141

142-
$this->communityApiService->removeUserRights($communityId, $userId);
142+
$this->communityApiService->removeUserRights($communityId, $userId)->wait();
143143

144144
return new JsonResponse(['user' => $userId]);
145145
} catch (ApiException $ex) {

src/Controller/Entrepot/DatasheetController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public function delete(string $datastoreId, string $datasheetName): Response
272272
// suppr des uploads
273273
if (isset($datasheet['upload_list'])) {
274274
foreach ($datasheet['upload_list'] as $upload) {
275-
$this->uploadApiService->remove($datastoreId, $upload['_id']);
275+
$this->uploadApiService->remove($datastoreId, $upload['_id'])->wait();
276276
}
277277
}
278278

@@ -306,17 +306,17 @@ public function delete(string $datastoreId, string $datasheetName): Response
306306
$metadata = $metadataList[0];
307307

308308
foreach ($metadata['endpoints'] as $metadataEndpoint) {
309-
$this->metadataApiService->unpublish($datastoreId, $metadata['file_identifier'], $metadataEndpoint['_id']);
309+
$this->metadataApiService->unpublish($datastoreId, $metadata['file_identifier'], $metadataEndpoint['_id'])->wait();
310310
}
311311

312-
$this->metadataApiService->delete($datastoreId, $metadata['_id']);
312+
$this->metadataApiService->delete($datastoreId, $metadata['_id'])->wait();
313313
}
314314

315315
// TODO : autres données à supprimer
316316
// Suppression des annexes : vignette, documents associés à la fiche de données etc
317317
$annexes = $this->annexeApiService->getAll($datastoreId, null, null, ["datasheet_name=$datasheetName"]);
318318
foreach ($annexes as $annexe) {
319-
$this->annexeApiService->remove($datastoreId, $annexe['_id']);
319+
$this->annexeApiService->remove($datastoreId, $annexe['_id'])->wait();
320320
}
321321

322322
return new JsonResponse(null, Response::HTTP_NO_CONTENT);

src/Controller/Entrepot/DatasheetDocumentController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getDocumentList(string $datastoreId, string $datasheetName): Jso
4848
try {
4949
$listAnnexe = $this->getListAnnexe($datastoreId, $datasheetName);
5050

51-
$docsListJson = $this->annexeApiService->download($datastoreId, $listAnnexe['_id']);
51+
$docsListJson = $this->annexeApiService->download($datastoreId, $listAnnexe['_id'])->text();
5252
$documentsList = json_decode($docsListJson, true);
5353

5454
return $this->json($documentsList);
@@ -72,7 +72,7 @@ public function add(string $datastoreId, string $datasheetName, Request $request
7272
/** @var array<mixed> $listAnnexe entité annexe de l'API entrepôt */
7373
$listAnnexe = $this->getListAnnexe($datastoreId, $datasheetName);
7474

75-
$docsListJson = $this->annexeApiService->download($datastoreId, $listAnnexe['_id']);
75+
$docsListJson = $this->annexeApiService->download($datastoreId, $listAnnexe['_id'])->text();
7676
$documentsList = json_decode($docsListJson, true);
7777

7878
$newDocument = [
@@ -137,7 +137,7 @@ public function edit(string $datastoreId, string $datasheetName, string $documen
137137

138138
$listAnnexe = $this->getListAnnexe($datastoreId, $datasheetName);
139139

140-
$docsListJson = $this->annexeApiService->download($datastoreId, $listAnnexe['_id']);
140+
$docsListJson = $this->annexeApiService->download($datastoreId, $listAnnexe['_id'])->text();
141141
$documentsList = json_decode($docsListJson, true);
142142

143143
$documentsList = array_map(function ($document) use ($documentId, $data) {
@@ -174,7 +174,7 @@ public function delete(string $datastoreId, string $datasheetName, string $docum
174174
try {
175175
$listAnnexe = $this->getListAnnexe($datastoreId, $datasheetName);
176176

177-
$docsListJson = $this->annexeApiService->download($datastoreId, $listAnnexe['_id']);
177+
$docsListJson = $this->annexeApiService->download($datastoreId, $listAnnexe['_id'])->text();
178178
$initialDocumentsList = json_decode($docsListJson, true);
179179

180180
// document à supprimer
@@ -189,7 +189,7 @@ public function delete(string $datastoreId, string $datasheetName, string $docum
189189
if (null !== $document) {
190190
switch ($document['type']) {
191191
case 'file':
192-
$this->annexeApiService->remove($datastoreId, $document['id']);
192+
$this->annexeApiService->remove($datastoreId, $document['id'])->wait();
193193
break;
194194
}
195195

src/Controller/Entrepot/DatastoreController.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,14 @@ public function getPermissions(string $datastoreId, Request $request): JsonRespo
9292
#[Route('/{datastoreId}/permission/{permissionId}', name: 'get_permission', methods: ['GET'])]
9393
public function getPermission(string $datastoreId, string $permissionId): JsonResponse
9494
{
95-
$permission = $this->datastoreApiService->getPermission($datastoreId, $permissionId);
95+
$permission = $this->datastoreApiService->getPermission($datastoreId, $permissionId)->json();
9696

9797
return $this->json($permission);
9898
}
9999

100100
#[Route('/{datastoreId}/add_permission', name: 'add_permission', methods: ['POST'],
101101
options: ['expose' => true],
102-
condition: 'request.isXmlHttpRequest()')
103-
]
102+
condition: 'request.isXmlHttpRequest()')]
104103
public function addPermission(string $datastoreId, #[MapRequestPayload] PermissionDTO $dto): JsonResponse
105104
{
106105
$body = json_decode(json_encode($dto), true);
@@ -112,20 +111,19 @@ public function addPermission(string $datastoreId, #[MapRequestPayload] Permissi
112111
unset($body['beneficiaries']);
113112

114113
// Ajout de la permission
115-
$permission = $this->datastoreApiService->addPermission($datastoreId, $body);
114+
$permission = $this->datastoreApiService->addPermission($datastoreId, $body)->json();
116115

117116
return $this->json($permission);
118117
}
119118

120119
#[Route('{datastoreId}/update_permission/{permissionId}', name: 'update_permission', methods: ['PATCH'],
121120
options: ['expose' => true],
122-
condition: 'request.isXmlHttpRequest()')
123-
]
121+
condition: 'request.isXmlHttpRequest()')]
124122
public function updatePermission(string $datastoreId, string $permissionId, #[MapRequestPayload] UpdatePermissionDTO $dto): JsonResponse
125123
{
126124
try {
127125
$body = json_decode(json_encode($dto), true);
128-
$permission = $this->datastoreApiService->updatePermission($datastoreId, $permissionId, $body);
126+
$permission = $this->datastoreApiService->updatePermission($datastoreId, $permissionId, $body)->json();
129127

130128
return $this->json($permission);
131129
} catch (ApiException $ex) {
@@ -135,12 +133,11 @@ public function updatePermission(string $datastoreId, string $permissionId, #[Ma
135133

136134
#[Route('{datastoreId}/remove_permission/{permissionId}', name: 'remove_permission', methods: ['DELETE'],
137135
options: ['expose' => true],
138-
condition: 'request.isXmlHttpRequest()')
139-
]
136+
condition: 'request.isXmlHttpRequest()')]
140137
public function removePermission(string $datastoreId, string $permissionId): JsonResponse
141138
{
142139
try {
143-
$this->datastoreApiService->removePermission($datastoreId, $permissionId);
140+
$this->datastoreApiService->removePermission($datastoreId, $permissionId)->wait();
144141

145142
return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);
146143
} catch (ApiException $ex) {

src/Controller/Entrepot/MetadataController.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function add(string $datastoreId, Request $request): JsonResponse
6363
if (null !== $datasheetName) {
6464
$metadata = $this->metadataApiService->addTags($datastoreId, $metadata['_id'], [
6565
CommonTags::DATASHEET_NAME => $datasheetName,
66-
]);
66+
])->json();
6767
}
6868

6969
return $this->json($metadata);
@@ -78,9 +78,9 @@ public function add(string $datastoreId, Request $request): JsonResponse
7878
public function get(string $datastoreId, string $metadataId): JsonResponse
7979
{
8080
try {
81-
$metadata = $this->metadataApiService->get($datastoreId, $metadataId);
81+
$metadata = $this->metadataApiService->get($datastoreId, $metadataId)->json();
8282

83-
$fileContent = $this->metadataApiService->downloadFile($datastoreId, $metadata['_id']);
83+
$fileContent = $this->metadataApiService->downloadFile($datastoreId, $metadata['_id'])->text();
8484
$metadata['csw_metadata'] = $this->cswMetadataHelper->fromXml($fileContent);
8585

8686
return $this->json($metadata);
@@ -107,7 +107,7 @@ public function getByDatasheetName(string $datastoreId, string $datasheetName):
107107

108108
$metadata = $metadataList[0];
109109

110-
$fileContent = $this->metadataApiService->downloadFile($datastoreId, $metadata['_id']);
110+
$fileContent = $this->metadataApiService->downloadFile($datastoreId, $metadata['_id'])->text();
111111

112112
$metadata['csw_metadata'] = $this->cswMetadataHelper->fromXml($fileContent);
113113

@@ -121,8 +121,8 @@ public function getByDatasheetName(string $datastoreId, string $datasheetName):
121121
public function getFileContent(string $datastoreId, string $metadataId, Request $request): Response
122122
{
123123
try {
124-
$metadata = $this->metadataApiService->get($datastoreId, $metadataId);
125-
$xmlFileContent = $this->metadataApiService->downloadFile($datastoreId, $metadata['_id']);
124+
$metadata = $this->metadataApiService->get($datastoreId, $metadataId)->json();
125+
$xmlFileContent = $this->metadataApiService->downloadFile($datastoreId, $metadata['_id'])->text();
126126

127127
$format = $request->query->get('format', 'xml');
128128

@@ -146,7 +146,7 @@ public function getFileContent(string $datastoreId, string $metadataId, Request
146146
public function delete(string $datastoreId, string $metadataId): JsonResponse
147147
{
148148
try {
149-
$this->metadataApiService->delete($datastoreId, $metadataId);
149+
$this->metadataApiService->delete($datastoreId, $metadataId)->wait();
150150

151151
return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);
152152
} catch (ApiException $ex) {
@@ -160,11 +160,11 @@ public function delete(string $datastoreId, string $metadataId): JsonResponse
160160
public function unpublish(string $datastoreId, string $metadataId): JsonResponse
161161
{
162162
try {
163-
$metadata = $this->metadataApiService->get($datastoreId, $metadataId);
163+
$metadata = $this->metadataApiService->get($datastoreId, $metadataId)->json();
164164

165165
$endpointId = $metadata['endpoints'][0]['_id'] ?? null;
166166
if (null !== $endpointId) {
167-
$this->metadataApiService->unpublish($datastoreId, $metadata['file_identifier'], $endpointId);
167+
$this->metadataApiService->unpublish($datastoreId, $metadata['file_identifier'], $endpointId)->wait();
168168
}
169169

170170
return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);

0 commit comments

Comments
 (0)