Skip to content

Commit

Permalink
Add filter by consultation terms (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
mako321 authored Aug 23, 2023
1 parent 2359904 commit 1f621d3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Dtos/CriteriaDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use EscolaLms\Core\Dtos\CriteriaDto as BaseCriteriaDto;
use EscolaLms\Core\Repositories\Criteria\Primitives\EqualCriterion;
use EscolaLms\Core\Repositories\Criteria\Primitives\HasCriterion;
use EscolaLms\Core\Repositories\Criteria\Primitives\InCriterion;
use EscolaLms\Core\Repositories\Criteria\Primitives\WhereCriterion;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -46,6 +47,9 @@ public static function instantiateFromRequest(Request $request): self
$query->whereDate('proposed_at', '<=', Carbon::make($request->get('proposed_at_to')));
}));
}
if ($request->get('consultation_term_ids')) {
$criteria->push(new InCriterion('consultation_user_id', $request->get('consultation_term_ids')));
}

return new static($criteria);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ interface ConsultationAccessEnquiryApiSwagger
* enum={"true", "false"}
* ),
* ),
* @OA\Parameter(
* name="consultation_term_ids[]",
* required=false,
* in="query",
* @OA\Schema(
* type="array",
* @OA\Items(
* @OA\Schema(
* type="integer"
* ),
* ),
* ),
* ),
* @OA\Response(
* response=200,
* description="Successfull operation",
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Requests/ListConsultationAccessEnquiryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function rules(): array
return [
'order' => ['sometimes', 'string', 'in:ASC,DESC'],
'order_by' => ['sometimes', 'string', 'in:id,consultation_id,status,description,user_id,meeting_link,created_at,term_date'],
'consultation_term_ids' => ['sometimes', 'array'],
'consultation_term_ids.*' => ['integer'],
];
}

Expand Down
6 changes: 6 additions & 0 deletions src/Http/Resources/ConsultationAccessEnquiryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
* ref="#/components/schemas/ConsultationShortResource"
* ),
* @OA\Property(
* property="consultation_term_id",
* description="consultation_term_id",
* type="integer"
* ),
* @OA\Property(
* property="user",
* ref="#/components/schemas/ConsultationUserShortResource"
* ),
Expand Down Expand Up @@ -82,6 +87,7 @@ public function toArray($request): array
'created_at' => $this->created_at,
'status' => $this->status,
'consultation' => ConsultationShortResource::make($this->consultation),
'consultation_term_id' => $this->consultation_user_id,
'user' => UserShortResource::make($this->user),
'proposed_terms' => ConsultationAccessEnquiryProposedTermsResource::collection($this->consultationAccessEnquiryProposedTerms),
'description' => $this->description,
Expand Down
8 changes: 7 additions & 1 deletion tests/Api/ConsultationAccessEnquiryListApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function testConsultationAccessEnquiryList(): void
'id',
'name',
],
'consultation_term_id',
'user' => [
'id',
'name',
Expand All @@ -76,7 +77,8 @@ public function testConsultationAccessEnquiryListFiltering(): void
->has(ConsultationAccessEnquiryProposedTerm::factory()->state(['proposed_at' => Carbon::now()]))
->create();

ConsultationAccessEnquiry::factory()
/** @var ConsultationAccessEnquiry $approved */
$approved = ConsultationAccessEnquiry::factory()
->state(['user_id' => $student->getKey()])
->approved()
->has(ConsultationAccessEnquiryProposedTerm::factory()->state(['proposed_at' => Carbon::now()->addDays(3)]))
Expand All @@ -93,6 +95,10 @@ public function testConsultationAccessEnquiryListFiltering(): void
$this->actingAs($student, 'api')->getJson('api/consultation-access-enquiries?is_coming=1')
->assertOk()
->assertJsonCount(1, 'data');

$this->actingAs($student, 'api')->getJson('api/consultation-access-enquiries?consultation_term_ids[]=' . $approved->consultation_user_id)
->assertOk()
->assertJsonCount(1, 'data');
}

public function testConsultationAccessEnquiryListPagination(): void
Expand Down
1 change: 1 addition & 0 deletions tests/Api/ConsultationAccessEnquiryReadApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function testConsultationAccessEnquiryRead(): void
'id',
'name',
],
'consultation_term_id',
'user' => [
'id',
'name',
Expand Down

0 comments on commit 1f621d3

Please sign in to comment.