Skip to content

Commit

Permalink
feat(api): added basic controller für update API (#3313)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jan 6, 2025
1 parent ccc177f commit d1f4756
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions phpmyfaq/src/api-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@
'controller' => [TitleController::class, 'index'],
'methods' => 'GET'
],
'api.update' => [
'path' => "v{$apiVersion}/update",
'controller' => [UpdateController::class, 'index'],
'methods' => 'POST'
],
'api.version' => [
'path' => "v{$apiVersion}/version",
'controller' => [VersionController::class, 'index'],
Expand Down
60 changes: 60 additions & 0 deletions phpmyfaq/src/phpMyFAQ/Controller/Api/UpdateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* The Update Controller for the REST API
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @copyright 2025 phpMyFAQ Team
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2025-01-06
*/

declare(strict_types=1);

namespace phpMyFAQ\Controller\Api;

use OpenApi\Attributes as OA;
use phpMyFAQ\Controller\AbstractController;
use phpMyFAQ\Enums\PermissionType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;

class UpdateController extends AbstractController
{
public function __construct()
{
parent::__construct();

if (!$this->isApiEnabled()) {
throw new UnauthorizedHttpException('API is not enabled');
}
}

#[OA\Post(path: '/api/v3.1/update', operationId: 'triggerUpdate', tags: ['Endpoints with Authentication'])]
#[OA\Header(
header: 'x-pmf-token',
description: 'phpMyFAQ client API Token, generated in admin backend',
schema: new OA\Schema(type: 'string')
)]
#[OA\Response(
response: 200,
description: 'Returns the new and updated phpMyFAQ version number as string.',
content: new OA\JsonContent(example: '4.0.0'),
)]
#[OA\Response(
response: 401,
description: 'If the user is not authenticated and/or does not have sufficient permissions.'
)]
public function index(): Response
{
$this->userHasPermission(PermissionType::CONFIGURATION_EDIT);

return $this->json($this->configuration->getVersion());
}
}

0 comments on commit d1f4756

Please sign in to comment.