-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
- Loading branch information
1 parent
a616219
commit 541cd43
Showing
2 changed files
with
140 additions
and
3 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,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); | ||
} | ||
} | ||
|
||
} | ||
|