Skip to content

Commit

Permalink
Add meeting link field (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mako321 authored Mar 15, 2023
1 parent 7b2e6a5 commit 0031bde
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddMeetingLinkFieldToConsultationAccessEnquiriesTable extends Migration
{
public function up(): void
{
Schema::table('consultation_access_enquiries', function (Blueprint $table) {
$table->string('meeting_link')->nullable();
});
}

public function down(): void
{
Schema::table('consultation_access_enquiries', function (Blueprint $table) {
$table->dropColumn('meeting_link');
});
}
}
42 changes: 42 additions & 0 deletions src/Dtos/ApproveConsultationAccessEnquiryDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace EscolaLms\ConsultationAccess\Dtos;

use EscolaLms\Core\Dtos\Contracts\DtoContract;
use EscolaLms\Core\Dtos\Contracts\InstantiateFromRequest;
use Illuminate\Http\Request;

class ApproveConsultationAccessEnquiryDto implements DtoContract, InstantiateFromRequest
{
private int $proposedTermId;
private ?string $meetingLink;

public function __construct(int $proposedTermId, ?string $meetingLink)
{
$this->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')
);
}
}
7 changes: 7 additions & 0 deletions src/Events/ConsultationAccessEnquiryApprovedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace EscolaLms\ConsultationAccess\Events;

class ConsultationAccessEnquiryApprovedEvent extends ConsultationAccessEnquiryEvent
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function index(AdminListConsultationAccessEnquiryRequest $request): JsonR
public function approve(AdminApproveConsultationAccessEnquiryRequest $request): JsonResponse
{
try {
$this->service->approveByProposedTerm($request->getProposedTermId());
$this->service->approveByProposedTerm($request->getApproveConsultationAccessEnquiryDto());
return $this->sendSuccess(__('Approved successfully.'));
} catch (ConsultationAccessException $e) {
return $this->sendError($e->getMessage(), $e->getCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'],
];
}

Expand All @@ -29,4 +43,9 @@ protected function prepareForValidation(): void
{
$this->merge(['proposed_term_id' => $this->getProposedTermId()]);
}

public function getApproveConsultationAccessEnquiryDto(): ApproveConsultationAccessEnquiryDto
{
return ApproveConsultationAccessEnquiryDto::instantiateFromRequest($this);
}
}
6 changes: 6 additions & 0 deletions src/Http/Resources/ConsultationAccessEnquiryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
* ),
Expand Down Expand Up @@ -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,
];
}
}
2 changes: 2 additions & 0 deletions src/Models/ConsultationAccessEnquiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +37,7 @@ class ConsultationAccessEnquiry extends Model
'status',
'description',
'consultation_user_id',
'meeting_link',
];

public function consultation(): BelongsTo
Expand Down
15 changes: 11 additions & 4 deletions src/Services/ConsultationAccessEnquiryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace EscolaLms\ConsultationAccess\Services;

use EscolaLms\ConsultationAccess\Dtos\ApproveConsultationAccessEnquiryDto;
use EscolaLms\ConsultationAccess\Dtos\ConsultationAccessEnquiryDto;
use EscolaLms\ConsultationAccess\Dtos\CriteriaDto;
use EscolaLms\ConsultationAccess\Dtos\PageDto;
use EscolaLms\ConsultationAccess\Dtos\UpdateConsultationAccessEnquiryDto;
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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ 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();

$this->assertDatabaseHas('consultation_access_enquiries', [
'status' => EnquiryStatusEnum::APPROVED,
'consultation_id' => $proposedTerm->consultationAccessEnquiry->consultation_id,
'meeting_link' => $meetingLink,
]);

$this->assertDatabaseHas('consultation_user', [
Expand Down

0 comments on commit 0031bde

Please sign in to comment.