1
0
mirror of https://github.com/flarum/core.git synced 2025-08-07 00:47:00 +02:00

refactor: remove listing of posts in the show discussion endpoint (#4067)

This commit is contained in:
Sami Mazouz
2024-10-16 18:02:46 +01:00
committed by GitHub
parent 40996de39a
commit b0e8f5ca36
12 changed files with 84 additions and 121 deletions

View File

@@ -52,11 +52,6 @@ return [
(new Extend\ApiResource(Resource\ForumResource::class))
->fields(ForumResourceFields::class),
(new Extend\ApiResource(Resource\DiscussionResource::class))
->endpoint(Endpoint\Show::class, function (Endpoint\Show $endpoint) {
return $endpoint->addDefaultInclude(['posts.flags', 'posts.flags.user']);
}),
(new Extend\ApiResource(Resource\PostResource::class))
->endpoint([Endpoint\Index::class, Endpoint\Show::class], function (Endpoint\Index|Endpoint\Show $endpoint) {
return $endpoint->addDefaultInclude(['flags', 'flags.user']);

View File

@@ -50,11 +50,6 @@ return [
}
),
(new Extend\ApiResource(Resource\DiscussionResource::class))
->endpoint(Endpoint\Show::class, function (Endpoint\Show $endpoint): Endpoint\Endpoint {
return $endpoint->addDefaultInclude(['posts.likes']);
}),
(new Extend\Event())
->listen(PostWasLiked::class, Listener\SendNotificationWhenPostIsLiked::class)
->listen(PostWasUnliked::class, Listener\SendNotificationWhenPostIsUnliked::class)

View File

@@ -173,9 +173,10 @@ class ListPostsTest extends TestCase
{
// Show discussion endpoint
$response = $this->send(
$this->request('GET', '/api/discussions/100', [
$this->request('GET', '/api/posts', [
'authenticatedAs' => 2,
])->withQueryParams([
'filter' => ['discussion' => 100],
'include' => $include,
])
);
@@ -184,7 +185,7 @@ class ListPostsTest extends TestCase
$this->assertEquals(200, $response->getStatusCode(), $body);
$included = json_decode($body, true)['included'] ?? [];
$included = json_decode($body, true)['data'] ?? [];
$likes = collect($included)
->where('type', 'posts')
@@ -206,8 +207,7 @@ class ListPostsTest extends TestCase
public static function likesIncludeProvider(): array
{
return [
['posts,posts.likes'],
['posts.likes'],
['likes'],
[null],
];
}

View File

@@ -81,15 +81,6 @@ return [
'lastPost.mentionsPosts.user', 'lastPost.mentionsPosts.discussion', 'lastPost.mentionsGroups',
],
]);
})
->endpoint(Endpoint\Show::class, function (Endpoint\Show $endpoint): Endpoint\Show {
return $endpoint->addDefaultInclude(['posts.mentionedBy', 'posts.mentionedBy.user', 'posts.mentionedBy.discussion'])
->eagerLoadWhenIncluded([
'posts' => [
'posts.mentionsUsers', 'posts.mentionsPosts', 'posts.mentionsPosts.user',
'posts.mentionsPosts.discussion', 'posts.mentionsGroups'
],
]);
}),
(new Extend\ApiResource(Resource\UserResource::class))
@@ -128,9 +119,6 @@ return [
]),
(new Extend\ApiResource(Resource\DiscussionResource::class))
->endpoint(Endpoint\Show::class, function (Endpoint\Show $endpoint): Endpoint\Show {
return $endpoint->eagerLoadWhenIncluded(['posts' => ['posts.mentionsTags']]);
})
->endpoint(Endpoint\Index::class, function (Endpoint\Index $endpoint): Endpoint\Index {
return $endpoint->eagerLoadWhenIncluded(['firstPost' => ['firstPost.mentionsTags'], 'lastPost' => ['lastPost.mentionsTags']]);
}),

View File

@@ -207,14 +207,15 @@ class ListPostsTest extends TestCase
// Show discussion endpoint
$response = $this->send(
$this->request('GET', '/api/discussions/100', [
$this->request('GET', '/api/posts', [
'authenticatedAs' => 2,
])->withQueryParams([
'filter' => ['discussion' => 100],
'include' => $include,
])
);
$included = json_decode($body = $response->getBody()->getContents(), true)['included'] ?? [];
$included = json_decode($body = $response->getBody()->getContents(), true)['data'] ?? [];
$this->assertEquals(200, $response->getStatusCode(), $body);
@@ -233,8 +234,7 @@ class ListPostsTest extends TestCase
public static function mentionedByIncludeProvider(): array
{
return [
['posts,posts.mentionedBy'],
['posts.mentionedBy'],
['mentionedBy'],
[null],
];
}

View File

@@ -178,10 +178,4 @@ return [
return $endpoint
->addDefaultInclude(['eventPostMentionsTags']);
}),
(new Extend\ApiResource(Resource\DiscussionResource::class))
->endpoint(Endpoint\Show::class, function (Endpoint\Show $endpoint) {
return $endpoint
->addDefaultInclude(['posts.eventPostMentionsTags']);
}),
];