Skip to content

Commit

Permalink
Merge pull request #1145 from shikorism/feature/user-checkin-has-link
Browse files Browse the repository at this point in the history
チェックイン一覧API オカズリンクを含むチェックインのみ取得するオプションを追加
  • Loading branch information
shibafu528 authored Dec 25, 2023
2 parents c130bb4 + 2551f20 commit 7aeb146
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/Http/Controllers/Api/V1/UserCheckinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function index(Request $request, User $user)
SQL
))
->where('user_id', $user->id);
if ($request->boolean('has_link')) {
$query = $query->where('link', '<>', '');
}
if (!Auth::check() || $user->id !== Auth::id()) {
$query = $query->where('is_private', false);
}
Expand Down
6 changes: 6 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ paths:
default: 20
minimum: 10
maximum: 100
- name: has_link
in: query
description: オカズリンクを含むチェックインのみ取得
schema:
type: boolean
default: false
responses:
200:
description: 成功
Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/Api/V1/UserCheckinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,30 @@ public function testHidePrivateCheckins()
]
], true);
}

public function testHasLink()
{
$user = User::factory()->create();
Passport::actingAs($user);

$target = User::factory()->create();
$hasLink = Ejaculation::factory()->create([
'user_id' => $target->id,
'link' => 'http://example.com',
]);
Ejaculation::factory()->create([
'user_id' => $target->id,
]);

$response = $this->getJson('/api/v1/users/' . $target->name . '/checkins?has_link=true');

$response->assertStatus(200);
$response->assertHeader('X-Total-Count', 1);
$response->assertJsonCount(1);
$response->assertJson([
[
'id' => $hasLink->id,
]
], true);
}
}

0 comments on commit 7aeb146

Please sign in to comment.