Skip to content

feat(MassDelete) #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,27 @@ Retrieve a whole set of records in one call

For example, `http://localhost:8080/mass/retrieve/1084,1092` Note that all the IDs must belong to the same module.

### Mass Delete (DELETE)

Delete a whole set of records in one call

`http://yourapplication.tld/mass/delete/{ids}`

For example, `http://localhost:8080/mass/delete/1084,1092`

```json
{
"success": true,
"result": {
"success_deletes": [
"12x1084",
"12x1092"
],
"failed_deletes": []
}
}
```

## Future tasks

There are a lot of things we can add. More operations from our web service API, paging on the query and list, custom API endpoints, ... but this project defines the path of how (officialy) we will support a RESTful API on top of all the awesome functionality EvolutivoFW and coreBOS provide!
2 changes: 1 addition & 1 deletion app/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function (RouteCollectorProxy $group) {
// $group->post('create', [MassOps::class, 'create']);
$group->get('retrieve/'.SPEC_IDS, [MassOps::class, 'list']);
// $group->patch('update', [MassOps::class, 'update']);
// $group->delete('delete/'.SPEC_IDS, [MassOps::class, 'delete']);
$group->delete('delete/'.SPEC_IDS, [MassOps::class, 'delete']);
}
)->add(RequireAPIKey::class)->add(AddJsonResponseHeader::class);

Expand Down
6 changes: 6 additions & 0 deletions app/src/App/Controllers/MassOps.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public function list(Request $request, Response $response, array $args): Respons
return $response->withStatus($this->getResponseCode($rdo['success']));
}

public function delete(Request $request, Response $response, array $args): Response {
$rdo = $this->repository->delete(self::getAPIKey($request), $args['ids']);
$response = $this->writeOutput($response, $rdo);
return $response->withStatus($this->getResponseCode($rdo['success']));
}

private function writeOutput(Response $response, array $output): Response {
$response->getBody()->write(json_encode($output));
return $response;
Expand Down
14 changes: 14 additions & 0 deletions app/src/App/Repositories/MassOpsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ public function getAll(string $apikey, string $ids): array {
return $rdo;
}

public function delete(string $apikey, string $ids): array {
$cb = new WSClient($_ENV['cburl'], $apikey);
$rdo = $cb->doMassDelete($ids);
if ($rdo === false) {
$rdo = $this->getErrorResponse('Record not found', 'INVALID_ID_ATTRIBUTE');
} else {
$rdo = [
'success' => true,
'result' => $rdo,
];
}
return $rdo;
}

private function getErrorResponse(string $msg, string $code): array {
return [
'success' => false,
Expand Down