Skip to content

Commit

Permalink
some ocs
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Mar 1, 2021
1 parent a616219 commit 541cd43
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 3 deletions.
11 changes: 8 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
*/

return [
'ocs' => [
],
'routes' => [
['name' => 'Settings#getSettings', 'url' => '/admin/settings', 'verb' => 'GET'],
['name' => 'Settings#setSettings', 'url' => '/admin/settings', 'verb' => 'POST'],
Expand Down Expand Up @@ -66,8 +64,15 @@
['name' => 'Shares#create', 'url' => '/v1/circles/{circleUniqueId}/share', 'verb' => 'PUT'],

['name' => 'GlobalScale#event', 'url' => '/v1/gs/event', 'verb' => 'POST'],
['name' => 'GlobalScale#asyncBroadcast', 'url' => '/v1/gs/broadcast/async/{token}/', 'verb' => 'POST'],
[
'name' => 'GlobalScale#asyncBroadcast', 'url' => '/v1/gs/broadcast/async/{token}/',
'verb' => 'POST'
],
['name' => 'GlobalScale#broadcast', 'url' => '/v1/gs/broadcast', 'verb' => 'POST'],
['name' => 'GlobalScale#status', 'url' => '/v1/gs/status', 'verb' => 'POST']
],
'ocs' => [
['name' => 'OcsApi#circles', 'url' => '/circles/', 'verb' => 'GET'],
['name' => 'OcsApi#members', 'url' => '/circles/{circleId}/members/', 'verb' => 'GET']
]
];
132 changes: 132 additions & 0 deletions lib/Controller/OcsApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

declare(strict_types=1);


/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/


namespace OCA\Circles\Controller;


use Exception;
use OCA\Circles\Model\Circle;
use OCA\Circles\Service\CirclesService;
use OCA\Circles\Service\MembersService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
use OCP\IUserSession;


/**
* Class OcsApiController
*
* @package OCA\Circles\Controller
*/
class OcsApiController extends OCSController {


/** @var IUserSession */
private $userSession;

/** @var CirclesService */
private $circlesService;

/** @var MembersService */
private $membersService;


/**
* OcsApiController constructor.
*
* @param $appName
* @param IRequest $request
* @param IUserSession $userSession
* @param CirclesService $circlesService
* @param MembersService $membersService
*/
public function __construct(
$appName,
IRequest $request,
IUserSession $userSession,
CirclesService $circlesService,
MembersService $membersService
) {
parent::__construct($appName, $request);

$this->userSession = $userSession;
$this->circlesService = $circlesService;
$this->membersService = $membersService;
}


/**
* @NoAdminRequired
*
* @return DataResponse
*/
public function circles(): DataResponse {
$user = $this->userSession->getUser();
try {
$circles = $this->circlesService->listCircles($user->getUID(), Circle::CIRCLES_ALL);

$circles = array_map(
function(Circle $circle) {
$circle->setSettings([]);

return $circle;
}, $circles
);

return new DataResponse(json_decode(json_encode($circles), true));
} catch (Exception $e) {
return new DataResponse(['message' => $$e->getMessage()], Http::STATUS_BAD_REQUEST);
}
}


/**
* @NoAdminRequired
*
* @param string $circleId
*
* @return DataResponse
*/
public function members(string $circleId): DataResponse {
try {
$circle = $this->circlesService->detailsCircle($circleId);
$members = ($circle->getMembers() === null) ? [] : $circle->getMembers();

return new DataResponse(json_decode(json_encode($members), true));
} catch (Exception $e) {
return new DataResponse(['message' => $$e->getMessage()], Http::STATUS_BAD_REQUEST);
}
}

}

0 comments on commit 541cd43

Please sign in to comment.