Skip to content

Commit

Permalink
Add additional columns (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
mako321 authored Mar 20, 2023
1 parent 7e102de commit 72c869c
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 4 deletions.
5 changes: 5 additions & 0 deletions database/factories/ConsultationAccessEnquiryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@
use EscolaLms\Consultations\Enum\ConsultationTermStatusEnum;
use EscolaLms\Consultations\Models\ConsultationUserPivot;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class ConsultationAccessEnquiryFactory extends Factory
{
protected $model = ConsultationAccessEnquiry::class;

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),
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

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

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

public function down(): void
{
Schema::table('consultation_access_enquiries', function (Blueprint $table) {
$table->dropMorphs('related');
$table->dropColumn('title');
});
}
}
16 changes: 14 additions & 2 deletions src/Dtos/ConsultationAccessEnquiryDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
];
}

Expand All @@ -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'),
);
}
}
16 changes: 14 additions & 2 deletions src/Dtos/UpdateConsultationAccessEnquiryDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,14 +36,20 @@ public function toArray(): array
{
return [
'description' => $this->description,
'title' => $this->title,
'related_type' => $this->relatedType,
'related_id' => $this->relatedId,
];
}

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'),
);
}
}
18 changes: 18 additions & 0 deletions src/Http/Requests/CreateConsultationAccessEnquiryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'],
];
}

Expand Down
18 changes: 18 additions & 0 deletions src/Http/Requests/UpdateConsultationAccessEnquiryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'],
];
}

Expand Down
18 changes: 18 additions & 0 deletions src/Http/Resources/ConsultationAccessEnquiryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
* ),
* )
*
*/
Expand All @@ -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,
];
}
}
12 changes: 12 additions & 0 deletions src/Models/ConsultationAccessEnquiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -38,6 +42,9 @@ class ConsultationAccessEnquiry extends Model
'description',
'consultation_user_id',
'meeting_link',
'title',
'related_type',
'related_id',
];

public function consultation(): BelongsTo
Expand All @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/Api/Admin/ConsultationAccessEnquiryAdminListApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public function testConsultationAccessEnquiryAdminList(callable $filter, int $co
],
'proposed_terms',
'description',
'title',
'related_type',
'related_id',
]],
]);
}
Expand Down

0 comments on commit 72c869c

Please sign in to comment.