Prefix API routes for now

This commit is contained in:
Toby Zerner 2015-06-17 17:48:50 +09:30
parent 7596dec7b9
commit f669b95fd1

View File

@ -43,23 +43,25 @@ class ApiServiceProvider extends ServiceProvider
{ {
$this->app->instance('flarum.api.routes', $routes = new RouteCollection); $this->app->instance('flarum.api.routes', $routes = new RouteCollection);
$prefix = '/api';
// Get forum information // Get forum information
$routes->get( $routes->get(
'/forum', $prefix.'/forum',
'flarum.api.forum.show', 'flarum.api.forum.show',
$this->action('Flarum\Api\Actions\Forum\ShowAction') $this->action('Flarum\Api\Actions\Forum\ShowAction')
); );
// Retrieve authentication token // Retrieve authentication token
$routes->post( $routes->post(
'/token', $prefix.'/token',
'flarum.api.token', 'flarum.api.token',
$this->action('Flarum\Api\Actions\TokenAction') $this->action('Flarum\Api\Actions\TokenAction')
); );
// Send forgot password email // Send forgot password email
$routes->post( $routes->post(
'/forgot', $prefix.'/forgot',
'flarum.api.forgot', 'flarum.api.forgot',
$this->action('Flarum\Api\Actions\ForgotAction') $this->action('Flarum\Api\Actions\ForgotAction')
); );
@ -72,49 +74,49 @@ class ApiServiceProvider extends ServiceProvider
// List users // List users
$routes->get( $routes->get(
'/users', $prefix.'/users',
'flarum.api.users.index', 'flarum.api.users.index',
$this->action('Flarum\Api\Actions\Users\IndexAction') $this->action('Flarum\Api\Actions\Users\IndexAction')
); );
// Register a user // Register a user
$routes->post( $routes->post(
'/users', $prefix.'/users',
'flarum.api.users.create', 'flarum.api.users.create',
$this->action('Flarum\Api\Actions\Users\CreateAction') $this->action('Flarum\Api\Actions\Users\CreateAction')
); );
// Get a single user // Get a single user
$routes->get( $routes->get(
'/users/{id}', $prefix.'/users/{id}',
'flarum.api.users.show', 'flarum.api.users.show',
$this->action('Flarum\Api\Actions\Users\ShowAction') $this->action('Flarum\Api\Actions\Users\ShowAction')
); );
// Edit a user // Edit a user
$routes->put( $routes->put(
'/users/{id}', $prefix.'/users/{id}',
'flarum.api.users.update', 'flarum.api.users.update',
$this->action('Flarum\Api\Actions\Users\UpdateAction') $this->action('Flarum\Api\Actions\Users\UpdateAction')
); );
// Delete a user // Delete a user
$routes->delete( $routes->delete(
'/users/{id}', $prefix.'/users/{id}',
'flarum.api.users.delete', 'flarum.api.users.delete',
$this->action('Flarum\Api\Actions\Users\DeleteAction') $this->action('Flarum\Api\Actions\Users\DeleteAction')
); );
// Upload avatar // Upload avatar
$routes->post( $routes->post(
'/users/{id}/avatar', $prefix.'/users/{id}/avatar',
'flarum.api.users.avatar.upload', 'flarum.api.users.avatar.upload',
$this->action('Flarum\Api\Actions\Users\UploadAvatarAction') $this->action('Flarum\Api\Actions\Users\UploadAvatarAction')
); );
// Remove avatar // Remove avatar
$routes->delete( $routes->delete(
'/users/{id}/avatar', $prefix.'/users/{id}/avatar',
'flarum.api.users.avatar.delete', 'flarum.api.users.avatar.delete',
$this->action('Flarum\Api\Actions\Users\DeleteAvatarAction') $this->action('Flarum\Api\Actions\Users\DeleteAvatarAction')
); );
@ -127,21 +129,21 @@ class ApiServiceProvider extends ServiceProvider
// List activity // List activity
$routes->get( $routes->get(
'/activity', $prefix.'/activity',
'flarum.api.activity.index', 'flarum.api.activity.index',
$this->action('Flarum\Api\Actions\Activity\IndexAction') $this->action('Flarum\Api\Actions\Activity\IndexAction')
); );
// List notifications for the current user // List notifications for the current user
$routes->get( $routes->get(
'/notifications', $prefix.'/notifications',
'flarum.api.notifications.index', 'flarum.api.notifications.index',
$this->action('Flarum\Api\Actions\Notifications\IndexAction') $this->action('Flarum\Api\Actions\Notifications\IndexAction')
); );
// Mark a single notification as read // Mark a single notification as read
$routes->put( $routes->put(
'/notifications/{id}', $prefix.'/notifications/{id}',
'flarum.api.notifications.update', 'flarum.api.notifications.update',
$this->action('Flarum\Api\Actions\Notifications\UpdateAction') $this->action('Flarum\Api\Actions\Notifications\UpdateAction')
); );
@ -154,34 +156,34 @@ class ApiServiceProvider extends ServiceProvider
// List discussions // List discussions
$routes->get( $routes->get(
'/discussions', $prefix.'/discussions',
'flarum.api.discussions.index', 'flarum.api.discussions.index',
$this->action('Flarum\Api\Actions\Discussions\IndexAction') $this->action('Flarum\Api\Actions\Discussions\IndexAction')
); );
// Create a discussion // Create a discussion
$routes->post( $routes->post(
'/discussions', $prefix.'/discussions',
'flarum.api.discussions.create', 'flarum.api.discussions.create',
$this->action('Flarum\Api\Actions\Discussions\CreateAction')); $this->action('Flarum\Api\Actions\Discussions\CreateAction'));
// Show a single discussion // Show a single discussion
$routes->get( $routes->get(
'/discussions/{id}', $prefix.'/discussions/{id}',
'flarum.api.discussions.show', 'flarum.api.discussions.show',
$this->action('Flarum\Api\Actions\Discussions\ShowAction') $this->action('Flarum\Api\Actions\Discussions\ShowAction')
); );
// Edit a discussion // Edit a discussion
$routes->put( $routes->put(
'/discussions/{id}', $prefix.'/discussions/{id}',
'flarum.api.discussions.update', 'flarum.api.discussions.update',
$this->action('Flarum\Api\Actions\Discussions\UpdateAction') $this->action('Flarum\Api\Actions\Discussions\UpdateAction')
); );
// Delete a discussion // Delete a discussion
$routes->delete( $routes->delete(
'/discussions/{id}', $prefix.'/discussions/{id}',
'flarum.api.discussions.delete', 'flarum.api.discussions.delete',
$this->action('Flarum\Api\Actions\Discussions\DeleteAction') $this->action('Flarum\Api\Actions\Discussions\DeleteAction')
); );
@ -194,7 +196,7 @@ class ApiServiceProvider extends ServiceProvider
// List posts, usually for a discussion // List posts, usually for a discussion
$routes->get( $routes->get(
'/posts', $prefix.'/posts',
'flarum.api.posts.index', 'flarum.api.posts.index',
$this->action('Flarum\Api\Actions\Posts\IndexAction') $this->action('Flarum\Api\Actions\Posts\IndexAction')
); );
@ -202,28 +204,28 @@ class ApiServiceProvider extends ServiceProvider
// Create a post // Create a post
// @todo consider 'discussions/{id}/links/posts'? // @todo consider 'discussions/{id}/links/posts'?
$routes->post( $routes->post(
'/posts', $prefix.'/posts',
'flarum.api.posts.create', 'flarum.api.posts.create',
$this->action('Flarum\Api\Actions\Posts\CreateAction') $this->action('Flarum\Api\Actions\Posts\CreateAction')
); );
// Show a single or multiple posts by ID // Show a single or multiple posts by ID
$routes->get( $routes->get(
'/posts/{id}', $prefix.'/posts/{id}',
'flarum.api.posts.show', 'flarum.api.posts.show',
$this->action('Flarum\Api\Actions\Posts\ShowAction') $this->action('Flarum\Api\Actions\Posts\ShowAction')
); );
// Edit a post // Edit a post
$routes->put( $routes->put(
'/posts/{id}', $prefix.'/posts/{id}',
'flarum.api.posts.update', 'flarum.api.posts.update',
$this->action('Flarum\Api\Actions\Posts\UpdateAction') $this->action('Flarum\Api\Actions\Posts\UpdateAction')
); );
// Delete a post // Delete a post
$routes->delete( $routes->delete(
'/posts/{id}', $prefix.'/posts/{id}',
'flarum.api.posts.delete', 'flarum.api.posts.delete',
$this->action('Flarum\Api\Actions\Posts\DeleteAction') $this->action('Flarum\Api\Actions\Posts\DeleteAction')
); );
@ -236,35 +238,35 @@ class ApiServiceProvider extends ServiceProvider
// List groups // List groups
$routes->get( $routes->get(
'/groups', $prefix.'/groups',
'flarum.api.groups.index', 'flarum.api.groups.index',
$this->action('Flarum\Api\Actions\Groups\IndexAction') $this->action('Flarum\Api\Actions\Groups\IndexAction')
); );
// Create a group // Create a group
$routes->post( $routes->post(
'/groups', $prefix.'/groups',
'flarum.api.groups.create', 'flarum.api.groups.create',
$this->action('Flarum\Api\Actions\Groups\CreateAction') $this->action('Flarum\Api\Actions\Groups\CreateAction')
); );
// Show a single group // Show a single group
$routes->get( $routes->get(
'/groups/{id}', $prefix.'/groups/{id}',
'flarum.api.groups.show', 'flarum.api.groups.show',
$this->action('Flarum\Api\Actions\Groups\ShowAction') $this->action('Flarum\Api\Actions\Groups\ShowAction')
); );
// Edit a group // Edit a group
$routes->put( $routes->put(
'/groups/{id}', $prefix.'/groups/{id}',
'flarum.api.groups.update', 'flarum.api.groups.update',
$this->action('Flarum\Api\Actions\Groups\UpdateAction') $this->action('Flarum\Api\Actions\Groups\UpdateAction')
); );
// Delete a group // Delete a group
$routes->delete( $routes->delete(
'/groups/{id}', $prefix.'/groups/{id}',
'flarum.api.groups.delete', 'flarum.api.groups.delete',
$this->action('Flarum\Api\Actions\Groups\DeleteAction') $this->action('Flarum\Api\Actions\Groups\DeleteAction')
); );