diff --git a/database/factories/ConsultationAccessEnquiryFactory.php b/database/factories/ConsultationAccessEnquiryFactory.php index 181aabe..444c322 100644 --- a/database/factories/ConsultationAccessEnquiryFactory.php +++ b/database/factories/ConsultationAccessEnquiryFactory.php @@ -9,6 +9,7 @@ use EscolaLms\Consultations\Enum\ConsultationTermStatusEnum; use EscolaLms\Consultations\Models\ConsultationUserPivot; use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Support\Str; class ConsultationAccessEnquiryFactory extends Factory { @@ -16,11 +17,15 @@ class ConsultationAccessEnquiryFactory extends Factory public function definition(): array { + $type = Str::ucfirst($this->faker->word) . $this->faker->numberBetween(); + return [ 'consultation_id' => Consultation::factory(), 'user_id' => User::factory(), 'status' => EnquiryStatusEnum::PENDING, 'description' => $this->faker->text(), + 'related_type' => 'EscolaLms\\' . $type . '\\Models\\' . $type, + 'related_id' => $this->faker->numberBetween(1), ]; } diff --git a/database/migrations/2023_03_20_100826_add_additional_columns_to_consultation_access_enquiries_table.php b/database/migrations/2023_03_20_100826_add_additional_columns_to_consultation_access_enquiries_table.php new file mode 100644 index 0000000..b8da8d9 --- /dev/null +++ b/database/migrations/2023_03_20_100826_add_additional_columns_to_consultation_access_enquiries_table.php @@ -0,0 +1,24 @@ +nullableMorphs('related'); + $table->string('title')->nullable(); + }); + } + + public function down(): void + { + Schema::table('consultation_access_enquiries', function (Blueprint $table) { + $table->dropMorphs('related'); + $table->dropColumn('title'); + }); + } +} diff --git a/src/Dtos/ConsultationAccessEnquiryDto.php b/src/Dtos/ConsultationAccessEnquiryDto.php index c01a4e4..dc2303f 100644 --- a/src/Dtos/ConsultationAccessEnquiryDto.php +++ b/src/Dtos/ConsultationAccessEnquiryDto.php @@ -15,14 +15,20 @@ class ConsultationAccessEnquiryDto implements DtoContract, InstantiateFromReques protected string $status; protected array $proposedTerms; protected ?string $description; + protected ?string $title; + protected ?string $relatedType; + protected ?int $relatedId; - public function __construct(int $consultationId, int $userId, string $status, array $proposedTerms, ?string $description) + public function __construct(int $consultationId, int $userId, string $status, array $proposedTerms, ?string $description, ?string $title, ?string $relatedType, ?int $relatedId) { $this->consultationId = $consultationId; $this->userId = $userId; $this->status = $status; $this->proposedTerms = $proposedTerms; $this->description = $description; + $this->title = $title; + $this->relatedType = $relatedType; + $this->relatedId = $relatedId; } public function getConsultationId(): int @@ -52,6 +58,9 @@ public function toArray(): array 'user_id' => $this->getUserId(), 'status' => $this->status, 'description' => $this->description, + 'title' => $this->title, + 'related_type' => $this->relatedType, + 'related_id' => $this->relatedId, ]; } @@ -62,7 +71,10 @@ public static function instantiateFromRequest(Request $request): self auth()->id(), EnquiryStatusEnum::PENDING, $request->input('proposed_terms'), - $request->input('description') + $request->input('description'), + $request->input('title'), + $request->input('related_type'), + $request->input('related_id'), ); } } diff --git a/src/Dtos/UpdateConsultationAccessEnquiryDto.php b/src/Dtos/UpdateConsultationAccessEnquiryDto.php index 57f3ebc..7757ff9 100644 --- a/src/Dtos/UpdateConsultationAccessEnquiryDto.php +++ b/src/Dtos/UpdateConsultationAccessEnquiryDto.php @@ -12,11 +12,17 @@ class UpdateConsultationAccessEnquiryDto implements DtoContract, InstantiateFrom { protected array $proposedTerms; protected ?string $description; + protected ?string $title; + protected ?string $relatedType; + protected ?int $relatedId; - public function __construct(array $proposedTerms, ?string $description) + public function __construct(array $proposedTerms, ?string $description, ?string $title, ?string $relatedType, ?int $relatedId) { $this->proposedTerms = $proposedTerms; $this->description = $description; + $this->title = $title; + $this->relatedType = $relatedType; + $this->relatedId = $relatedId; } public function getProposedTerms(): array @@ -30,6 +36,9 @@ public function toArray(): array { return [ 'description' => $this->description, + 'title' => $this->title, + 'related_type' => $this->relatedType, + 'related_id' => $this->relatedId, ]; } @@ -37,7 +46,10 @@ public static function instantiateFromRequest(Request $request): self { return new static( $request->input('proposed_terms'), - $request->input('description') + $request->input('description'), + $request->input('title'), + $request->input('related_type'), + $request->input('related_id'), ); } } diff --git a/src/Http/Requests/CreateConsultationAccessEnquiryRequest.php b/src/Http/Requests/CreateConsultationAccessEnquiryRequest.php index c0c89de..fe2dd6e 100644 --- a/src/Http/Requests/CreateConsultationAccessEnquiryRequest.php +++ b/src/Http/Requests/CreateConsultationAccessEnquiryRequest.php @@ -22,6 +22,21 @@ * type="string" * ), * @OA\Property( + * property="title", + * description="title", + * type="string" + * ), + * @OA\Property( + * property="related_type", + * description="related_type", + * type="string" + * ), + * @OA\Property( + * property="related_id", + * description="related_id", + * type="integer" + * ), + * @OA\Property( * property="proposed_terms", * type="array", * @OA\Items( @@ -46,6 +61,9 @@ public function rules(): array 'proposed_terms' => ['required', 'array', 'min:1'], 'proposed_terms.*' => ['required', 'date', 'after_or_equal:now'], 'description' => ['nullable', 'string', 'max:255'], + 'related_type' => ['nullable', 'string', 'required_with:related_id'], + 'related_id' => ['nullable', 'integer', 'required_with:related_type'], + 'title' => ['nullable', 'string', 'max:255'], ]; } diff --git a/src/Http/Requests/UpdateConsultationAccessEnquiryRequest.php b/src/Http/Requests/UpdateConsultationAccessEnquiryRequest.php index 17c9422..ba344a7 100644 --- a/src/Http/Requests/UpdateConsultationAccessEnquiryRequest.php +++ b/src/Http/Requests/UpdateConsultationAccessEnquiryRequest.php @@ -18,6 +18,21 @@ * type="string" * ), * @OA\Property( + * property="title", + * description="title", + * type="string" + * ), + * @OA\Property( + * property="related_type", + * description="related_type", + * type="string" + * ), + * @OA\Property( + * property="related_id", + * description="related_id", + * type="integer" + * ), + * @OA\Property( * property="proposed_terms", * type="array", * @OA\Items( @@ -41,6 +56,9 @@ public function rules(): array 'description' => ['nullable', 'string', 'max:255'], 'proposed_terms' => ['required', 'array', 'min:1'], 'proposed_terms.*' => ['required', 'date', 'after_or_equal:now'], + 'related_type' => ['nullable', 'string', 'required_with:related_id'], + 'related_id' => ['nullable', 'integer', 'required_with:related_type'], + 'title' => ['nullable', 'string', 'max:255'], ]; } diff --git a/src/Http/Resources/ConsultationAccessEnquiryResource.php b/src/Http/Resources/ConsultationAccessEnquiryResource.php index 61540db..7fe4b22 100644 --- a/src/Http/Resources/ConsultationAccessEnquiryResource.php +++ b/src/Http/Resources/ConsultationAccessEnquiryResource.php @@ -51,6 +51,21 @@ * property="consultation_term", * ref="#/components/schemas/ConsultationTerm" * ), + * @OA\Property( + * property="related_type", + * description="related_type", + * type="string" + * ), + * @OA\Property( + * property="related_id", + * description="related_id", + * type="integer" + * ), + * @OA\Property( + * property="title", + * description="title", + * type="string" + * ), * ) * */ @@ -72,6 +87,9 @@ public function toArray($request): array 'description' => $this->description, 'consultation_term' => $this->consultationUser ? ConsultationTermsResource::make($this->consultationUser) : null, 'meeting_link' => $this->meeting_link, + 'related_type' => $this->related_type, + 'related_id' => $this->related_id, + 'title' => $this->title, ]; } } diff --git a/src/Models/ConsultationAccessEnquiry.php b/src/Models/ConsultationAccessEnquiry.php index 814d76f..a613f40 100644 --- a/src/Models/ConsultationAccessEnquiry.php +++ b/src/Models/ConsultationAccessEnquiry.php @@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphTo; /** * EscolaLms\ConsultationAccess\Models\ConsultationAccessEnquiry @@ -21,6 +22,9 @@ * @property string $description * @property int $consultation_user_id * @property string $meeting_link + * @property ?string $title + * @property ?string $related_type + * @property ?int $related_id * * @property-read User $user * @property-read Consultation $consultation @@ -38,6 +42,9 @@ class ConsultationAccessEnquiry extends Model 'description', 'consultation_user_id', 'meeting_link', + 'title', + 'related_type', + 'related_id', ]; public function consultation(): BelongsTo @@ -60,6 +67,11 @@ public function consultationAccessEnquiryProposedTerms(): HasMany return $this->hasMany(ConsultationAccessEnquiryProposedTerm::class); } + public function related(): MorphTo + { + return $this->morphTo('related'); + } + public static function newFactory(): ConsultationAccessEnquiryFactory { return ConsultationAccessEnquiryFactory::new(); diff --git a/tests/Api/Admin/ConsultationAccessEnquiryAdminListApiTest.php b/tests/Api/Admin/ConsultationAccessEnquiryAdminListApiTest.php index 32a21cf..d2d451f 100644 --- a/tests/Api/Admin/ConsultationAccessEnquiryAdminListApiTest.php +++ b/tests/Api/Admin/ConsultationAccessEnquiryAdminListApiTest.php @@ -72,6 +72,9 @@ public function testConsultationAccessEnquiryAdminList(callable $filter, int $co ], 'proposed_terms', 'description', + 'title', + 'related_type', + 'related_id', ]], ]); }