mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 15:03:44 +08:00
Restructure Flarum\Api namespace
This commit is contained in:
parent
0e2de95601
commit
b3ce1cd141
|
@ -41,16 +41,16 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||
$this->app->singleton(ErrorHandler::class, function () {
|
||||
$handler = new ErrorHandler;
|
||||
|
||||
$handler->registerHandler(new Handler\FloodingExceptionHandler);
|
||||
$handler->registerHandler(new Handler\IlluminateValidationExceptionHandler);
|
||||
$handler->registerHandler(new Handler\InvalidAccessTokenExceptionHandler);
|
||||
$handler->registerHandler(new Handler\InvalidConfirmationTokenExceptionHandler);
|
||||
$handler->registerHandler(new Handler\MethodNotAllowedExceptionHandler);
|
||||
$handler->registerHandler(new Handler\ModelNotFoundExceptionHandler);
|
||||
$handler->registerHandler(new Handler\PermissionDeniedExceptionHandler);
|
||||
$handler->registerHandler(new Handler\RouteNotFoundExceptionHandler);
|
||||
$handler->registerHandler(new Handler\TokenMismatchExceptionHandler);
|
||||
$handler->registerHandler(new Handler\ValidationExceptionHandler);
|
||||
$handler->registerHandler(new ExceptionHandler\FloodingExceptionHandler);
|
||||
$handler->registerHandler(new ExceptionHandler\IlluminateValidationExceptionHandler);
|
||||
$handler->registerHandler(new ExceptionHandler\InvalidAccessTokenExceptionHandler);
|
||||
$handler->registerHandler(new ExceptionHandler\InvalidConfirmationTokenExceptionHandler);
|
||||
$handler->registerHandler(new ExceptionHandler\MethodNotAllowedExceptionHandler);
|
||||
$handler->registerHandler(new ExceptionHandler\ModelNotFoundExceptionHandler);
|
||||
$handler->registerHandler(new ExceptionHandler\PermissionDeniedExceptionHandler);
|
||||
$handler->registerHandler(new ExceptionHandler\RouteNotFoundExceptionHandler);
|
||||
$handler->registerHandler(new ExceptionHandler\TokenMismatchExceptionHandler);
|
||||
$handler->registerHandler(new ExceptionHandler\ValidationExceptionHandler);
|
||||
$handler->registerHandler(new InvalidParameterExceptionHandler);
|
||||
$handler->registerHandler(new FallbackExceptionHandler($this->app->inDebugMode()));
|
||||
|
||||
|
@ -100,298 +100,13 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||
*/
|
||||
protected function populateRoutes(RouteCollection $routes)
|
||||
{
|
||||
$route = $this->app->make(RouteHandlerFactory::class);
|
||||
$factory = $this->app->make(RouteHandlerFactory::class);
|
||||
|
||||
// Get forum information
|
||||
$routes->get(
|
||||
'/forum',
|
||||
'forum.show',
|
||||
$route->toController(Controller\ShowForumController::class)
|
||||
);
|
||||
|
||||
// Retrieve authentication token
|
||||
$routes->post(
|
||||
'/token',
|
||||
'token',
|
||||
$route->toController(Controller\TokenController::class)
|
||||
);
|
||||
|
||||
// Send forgot password email
|
||||
$routes->post(
|
||||
'/forgot',
|
||||
'forgot',
|
||||
$route->toController(Controller\ForgotPasswordController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Users
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// List users
|
||||
$routes->get(
|
||||
'/users',
|
||||
'users.index',
|
||||
$route->toController(Controller\ListUsersController::class)
|
||||
);
|
||||
|
||||
// Register a user
|
||||
$routes->post(
|
||||
'/users',
|
||||
'users.create',
|
||||
$route->toController(Controller\CreateUserController::class)
|
||||
);
|
||||
|
||||
// Get a single user
|
||||
$routes->get(
|
||||
'/users/{id}',
|
||||
'users.show',
|
||||
$route->toController(Controller\ShowUserController::class)
|
||||
);
|
||||
|
||||
// Edit a user
|
||||
$routes->patch(
|
||||
'/users/{id}',
|
||||
'users.update',
|
||||
$route->toController(Controller\UpdateUserController::class)
|
||||
);
|
||||
|
||||
// Delete a user
|
||||
$routes->delete(
|
||||
'/users/{id}',
|
||||
'users.delete',
|
||||
$route->toController(Controller\DeleteUserController::class)
|
||||
);
|
||||
|
||||
// Upload avatar
|
||||
$routes->post(
|
||||
'/users/{id}/avatar',
|
||||
'users.avatar.upload',
|
||||
$route->toController(Controller\UploadAvatarController::class)
|
||||
);
|
||||
|
||||
// Remove avatar
|
||||
$routes->delete(
|
||||
'/users/{id}/avatar',
|
||||
'users.avatar.delete',
|
||||
$route->toController(Controller\DeleteAvatarController::class)
|
||||
);
|
||||
|
||||
// send confirmation email
|
||||
$routes->post(
|
||||
'/users/{id}/send-confirmation',
|
||||
'users.confirmation.send',
|
||||
$route->toController(Controller\SendConfirmationEmailController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Notifications
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// List notifications for the current user
|
||||
$routes->get(
|
||||
'/notifications',
|
||||
'notifications.index',
|
||||
$route->toController(Controller\ListNotificationsController::class)
|
||||
);
|
||||
|
||||
// Mark all notifications as read
|
||||
$routes->post(
|
||||
'/notifications/read',
|
||||
'notifications.readAll',
|
||||
$route->toController(Controller\ReadAllNotificationsController::class)
|
||||
);
|
||||
|
||||
// Mark a single notification as read
|
||||
$routes->patch(
|
||||
'/notifications/{id}',
|
||||
'notifications.update',
|
||||
$route->toController(Controller\UpdateNotificationController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Discussions
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// List discussions
|
||||
$routes->get(
|
||||
'/discussions',
|
||||
'discussions.index',
|
||||
$route->toController(Controller\ListDiscussionsController::class)
|
||||
);
|
||||
|
||||
// Create a discussion
|
||||
$routes->post(
|
||||
'/discussions',
|
||||
'discussions.create',
|
||||
$route->toController(Controller\CreateDiscussionController::class)
|
||||
);
|
||||
|
||||
// Show a single discussion
|
||||
$routes->get(
|
||||
'/discussions/{id}',
|
||||
'discussions.show',
|
||||
$route->toController(Controller\ShowDiscussionController::class)
|
||||
);
|
||||
|
||||
// Edit a discussion
|
||||
$routes->patch(
|
||||
'/discussions/{id}',
|
||||
'discussions.update',
|
||||
$route->toController(Controller\UpdateDiscussionController::class)
|
||||
);
|
||||
|
||||
// Delete a discussion
|
||||
$routes->delete(
|
||||
'/discussions/{id}',
|
||||
'discussions.delete',
|
||||
$route->toController(Controller\DeleteDiscussionController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Posts
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// List posts, usually for a discussion
|
||||
$routes->get(
|
||||
'/posts',
|
||||
'posts.index',
|
||||
$route->toController(Controller\ListPostsController::class)
|
||||
);
|
||||
|
||||
// Create a post
|
||||
$routes->post(
|
||||
'/posts',
|
||||
'posts.create',
|
||||
$route->toController(Controller\CreatePostController::class)
|
||||
);
|
||||
|
||||
// Show a single or multiple posts by ID
|
||||
$routes->get(
|
||||
'/posts/{id}',
|
||||
'posts.show',
|
||||
$route->toController(Controller\ShowPostController::class)
|
||||
);
|
||||
|
||||
// Edit a post
|
||||
$routes->patch(
|
||||
'/posts/{id}',
|
||||
'posts.update',
|
||||
$route->toController(Controller\UpdatePostController::class)
|
||||
);
|
||||
|
||||
// Delete a post
|
||||
$routes->delete(
|
||||
'/posts/{id}',
|
||||
'posts.delete',
|
||||
$route->toController(Controller\DeletePostController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Groups
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// List groups
|
||||
$routes->get(
|
||||
'/groups',
|
||||
'groups.index',
|
||||
$route->toController(Controller\ListGroupsController::class)
|
||||
);
|
||||
|
||||
// Create a group
|
||||
$routes->post(
|
||||
'/groups',
|
||||
'groups.create',
|
||||
$route->toController(Controller\CreateGroupController::class)
|
||||
);
|
||||
|
||||
// Edit a group
|
||||
$routes->patch(
|
||||
'/groups/{id}',
|
||||
'groups.update',
|
||||
$route->toController(Controller\UpdateGroupController::class)
|
||||
);
|
||||
|
||||
// Delete a group
|
||||
$routes->delete(
|
||||
'/groups/{id}',
|
||||
'groups.delete',
|
||||
$route->toController(Controller\DeleteGroupController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Administration
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Toggle an extension
|
||||
$routes->patch(
|
||||
'/extensions/{name}',
|
||||
'extensions.update',
|
||||
$route->toController(Controller\UpdateExtensionController::class)
|
||||
);
|
||||
|
||||
// Uninstall an extension
|
||||
$routes->delete(
|
||||
'/extensions/{name}',
|
||||
'extensions.delete',
|
||||
$route->toController(Controller\UninstallExtensionController::class)
|
||||
);
|
||||
|
||||
// Update settings
|
||||
$routes->post(
|
||||
'/settings',
|
||||
'settings',
|
||||
$route->toController(Controller\SetSettingsController::class)
|
||||
);
|
||||
|
||||
// Update a permission
|
||||
$routes->post(
|
||||
'/permission',
|
||||
'permission',
|
||||
$route->toController(Controller\SetPermissionController::class)
|
||||
);
|
||||
|
||||
// Upload a logo
|
||||
$routes->post(
|
||||
'/logo',
|
||||
'logo',
|
||||
$route->toController(Controller\UploadLogoController::class)
|
||||
);
|
||||
|
||||
// Remove the logo
|
||||
$routes->delete(
|
||||
'/logo',
|
||||
'logo.delete',
|
||||
$route->toController(Controller\DeleteLogoController::class)
|
||||
);
|
||||
|
||||
// Upload a favicon
|
||||
$routes->post(
|
||||
'/favicon',
|
||||
'favicon',
|
||||
$route->toController(Controller\UploadFaviconController::class)
|
||||
);
|
||||
|
||||
// Remove the favicon
|
||||
$routes->delete(
|
||||
'/favicon',
|
||||
'favicon.delete',
|
||||
$route->toController(Controller\DeleteFaviconController::class)
|
||||
);
|
||||
$callback = include __DIR__.'/routes.php';
|
||||
$callback($routes, $factory);
|
||||
|
||||
$this->app->make('events')->fire(
|
||||
new ConfigureApiRoutes($routes, $route)
|
||||
new ConfigureApiRoutes($routes, $factory)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Flarum\Api\Controller;
|
|||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
abstract class AbstractCreateController extends AbstractResourceController
|
||||
abstract class AbstractCreateController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Flarum\Api\Controller;
|
|||
use Tobscure\JsonApi\Collection;
|
||||
use Tobscure\JsonApi\SerializerInterface;
|
||||
|
||||
abstract class AbstractCollectionController extends AbstractSerializeController
|
||||
abstract class AbstractListController extends AbstractSerializeController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
|
@ -14,7 +14,7 @@ namespace Flarum\Api\Controller;
|
|||
use Tobscure\JsonApi\Resource;
|
||||
use Tobscure\JsonApi\SerializerInterface;
|
||||
|
||||
abstract class AbstractResourceController extends AbstractSerializeController
|
||||
abstract class AbstractShowController extends AbstractSerializeController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
|
@ -16,7 +16,7 @@ use Illuminate\Contracts\Bus\Dispatcher;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class DeleteAvatarController extends AbstractResourceController
|
||||
class DeleteAvatarController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -17,7 +17,7 @@ use Flarum\Core\Search\SearchCriteria;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class ListDiscussionsController extends AbstractCollectionController
|
||||
class ListDiscussionsController extends AbstractListController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -15,7 +15,7 @@ use Flarum\Core\Group;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class ListGroupsController extends AbstractCollectionController
|
||||
class ListGroupsController extends AbstractListController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -17,7 +17,7 @@ use Flarum\Core\Repository\NotificationRepository;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class ListNotificationsController extends AbstractCollectionController
|
||||
class ListNotificationsController extends AbstractListController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -18,7 +18,7 @@ use Psr\Http\Message\ServerRequestInterface;
|
|||
use Tobscure\JsonApi\Document;
|
||||
use Tobscure\JsonApi\Exception\InvalidParameterException;
|
||||
|
||||
class ListPostsController extends AbstractCollectionController
|
||||
class ListPostsController extends AbstractListController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -18,7 +18,7 @@ use Flarum\Core\Search\User\UserSearcher;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class ListUsersController extends AbstractCollectionController
|
||||
class ListUsersController extends AbstractListController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -18,7 +18,7 @@ use Flarum\Core\User;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class ShowDiscussionController extends AbstractResourceController
|
||||
class ShowDiscussionController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* @var DiscussionRepository
|
||||
|
|
|
@ -15,7 +15,7 @@ use Flarum\Core\Group;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class ShowForumController extends AbstractResourceController
|
||||
class ShowForumController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -15,7 +15,7 @@ use Flarum\Core\Repository\PostRepository;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class ShowPostController extends AbstractResourceController
|
||||
class ShowPostController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -15,7 +15,7 @@ use Flarum\Core\Repository\UserRepository;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class ShowUserController extends AbstractResourceController
|
||||
class ShowUserController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -18,7 +18,7 @@ use Illuminate\Database\Eloquent\Collection;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class UpdateDiscussionController extends AbstractResourceController
|
||||
class UpdateDiscussionController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -16,7 +16,7 @@ use Illuminate\Contracts\Bus\Dispatcher;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class UpdateGroupController extends AbstractResourceController
|
||||
class UpdateGroupController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -16,7 +16,7 @@ use Illuminate\Contracts\Bus\Dispatcher;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class UpdateNotificationController extends AbstractResourceController
|
||||
class UpdateNotificationController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -16,7 +16,7 @@ use Illuminate\Contracts\Bus\Dispatcher;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class UpdatePostController extends AbstractResourceController
|
||||
class UpdatePostController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -17,7 +17,7 @@ use Illuminate\Contracts\Bus\Dispatcher;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class UpdateUserController extends AbstractResourceController
|
||||
class UpdateUserController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -16,7 +16,7 @@ use Illuminate\Contracts\Bus\Dispatcher;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class UploadAvatarController extends AbstractResourceController
|
||||
class UploadAvatarController extends AbstractShowController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Handler;
|
||||
namespace Flarum\Api\ExceptionHandler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Core\Exception\FloodingException;
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Handler;
|
||||
namespace Flarum\Api\ExceptionHandler;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Validation\ValidationException;
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Handler;
|
||||
namespace Flarum\Api\ExceptionHandler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Api\Exception\InvalidAccessTokenException;
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Handler;
|
||||
namespace Flarum\Api\ExceptionHandler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Core\Exception\InvalidConfirmationTokenException;
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Handler;
|
||||
namespace Flarum\Api\ExceptionHandler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Http\Exception\MethodNotAllowedException;
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Handler;
|
||||
namespace Flarum\Api\ExceptionHandler;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Handler;
|
||||
namespace Flarum\Api\ExceptionHandler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Core\Exception\PermissionDeniedException;
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Handler;
|
||||
namespace Flarum\Api\ExceptionHandler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Http\Exception\RouteNotFoundException;
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Handler;
|
||||
namespace Flarum\Api\ExceptionHandler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Http\Exception\TokenMismatchException;
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Handler;
|
||||
namespace Flarum\Api\ExceptionHandler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Core\Exception\ValidationException;
|
|
@ -14,7 +14,7 @@ namespace Flarum\Api\Serializer;
|
|||
use Flarum\Core\Discussion;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class DiscussionBasicSerializer extends AbstractSerializer
|
||||
class BasicDiscussionSerializer extends AbstractSerializer
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
|
@ -15,7 +15,7 @@ use Flarum\Core\Post;
|
|||
use Flarum\Core\Post\CommentPost;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class PostBasicSerializer extends AbstractSerializer
|
||||
class BasicPostSerializer extends AbstractSerializer
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
|
@ -14,7 +14,7 @@ namespace Flarum\Api\Serializer;
|
|||
use Flarum\Core\User;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class UserBasicSerializer extends AbstractSerializer
|
||||
class BasicUserSerializer extends AbstractSerializer
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
|
@ -14,7 +14,7 @@ namespace Flarum\Api\Serializer;
|
|||
use Flarum\Core\Access\Gate;
|
||||
use Flarum\Core\Discussion;
|
||||
|
||||
class DiscussionSerializer extends DiscussionBasicSerializer
|
||||
class DiscussionSerializer extends BasicDiscussionSerializer
|
||||
{
|
||||
/**
|
||||
* @var Gate
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Flarum\Api\Serializer;
|
|||
use Flarum\Core\Access\Gate;
|
||||
use Flarum\Core\Post\CommentPost;
|
||||
|
||||
class PostSerializer extends PostBasicSerializer
|
||||
class PostSerializer extends BasicPostSerializer
|
||||
{
|
||||
/**
|
||||
* @var \Flarum\Core\Access\Gate
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Flarum\Api\Serializer;
|
|||
|
||||
use Flarum\Core\Access\Gate;
|
||||
|
||||
class UserSerializer extends UserBasicSerializer
|
||||
class UserSerializer extends BasicUserSerializer
|
||||
{
|
||||
/**
|
||||
* @var Gate
|
||||
|
|
304
framework/core/src/Api/routes.php
Normal file
304
framework/core/src/Api/routes.php
Normal file
|
@ -0,0 +1,304 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Api\Controller;
|
||||
use Flarum\Http\Handler\RouteHandlerFactory;
|
||||
use Flarum\Http\RouteCollection;
|
||||
|
||||
return function (RouteCollection $map, RouteHandlerFactory $route) {
|
||||
// Get forum information
|
||||
$map->get(
|
||||
'/forum',
|
||||
'forum.show',
|
||||
$route->toController(Controller\ShowForumController::class)
|
||||
);
|
||||
|
||||
// Retrieve authentication token
|
||||
$map->post(
|
||||
'/token',
|
||||
'token',
|
||||
$route->toController(Controller\TokenController::class)
|
||||
);
|
||||
|
||||
// Send forgot password email
|
||||
$map->post(
|
||||
'/forgot',
|
||||
'forgot',
|
||||
$route->toController(Controller\ForgotPasswordController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Users
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// List users
|
||||
$map->get(
|
||||
'/users',
|
||||
'users.index',
|
||||
$route->toController(Controller\ListUsersController::class)
|
||||
);
|
||||
|
||||
// Register a user
|
||||
$map->post(
|
||||
'/users',
|
||||
'users.create',
|
||||
$route->toController(Controller\CreateUserController::class)
|
||||
);
|
||||
|
||||
// Get a single user
|
||||
$map->get(
|
||||
'/users/{id}',
|
||||
'users.show',
|
||||
$route->toController(Controller\ShowUserController::class)
|
||||
);
|
||||
|
||||
// Edit a user
|
||||
$map->patch(
|
||||
'/users/{id}',
|
||||
'users.update',
|
||||
$route->toController(Controller\UpdateUserController::class)
|
||||
);
|
||||
|
||||
// Delete a user
|
||||
$map->delete(
|
||||
'/users/{id}',
|
||||
'users.delete',
|
||||
$route->toController(Controller\DeleteUserController::class)
|
||||
);
|
||||
|
||||
// Upload avatar
|
||||
$map->post(
|
||||
'/users/{id}/avatar',
|
||||
'users.avatar.upload',
|
||||
$route->toController(Controller\UploadAvatarController::class)
|
||||
);
|
||||
|
||||
// Remove avatar
|
||||
$map->delete(
|
||||
'/users/{id}/avatar',
|
||||
'users.avatar.delete',
|
||||
$route->toController(Controller\DeleteAvatarController::class)
|
||||
);
|
||||
|
||||
// send confirmation email
|
||||
$map->post(
|
||||
'/users/{id}/send-confirmation',
|
||||
'users.confirmation.send',
|
||||
$route->toController(Controller\SendConfirmationEmailController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Notifications
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// List notifications for the current user
|
||||
$map->get(
|
||||
'/notifications',
|
||||
'notifications.index',
|
||||
$route->toController(Controller\ListNotificationsController::class)
|
||||
);
|
||||
|
||||
// Mark all notifications as read
|
||||
$map->post(
|
||||
'/notifications/read',
|
||||
'notifications.readAll',
|
||||
$route->toController(Controller\ReadAllNotificationsController::class)
|
||||
);
|
||||
|
||||
// Mark a single notification as read
|
||||
$map->patch(
|
||||
'/notifications/{id}',
|
||||
'notifications.update',
|
||||
$route->toController(Controller\UpdateNotificationController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Discussions
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// List discussions
|
||||
$map->get(
|
||||
'/discussions',
|
||||
'discussions.index',
|
||||
$route->toController(Controller\ListDiscussionsController::class)
|
||||
);
|
||||
|
||||
// Create a discussion
|
||||
$map->post(
|
||||
'/discussions',
|
||||
'discussions.create',
|
||||
$route->toController(Controller\CreateDiscussionController::class)
|
||||
);
|
||||
|
||||
// Show a single discussion
|
||||
$map->get(
|
||||
'/discussions/{id}',
|
||||
'discussions.show',
|
||||
$route->toController(Controller\ShowDiscussionController::class)
|
||||
);
|
||||
|
||||
// Edit a discussion
|
||||
$map->patch(
|
||||
'/discussions/{id}',
|
||||
'discussions.update',
|
||||
$route->toController(Controller\UpdateDiscussionController::class)
|
||||
);
|
||||
|
||||
// Delete a discussion
|
||||
$map->delete(
|
||||
'/discussions/{id}',
|
||||
'discussions.delete',
|
||||
$route->toController(Controller\DeleteDiscussionController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Posts
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// List posts, usually for a discussion
|
||||
$map->get(
|
||||
'/posts',
|
||||
'posts.index',
|
||||
$route->toController(Controller\ListPostsController::class)
|
||||
);
|
||||
|
||||
// Create a post
|
||||
$map->post(
|
||||
'/posts',
|
||||
'posts.create',
|
||||
$route->toController(Controller\CreatePostController::class)
|
||||
);
|
||||
|
||||
// Show a single or multiple posts by ID
|
||||
$map->get(
|
||||
'/posts/{id}',
|
||||
'posts.show',
|
||||
$route->toController(Controller\ShowPostController::class)
|
||||
);
|
||||
|
||||
// Edit a post
|
||||
$map->patch(
|
||||
'/posts/{id}',
|
||||
'posts.update',
|
||||
$route->toController(Controller\UpdatePostController::class)
|
||||
);
|
||||
|
||||
// Delete a post
|
||||
$map->delete(
|
||||
'/posts/{id}',
|
||||
'posts.delete',
|
||||
$route->toController(Controller\DeletePostController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Groups
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// List groups
|
||||
$map->get(
|
||||
'/groups',
|
||||
'groups.index',
|
||||
$route->toController(Controller\ListGroupsController::class)
|
||||
);
|
||||
|
||||
// Create a group
|
||||
$map->post(
|
||||
'/groups',
|
||||
'groups.create',
|
||||
$route->toController(Controller\CreateGroupController::class)
|
||||
);
|
||||
|
||||
// Edit a group
|
||||
$map->patch(
|
||||
'/groups/{id}',
|
||||
'groups.update',
|
||||
$route->toController(Controller\UpdateGroupController::class)
|
||||
);
|
||||
|
||||
// Delete a group
|
||||
$map->delete(
|
||||
'/groups/{id}',
|
||||
'groups.delete',
|
||||
$route->toController(Controller\DeleteGroupController::class)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Administration
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Toggle an extension
|
||||
$map->patch(
|
||||
'/extensions/{name}',
|
||||
'extensions.update',
|
||||
$route->toController(Controller\UpdateExtensionController::class)
|
||||
);
|
||||
|
||||
// Uninstall an extension
|
||||
$map->delete(
|
||||
'/extensions/{name}',
|
||||
'extensions.delete',
|
||||
$route->toController(Controller\UninstallExtensionController::class)
|
||||
);
|
||||
|
||||
// Update settings
|
||||
$map->post(
|
||||
'/settings',
|
||||
'settings',
|
||||
$route->toController(Controller\SetSettingsController::class)
|
||||
);
|
||||
|
||||
// Update a permission
|
||||
$map->post(
|
||||
'/permission',
|
||||
'permission',
|
||||
$route->toController(Controller\SetPermissionController::class)
|
||||
);
|
||||
|
||||
// Upload a logo
|
||||
$map->post(
|
||||
'/logo',
|
||||
'logo',
|
||||
$route->toController(Controller\UploadLogoController::class)
|
||||
);
|
||||
|
||||
// Remove the logo
|
||||
$map->delete(
|
||||
'/logo',
|
||||
'logo.delete',
|
||||
$route->toController(Controller\DeleteLogoController::class)
|
||||
);
|
||||
|
||||
// Upload a favicon
|
||||
$map->post(
|
||||
'/favicon',
|
||||
'favicon',
|
||||
$route->toController(Controller\UploadFaviconController::class)
|
||||
);
|
||||
|
||||
// Remove the favicon
|
||||
$map->delete(
|
||||
'/favicon',
|
||||
'favicon.delete',
|
||||
$route->toController(Controller\DeleteFaviconController::class)
|
||||
);
|
||||
};
|
|
@ -12,7 +12,7 @@
|
|||
namespace Tests\Flarum\Api\Handler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Api\Handler\FloodingExceptionHandler;
|
||||
use Flarum\Api\ExceptionHandler\FloodingExceptionHandler;
|
||||
use Flarum\Core\Exception\FloodingException;
|
||||
use Tests\Test\TestCase;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Tests\Flarum\Api\Handler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Api\Handler\IlluminateValidationExceptionHandler;
|
||||
use Flarum\Api\ExceptionHandler\IlluminateValidationExceptionHandler;
|
||||
use Illuminate\Contracts\Validation\ValidationException;
|
||||
use Illuminate\Validation\Factory;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Tests\Flarum\Api\Handler;
|
|||
|
||||
use Exception;
|
||||
use Flarum\Api\Exception\InvalidAccessTokenException;
|
||||
use Flarum\Api\Handler\InvalidAccessTokenExceptionHandler;
|
||||
use Flarum\Api\ExceptionHandler\InvalidAccessTokenExceptionHandler;
|
||||
use Tests\Test\TestCase;
|
||||
|
||||
class InvalidAccessTokenExceptionHandlerTest extends TestCase
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Tests\Flarum\Api\Handler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Api\Handler\InvalidConfirmationTokenExceptionHandler;
|
||||
use Flarum\Api\ExceptionHandler\InvalidConfirmationTokenExceptionHandler;
|
||||
use Flarum\Core\Exception\InvalidConfirmationTokenException;
|
||||
use Tests\Test\TestCase;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Tests\Flarum\Api\Handler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Api\Handler\MethodNotAllowedExceptionHandler;
|
||||
use Flarum\Api\ExceptionHandler\MethodNotAllowedExceptionHandler;
|
||||
use Flarum\Http\Exception\MethodNotAllowedException;
|
||||
use Tests\Test\TestCase;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Tests\Flarum\Api\Handler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Api\Handler\ModelNotFoundExceptionHandler;
|
||||
use Flarum\Api\ExceptionHandler\ModelNotFoundExceptionHandler;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Tests\Test\TestCase;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Tests\Flarum\Api\Handler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Api\Handler\PermissionDeniedExceptionHandler;
|
||||
use Flarum\Api\ExceptionHandler\PermissionDeniedExceptionHandler;
|
||||
use Flarum\Core\Exception\PermissionDeniedException;
|
||||
use Tests\Test\TestCase;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Tests\Flarum\Api\Handler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Api\Handler\RouteNotFoundExceptionHandler;
|
||||
use Flarum\Api\ExceptionHandler\RouteNotFoundExceptionHandler;
|
||||
use Flarum\Http\Exception\RouteNotFoundException;
|
||||
use Tests\Test\TestCase;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Tests\Flarum\Api\Handler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Api\Handler\TokenMismatchExceptionHandler;
|
||||
use Flarum\Api\ExceptionHandler\TokenMismatchExceptionHandler;
|
||||
use Flarum\Http\Exception\TokenMismatchException;
|
||||
use Tests\Test\TestCase;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Tests\Flarum\Api\Handler;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Api\Handler\ValidationExceptionHandler;
|
||||
use Flarum\Api\ExceptionHandler\ValidationExceptionHandler;
|
||||
use Flarum\Core\Exception\ValidationException;
|
||||
use Tests\Test\TestCase;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user