-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration with Pencil Spaces (#12)
* Add integration with pencil space * Add test
- Loading branch information
Showing
17 changed files
with
363 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.../2023_08_04_150519_add_meeting_link_type_field_to_consultation_access_enquiries_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 AddMeetingLinkTypeFieldToConsultationAccessEnquiriesTable extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::table('consultation_access_enquiries', function (Blueprint $table) { | ||
$table->string('meeting_link_type')->nullable(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::table('consultation_access_enquiries', function (Blueprint $table) { | ||
$table->dropColumn('meeting_link_type'); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace EscolaLms\ConsultationAccess\Enum; | ||
|
||
class MeetingLinkTypeEnum | ||
{ | ||
public const CUSTOM = 'custom'; | ||
public const PENCIL_SPACES = 'pencil_spaces'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace EscolaLms\ConsultationAccess\Http\Resources; | ||
|
||
use EscolaLms\ConsultationAccess\Enum\MeetingLinkTypeEnum; | ||
use EscolaLms\ConsultationAccess\Models\ConsultationAccessEnquiry; | ||
use EscolaLms\PencilSpaces\Facades\PencilSpace; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
/** | ||
* @OA\Schema( | ||
* schema="JoinConsultationAccessResource", | ||
* @OA\Property( | ||
* property="id", | ||
* description="id", | ||
* type="number" | ||
* ), | ||
* @OA\Property( | ||
* property="meeting_link", | ||
* type="string" | ||
* ), | ||
* @OA\Property( | ||
* property="meeting_link_type", | ||
* type="string" | ||
* ), | ||
* ) | ||
* | ||
*/ | ||
|
||
/** @mixin ConsultationAccessEnquiry */ | ||
class JoinConsultationAccessResource extends JsonResource | ||
{ | ||
public function toArray($request): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'meeting_link_type' => $this->meeting_link_type, | ||
'meeting_link' => $this->meeting_link_type === MeetingLinkTypeEnum::PENCIL_SPACES | ||
? PencilSpace::getDirectLoginUrl(Auth::id(), $this->meeting_link) | ||
: $this->meeting_link, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace EscolaLms\ConsultationAccess\Jobs; | ||
|
||
use EscolaLms\ConsultationAccess\Enum\MeetingLinkTypeEnum; | ||
use EscolaLms\ConsultationAccess\Events\ConsultationAccessEnquiryApprovedEvent; | ||
use EscolaLms\ConsultationAccess\Models\ConsultationAccessEnquiry; | ||
use EscolaLms\ConsultationAccess\Repositories\Contracts\ConsultationAccessEnquiryRepositoryContract; | ||
use EscolaLms\PencilSpaces\Facades\PencilSpace; | ||
use EscolaLms\PencilSpaces\Resource\CreatePencilSpaceResource; | ||
use Exception; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class CreatePencilSpaceJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
private int $consultationAccessEnquiryId; | ||
|
||
public function __construct(int $consultationAccessEnquiryId) | ||
{ | ||
$this->consultationAccessEnquiryId = $consultationAccessEnquiryId; | ||
} | ||
|
||
public function handle(ConsultationAccessEnquiryRepositoryContract $consultationAccessEnquiryRepository): void | ||
{ | ||
try { | ||
/** @var ?ConsultationAccessEnquiry $enquiry */ | ||
$enquiry = $consultationAccessEnquiryRepository->find($this->consultationAccessEnquiryId); | ||
|
||
if (!$enquiry) { | ||
return; | ||
} | ||
|
||
$resource = new CreatePencilSpaceResource( | ||
$enquiry->title ?? 'Consultation X ' . $enquiry->user->name, | ||
collect($enquiry->consultation->author_id), | ||
collect($enquiry->user_id) | ||
); | ||
|
||
$space = PencilSpace::createSpace($resource); | ||
|
||
$consultationAccessEnquiryRepository->update([ | ||
'meeting_link' => Arr::get($space, 'link'), | ||
'meeting_link_type' => MeetingLinkTypeEnum::PENCIL_SPACES, | ||
], $this->consultationAccessEnquiryId); | ||
|
||
event(new ConsultationAccessEnquiryApprovedEvent($enquiry->user, $enquiry)); | ||
} catch (Exception $e) { | ||
Log::error('[ConsultationAccess][CreatePencilSpaceJob] Fails', ['error' => $e->getMessage()]); | ||
$this->fail(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.