Skip to content

Commit

Permalink
Added UserConfiguration Controller and moved methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ksainc committed Oct 3, 2023
1 parent 59df5d1 commit dfa3924
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 77 deletions.
6 changes: 3 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
'verb' => 'GET'
],
[
'name' => 'data#listCollections',
'name' => 'UserConfiguration#listCollections',
'url' => '/list-collections',
'verb' => 'GET'
],
[
'name' => 'data#listFormats',
'name' => 'UserConfiguration#listFormats',
'url' => '/list-formats',
'verb' => 'GET'
],
[
'name' => 'data#listServices',
'name' => 'UserConfiguration#listServices',
'url' => '/list-services',
'verb' => 'GET'
],
Expand Down
75 changes: 1 addition & 74 deletions lib/Controller/DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ class DataController extends Controller {
use Errors;

public function __construct(IRequest $request,
DataService $DataService,
string $userId) {
DataService $DataService) {
parent::__construct(Application::APP_ID, $request);
$this->DataService = $DataService;
$this->userId = $userId;
}

/**
Expand Down Expand Up @@ -137,75 +135,4 @@ public function phone(string $id) {

}

/**
* handels collections list requests
*
* @NoAdminRequired
*
* @return DataResponse
*/
public function listCollections(string $type): DataResponse {

// evaluate if user id is present
if ($this->userId === null) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
// retrieve collections
$rs = $this->DataService->listCollections($this->userId, $type);
// return response
if (isset($rs)) {
return new DataResponse($rs);
} else {
return new DataResponse($rs['error'], 401);
}

}

/**
* handels formats list requests
*
* @NoAdminRequired
*
* @return DataResponse
*/
public function listFormats(string $type): DataResponse {

// evaluate if user id is present
if ($this->userId === null) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
// retrieve formats
$rs = $this->DataService->listFormats($type);
// return response
if (isset($rs)) {
return new DataResponse($rs);
} else {
return new DataResponse($rs['error'], 401);
}

}

/**
* handels services list requests
*
* @NoAdminRequired
*
* @return DataResponse
*/
public function listServices(): DataResponse {

// evaluate if user id is present
if ($this->userId === null) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
// retrieve formats
$rs = $this->DataService->listServices($this->userId);
// return response
if (isset($rs)) {
return new DataResponse($rs);
} else {
return new DataResponse($rs['error'], 401);
}

}
}
99 changes: 99 additions & 0 deletions lib/Controller/UserConfigurationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
// SPDX-FileCopyrightText: Sebastian Krupinski <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\Data\Controller;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;

use OCA\Data\AppInfo\Application;
use OCA\Data\Service\DataService;

class UserConfigurationController extends Controller {
private DataService $DataService;

use Errors;

public function __construct(IRequest $request,
DataService $DataService,
string $userId) {
parent::__construct(Application::APP_ID, $request);
$this->DataService = $DataService;
$this->userId = $userId;
}

/**
* handels collections list requests
*
* @NoAdminRequired
*
* @return DataResponse
*/
public function listCollections(string $type): DataResponse {

// evaluate if user id is present
if ($this->userId === null) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
// retrieve collections
$rs = $this->DataService->listCollections($this->userId, $type);
// return response
if (isset($rs)) {
return new DataResponse($rs);
} else {
return new DataResponse($rs['error'], 401);
}

}

/**
* handels formats list requests
*
* @NoAdminRequired
*
* @return DataResponse
*/
public function listFormats(string $type): DataResponse {

// evaluate if user id is present
if ($this->userId === null) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
// retrieve formats
$rs = $this->DataService->listFormats($type);
// return response
if (isset($rs)) {
return new DataResponse($rs);
} else {
return new DataResponse($rs['error'], 401);
}

}

/**
* handels services list requests
*
* @NoAdminRequired
*
* @return DataResponse
*/
public function listServices(): DataResponse {

// evaluate if user id is present
if ($this->userId === null) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
// retrieve formats
$rs = $this->DataService->listServices($this->userId);
// return response
if (isset($rs)) {
return new DataResponse($rs);
} else {
return new DataResponse($rs['error'], 401);
}

}
}

0 comments on commit dfa3924

Please sign in to comment.