From 0031bdeb33edc22205b074cbcd19eee8f0a50672 Mon Sep 17 00:00:00 2001 From: Maciej Rymarz <59456825+mako321@users.noreply.github.com> Date: Wed, 15 Mar 2023 13:31:01 +0100 Subject: [PATCH] Add meeting link field (#7) --- ...to_consultation_access_enquiries_table.php | 22 ++++++++++ .../ApproveConsultationAccessEnquiryDto.php | 42 +++++++++++++++++++ ...ConsultationAccessEnquiryApprovedEvent.php | 7 ++++ ...ltationAccessEnquiryAdminApiController.php | 2 +- ...nsultationAccessEnquiryAdminApiSwagger.php | 7 ++++ ...pproveConsultationAccessEnquiryRequest.php | 19 +++++++++ .../ConsultationAccessEnquiryResource.php | 6 +++ src/Models/ConsultationAccessEnquiry.php | 2 + .../ConsultationAccessEnquiryService.php | 15 +++++-- ...nsultationAccessEnquiryServiceContract.php | 3 +- ...tationAccessEnquiryAdminApproveApiTest.php | 7 +++- 11 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 database/migrations/2023_03_15_101928_add_meeting_link_field_to_consultation_access_enquiries_table.php create mode 100644 src/Dtos/ApproveConsultationAccessEnquiryDto.php create mode 100644 src/Events/ConsultationAccessEnquiryApprovedEvent.php diff --git a/database/migrations/2023_03_15_101928_add_meeting_link_field_to_consultation_access_enquiries_table.php b/database/migrations/2023_03_15_101928_add_meeting_link_field_to_consultation_access_enquiries_table.php new file mode 100644 index 0000000..69d1f0c --- /dev/null +++ b/database/migrations/2023_03_15_101928_add_meeting_link_field_to_consultation_access_enquiries_table.php @@ -0,0 +1,22 @@ +string('meeting_link')->nullable(); + }); + } + + public function down(): void + { + Schema::table('consultation_access_enquiries', function (Blueprint $table) { + $table->dropColumn('meeting_link'); + }); + } +} diff --git a/src/Dtos/ApproveConsultationAccessEnquiryDto.php b/src/Dtos/ApproveConsultationAccessEnquiryDto.php new file mode 100644 index 0000000..e2bcdf4 --- /dev/null +++ b/src/Dtos/ApproveConsultationAccessEnquiryDto.php @@ -0,0 +1,42 @@ +proposedTermId = $proposedTermId; + $this->meetingLink = $meetingLink; + } + + public function toArray(): array + { + return []; + } + + public function getProposedTermId(): int + { + return $this->proposedTermId; + } + + public function getMeetingLink(): ?string + { + return $this->meetingLink; + } + + public static function instantiateFromRequest(Request $request): ApproveConsultationAccessEnquiryDto + { + return new static( + $request->input('proposed_term_id'), + $request->input('meeting_link') + ); + } +} diff --git a/src/Events/ConsultationAccessEnquiryApprovedEvent.php b/src/Events/ConsultationAccessEnquiryApprovedEvent.php new file mode 100644 index 0000000..5a067d4 --- /dev/null +++ b/src/Events/ConsultationAccessEnquiryApprovedEvent.php @@ -0,0 +1,7 @@ +service->approveByProposedTerm($request->getProposedTermId()); + $this->service->approveByProposedTerm($request->getApproveConsultationAccessEnquiryDto()); return $this->sendSuccess(__('Approved successfully.')); } catch (ConsultationAccessException $e) { return $this->sendError($e->getMessage(), $e->getCode()); diff --git a/src/Http/Controllers/Admin/Swagger/ConsultationAccessEnquiryAdminApiSwagger.php b/src/Http/Controllers/Admin/Swagger/ConsultationAccessEnquiryAdminApiSwagger.php index 8a172fe..6f169c9 100644 --- a/src/Http/Controllers/Admin/Swagger/ConsultationAccessEnquiryAdminApiSwagger.php +++ b/src/Http/Controllers/Admin/Swagger/ConsultationAccessEnquiryAdminApiSwagger.php @@ -132,6 +132,13 @@ public function index(AdminListConsultationAccessEnquiryRequest $request): JsonR * required=true, * in="path" * ), + * @OA\RequestBody( + * required=true, + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema(ref="#/components/schemas/AdminApproveConsultationAccessEnquiryRequest") + * ), + * ), * @OA\Response( * response=200, * description="successful operation", diff --git a/src/Http/Requests/Admin/AdminApproveConsultationAccessEnquiryRequest.php b/src/Http/Requests/Admin/AdminApproveConsultationAccessEnquiryRequest.php index 97465f0..f1839a2 100644 --- a/src/Http/Requests/Admin/AdminApproveConsultationAccessEnquiryRequest.php +++ b/src/Http/Requests/Admin/AdminApproveConsultationAccessEnquiryRequest.php @@ -2,10 +2,23 @@ namespace EscolaLms\ConsultationAccess\Http\Requests\Admin; +use EscolaLms\ConsultationAccess\Dtos\ApproveConsultationAccessEnquiryDto; use EscolaLms\ConsultationAccess\Models\ConsultationAccessEnquiry; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Gate; +/** + * @OA\Schema( + * schema="AdminApproveConsultationAccessEnquiryRequest", + * required={"meeting_link"}, + * @OA\Property( + * property="meeting_link", + * description="meeting_link", + * type="string" + * ), + * ) + * + */ class AdminApproveConsultationAccessEnquiryRequest extends FormRequest { public function authorize(): bool @@ -17,6 +30,7 @@ public function rules(): array { return [ 'proposed_term_id' => ['required', 'integer', 'exists:consultation_access_enquiry_proposed_terms,id'], + 'meeting_link' => ['sometimes', 'string', 'url'], ]; } @@ -29,4 +43,9 @@ protected function prepareForValidation(): void { $this->merge(['proposed_term_id' => $this->getProposedTermId()]); } + + public function getApproveConsultationAccessEnquiryDto(): ApproveConsultationAccessEnquiryDto + { + return ApproveConsultationAccessEnquiryDto::instantiateFromRequest($this); + } } diff --git a/src/Http/Resources/ConsultationAccessEnquiryResource.php b/src/Http/Resources/ConsultationAccessEnquiryResource.php index 7c2c536..61540db 100644 --- a/src/Http/Resources/ConsultationAccessEnquiryResource.php +++ b/src/Http/Resources/ConsultationAccessEnquiryResource.php @@ -39,6 +39,11 @@ * type="string" * ), * @OA\Property( + * property="meeting_link", + * description="meeting_link", + * type="string" + * ), + * @OA\Property( * property="proposed_terms", * ref="#/components/schemas/ConsultationAccessEnquiryProposedTermsResource" * ), @@ -66,6 +71,7 @@ public function toArray($request): array 'proposed_terms' => ConsultationAccessEnquiryProposedTermsResource::collection($this->consultationAccessEnquiryProposedTerms), 'description' => $this->description, 'consultation_term' => $this->consultationUser ? ConsultationTermsResource::make($this->consultationUser) : null, + 'meeting_link' => $this->meeting_link, ]; } } diff --git a/src/Models/ConsultationAccessEnquiry.php b/src/Models/ConsultationAccessEnquiry.php index 4930efa..814d76f 100644 --- a/src/Models/ConsultationAccessEnquiry.php +++ b/src/Models/ConsultationAccessEnquiry.php @@ -20,6 +20,7 @@ * @property string $status * @property string $description * @property int $consultation_user_id + * @property string $meeting_link * * @property-read User $user * @property-read Consultation $consultation @@ -36,6 +37,7 @@ class ConsultationAccessEnquiry extends Model 'status', 'description', 'consultation_user_id', + 'meeting_link', ]; public function consultation(): BelongsTo diff --git a/src/Services/ConsultationAccessEnquiryService.php b/src/Services/ConsultationAccessEnquiryService.php index 8da8aac..28e307a 100644 --- a/src/Services/ConsultationAccessEnquiryService.php +++ b/src/Services/ConsultationAccessEnquiryService.php @@ -2,6 +2,7 @@ namespace EscolaLms\ConsultationAccess\Services; +use EscolaLms\ConsultationAccess\Dtos\ApproveConsultationAccessEnquiryDto; use EscolaLms\ConsultationAccess\Dtos\ConsultationAccessEnquiryDto; use EscolaLms\ConsultationAccess\Dtos\CriteriaDto; use EscolaLms\ConsultationAccess\Dtos\PageDto; @@ -9,6 +10,7 @@ use EscolaLms\ConsultationAccess\Enum\EnquiryStatusEnum; use EscolaLms\ConsultationAccess\Events\ConsultationAccessEnquiryAdminCreatedEvent; use EscolaLms\ConsultationAccess\Events\ConsultationAccessEnquiryAdminUpdatedEvent; +use EscolaLms\ConsultationAccess\Events\ConsultationAccessEnquiryApprovedEvent; use EscolaLms\ConsultationAccess\Events\ConsultationAccessEnquiryDisapprovedEvent; use EscolaLms\ConsultationAccess\Exceptions\ConsultationAccessException; use EscolaLms\ConsultationAccess\Exceptions\EnquiryAlreadyApprovedException; @@ -80,9 +82,9 @@ public function create(ConsultationAccessEnquiryDto $dto): ConsultationAccessEnq /** * @throws ConsultationAccessException */ - public function approveByProposedTerm(int $proposedTermId): void + public function approveByProposedTerm(ApproveConsultationAccessEnquiryDto $dto): void { - $proposedTerm = $this->proposedTermRepository->findById($proposedTermId); + $proposedTerm = $this->proposedTermRepository->findById($dto->getProposedTermId()); $enquiry = $proposedTerm->consultationAccessEnquiry; if ($enquiry->status === EnquiryStatusEnum::APPROVED) { @@ -93,12 +95,17 @@ public function approveByProposedTerm(int $proposedTermId): void throw new TermIsBusyException(); } - DB::transaction(function () use ($enquiry, $proposedTerm) { + DB::transaction(function () use ($enquiry, $proposedTerm, $dto) { $consultationUser = $this->createConsultationUser($proposedTerm); - $this->accessEnquiryRepository->update([ + + /** @var ConsultationAccessEnquiry $enquiry */ + $enquiry = $this->accessEnquiryRepository->update([ 'consultation_user_id' => $consultationUser->getKey(), 'status' => EnquiryStatusEnum::APPROVED, + 'meeting_link' => $dto->getMeetingLink(), ], $enquiry->getKey()); + + event(new ConsultationAccessEnquiryApprovedEvent($enquiry->user, $enquiry)); }); } diff --git a/src/Services/Contracts/ConsultationAccessEnquiryServiceContract.php b/src/Services/Contracts/ConsultationAccessEnquiryServiceContract.php index e816292..eede906 100644 --- a/src/Services/Contracts/ConsultationAccessEnquiryServiceContract.php +++ b/src/Services/Contracts/ConsultationAccessEnquiryServiceContract.php @@ -2,6 +2,7 @@ namespace EscolaLms\ConsultationAccess\Services\Contracts; +use EscolaLms\ConsultationAccess\Dtos\ApproveConsultationAccessEnquiryDto; use EscolaLms\ConsultationAccess\Dtos\ConsultationAccessEnquiryDto; use EscolaLms\ConsultationAccess\Dtos\CriteriaDto; use EscolaLms\ConsultationAccess\Dtos\PageDto; @@ -17,7 +18,7 @@ public function findAll(CriteriaDto $criteriaDto, PageDto $paginationDto, int $u /** * @throws ConsultationAccessException */ - public function approveByProposedTerm(int $proposedTermId): void; + public function approveByProposedTerm(ApproveConsultationAccessEnquiryDto $dto): void; public function disapprove(int $id, ?string $message): void; diff --git a/tests/Api/Admin/ConsultationAccessEnquiryAdminApproveApiTest.php b/tests/Api/Admin/ConsultationAccessEnquiryAdminApproveApiTest.php index df18d8d..051bce8 100644 --- a/tests/Api/Admin/ConsultationAccessEnquiryAdminApproveApiTest.php +++ b/tests/Api/Admin/ConsultationAccessEnquiryAdminApproveApiTest.php @@ -31,9 +31,11 @@ public function testConsultationAccessEnquiryAdminApprove(): void { /** @var ConsultationAccessEnquiryProposedTerm $proposedTerm */ $proposedTerm = ConsultationAccessEnquiryProposedTerm::factory()->create(); - + $meetingLink = $this->faker->url; $this->actingAs($this->makeAdmin(), 'api') - ->postJson('api/admin/consultation-access-enquiries/approve/' . $proposedTerm->getKey()) + ->postJson('api/admin/consultation-access-enquiries/approve/' . $proposedTerm->getKey(), [ + 'meeting_link' => $meetingLink, + ]) ->assertOk(); $proposedTerm->refresh(); @@ -41,6 +43,7 @@ public function testConsultationAccessEnquiryAdminApprove(): void $this->assertDatabaseHas('consultation_access_enquiries', [ 'status' => EnquiryStatusEnum::APPROVED, 'consultation_id' => $proposedTerm->consultationAccessEnquiry->consultation_id, + 'meeting_link' => $meetingLink, ]); $this->assertDatabaseHas('consultation_user', [