-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from ConductionNL/feature/CONNECTOR-136/up-do…
…wnload-endpoints Import & export for OpenConnector
- Loading branch information
Showing
17 changed files
with
923 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace OCA\OpenConnector\Controller; | ||
|
||
use OCA\OpenConnector\Service\ExportService; | ||
use OCP\AppFramework\Controller; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\IAppConfig; | ||
use OCP\IRequest; | ||
|
||
class ExportController extends Controller | ||
{ | ||
/** | ||
* Constructor for the ExportController | ||
* | ||
* @param string $appName The name of the app | ||
* @param IRequest $request The request object | ||
* @param IAppConfig $config The app configuration object | ||
* @param ExportService $exportService The Export Service. | ||
*/ | ||
public function __construct( | ||
$appName, | ||
IRequest $request, | ||
private IAppConfig $config, | ||
private readonly ExportService $exportService | ||
) | ||
{ | ||
parent::__construct($appName, $request); | ||
} | ||
|
||
/** | ||
* Creates and return a json file for a specific object. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @param string $type The object type we want to export an object for. | ||
* @param string $id The id used to find an existing object to export. | ||
* | ||
* @return JSONResponse | ||
*/ | ||
public function export(string $type, string $id): JSONResponse | ||
{ | ||
$accept = $this->request->getHeader(name: 'Accept'); | ||
|
||
if (empty($accept) === true) { | ||
return new JSONResponse(data: ['error' => 'Request is missing header Accept'], statusCode: 400); | ||
} | ||
|
||
return $this->exportService->export(objectType: $type, id: $id, accept: $accept); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace OCA\OpenConnector\Controller; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use OCA\OpenConnector\Service\ImportService; | ||
use OCP\AppFramework\Controller; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\IAppConfig; | ||
use OCP\IRequest; | ||
|
||
class ImportController extends Controller | ||
{ | ||
/** | ||
* Constructor for the ImportController | ||
* | ||
* @param string $appName The name of the app | ||
* @param IRequest $request The request object | ||
* @param IAppConfig $config The app configuration object | ||
* @param ImportService $importService The Import Service. | ||
*/ | ||
public function __construct( | ||
$appName, | ||
IRequest $request, | ||
private IAppConfig $config, | ||
private readonly ImportService $importService | ||
) | ||
{ | ||
parent::__construct($appName, $request); | ||
} | ||
|
||
/** | ||
* Creates a new object or updates an existing one using a json text/string as input. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @return JSONResponse | ||
* @throws GuzzleException | ||
*/ | ||
public function import(): JSONResponse | ||
{ | ||
$data = $this->request->getParams(); | ||
$uploadedFiles = []; | ||
|
||
// Check if multiple files have been uploaded. | ||
$files = $_FILES['files'] ?? null; | ||
|
||
if (empty($files) === false) { | ||
// Loop through each file using the count of 'name' | ||
for ($i = 0; $i < count($files['name']); $i++) { | ||
$uploadedFiles[] = [ | ||
'name' => $files['name'][$i], | ||
'type' => $files['type'][$i], | ||
'tmp_name' => $files['tmp_name'][$i], | ||
'error' => $files['error'][$i], | ||
'size' => $files['size'][$i] | ||
]; | ||
} | ||
} | ||
|
||
// Get the uploaded file from the request if a single file hase been uploaded. | ||
$uploadedFile = $this->request->getUploadedFile(key: 'file'); | ||
if (empty($uploadedFile) === false) { | ||
$uploadedFiles[] = $uploadedFile; | ||
} | ||
|
||
return $this->importService->import(data: $data, uploadedFiles: $uploadedFiles); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.