Skip to content

Commit fa6e2ec

Browse files
committed
feat: let API reply lists leave out one reply
1 parent 4b00891 commit fa6e2ec

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎app/Http/Controllers/Api/CommitReplyController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
{
1717
public function index(ListApiCommitRepliesRequest $request, #[CurrentUser] User $user, Commit $commit, CommitRepliesQuery $replies): AnonymousResourceCollection
1818
{
19-
return CommitResource::collection($replies->paginate($commit, $user, $request->boolean('newest'))->withQueryString());
19+
return CommitResource::collection($replies->paginate($commit, $user, $request->boolean('newest'), except: $request->exceptedReplyId())->withQueryString());
2020
}
2121
}

‎app/Http/Requests/ListApiCommitRepliesRequest.php‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,22 @@ public function authorize(): Response
2525
return $commit->isVisibleTo($user) ? Response::allow() : Response::denyAsNotFound();
2626
}
2727

28+
public function exceptedReplyId(): ?string
29+
{
30+
return $this->string('except')->value() ?: null;
31+
}
32+
2833
/**
29-
* Newest first continues the next_cursor of a reply preview, as on the web.
34+
* Newest first continues the next_cursor of a reply preview, as on the web. Except leaves out the reply that
35+
* continues the author's thread, which the web shows on its own.
3036
*
3137
* @return array<string, list<string>>
3238
*/
3339
public function rules(): array
3440
{
3541
return [
3642
'newest' => ['sometimes', 'boolean'],
43+
'except' => ['sometimes', 'nullable', 'uuid'],
3744
];
3845
}
3946
}

‎tests/Feature/Controllers/Api/CommitReplyControllerTest.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@
4646
->assertJsonPath('data.0.continuation_id', $next->id);
4747
});
4848

49+
it('leaves out the reply it is asked to, as the web does', function (): void {
50+
$parent = Commit::factory()->create();
51+
$continuation = Commit::factory()->for($parent, 'parent')->for($parent->user)->create(['created_at' => now()->subMinute()]);
52+
$other = Commit::factory()->for($parent, 'parent')->create();
53+
54+
signedApiRequest($this->keyPair, 'GET', route('api-commit-reply.index', [$parent, 'except' => $continuation->id]))
55+
->assertOk()
56+
->assertJsonPath('data.*.id', [$other->id]);
57+
});
58+
59+
it('validates the reply to leave out', function (): void {
60+
signedApiRequest($this->keyPair, 'GET', route('api-commit-reply.index', [Commit::factory()->create(), 'except' => 'not-a-uuid']))
61+
->assertUnprocessable()
62+
->assertJsonValidationErrors('except');
63+
});
64+
4965
it('shows the stars and saves of each reply as the user sees them', function (): void {
5066
$parent = Commit::factory()->create();
5167
$starred = Commit::factory()->for($parent, 'parent')->create(['created_at' => now()->subMinutes(2)]);

0 commit comments

Comments
 (0)