This repository has been archived by the owner on Sep 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathroutes.php
95 lines (80 loc) · 3.81 KB
/
routes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
use Conduit\Controllers\Article\ArticleController;
use Conduit\Controllers\Article\CommentController;
use Conduit\Controllers\Article\FavoriteController;
use Conduit\Controllers\Auth\LoginController;
use Conduit\Controllers\Auth\RegisterController;
use Conduit\Controllers\User\ProfileController;
use Conduit\Controllers\User\UserController;
use Conduit\Middleware\OptionalAuth;
use Conduit\Models\Tag;
use Slim\Http\Request;
use Slim\Http\Response;
// Api Routes
$app->group('/api',
function () {
$jwtMiddleware = $this->getContainer()->get('jwt');
$optionalAuth = $this->getContainer()->get('optionalAuth');
/** @var \Slim\App $this */
// Auth Routes
$this->post('/users', RegisterController::class . ':register')->setName('auth.register');
$this->post('/users/login', LoginController::class . ':login')->setName('auth.login');
// User Routes
$this->get('/user', UserController::class . ':show')->add($jwtMiddleware)->setName('user.show');
$this->put('/user', UserController::class . ':update')->add($jwtMiddleware)->setName('user.update');
// Profile Routes
$this->get('/profiles/{username}', ProfileController::class . ':show')
->add($optionalAuth)
->setName('profile.show');
$this->post('/profiles/{username}/follow', ProfileController::class . ':follow')
->add($jwtMiddleware)
->setName('profile.follow');
$this->delete('/profiles/{username}/follow', ProfileController::class . ':unfollow')
->add($jwtMiddleware)
->setName('profile.unfollow');
// Articles Routes
$this->get('/articles/feed', ArticleController::class . ':index')->add($optionalAuth)->setName('article.index');
$this->get('/articles/{slug}', ArticleController::class . ':show')->add($optionalAuth)->setName('article.show');
$this->put('/articles/{slug}',
ArticleController::class . ':update')->add($jwtMiddleware)->setName('article.update');
$this->delete('/articles/{slug}',
ArticleController::class . ':destroy')->add($jwtMiddleware)->setName('article.destroy');
$this->post('/articles', ArticleController::class . ':store')->add($jwtMiddleware)->setName('article.store');
$this->get('/articles', ArticleController::class . ':index')->add($optionalAuth)->setName('article.index');
// Comments
$this->get('/articles/{slug}/comments',
CommentController::class . ':index')
->add($optionalAuth)
->setName('comment.index');
$this->post('/articles/{slug}/comments',
CommentController::class . ':store')
->add($jwtMiddleware)
->setName('comment.store');
$this->delete('/articles/{slug}/comments/{id}',
CommentController::class . ':destroy')
->add($jwtMiddleware)
->setName('comment.destroy');
// Favorite Article Routes
$this->post('/articles/{slug}/favorite',
FavoriteController::class . ':store')
->add($jwtMiddleware)
->setName('favorite.store');
$this->delete('/articles/{slug}/favorite',
FavoriteController::class . ':destroy')
->add($jwtMiddleware)
->setName('favorite.destroy');
// Tags Route
$this->get('/tags', function (Request $request, Response $response) {
return $response->withJson([
'tags' => Tag::all('title')->pluck('title'),
]);
});
});
// Routes
$app->get('/[{name}]',
function (Request $request, Response $response, array $args) {
// Sample log message
$this->logger->info("Slim-Skeleton '/' route");
// Render index view
return $this->renderer->render($response, 'index.phtml', $args);
});