-
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.
refactor: moved data handling logic from service to value objects
- Loading branch information
1 parent
9c88018
commit f46dc80
Showing
8 changed files
with
131 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\ValueObjects\CreateCourseRegistration; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class StoreCourseRegistrationRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function getCourseRegistration(int $courseId): CreateCourseRegistration | ||
{ | ||
return new CreateCourseRegistration( | ||
$courseId, | ||
auth()->id() | ||
); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace App\ValueObjects; | ||
|
||
use App\Enums\RegistrationStatus; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
final readonly class CreateCourseRegistration implements Arrayable | ||
{ | ||
public function __construct(private int $courseId, private int $userId) {} | ||
|
||
public function getCourseId(): int | ||
{ | ||
return $this->courseId; | ||
} | ||
public function getUserId(): int | ||
{ | ||
return $this->userId; | ||
} | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'course_id' => $this->getCourseId(), | ||
'user_id' => $this->getUserId(), | ||
'status' => RegistrationStatus::PENDING->value, | ||
]; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace App\ValueObjects; | ||
|
||
use App\Enums\RegistrationStatus; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
final readonly class UpdateCourseRegistration implements Arrayable{ | ||
public function __construct(private RegistrationStatus $status) {} | ||
|
||
public function getStatus(): RegistrationStatus{ | ||
return $this->status; | ||
} | ||
|
||
public function toArray(): array { | ||
return [ | ||
'status' => $this->getStatus()->value | ||
]; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Enums\RegistrationStatus; | ||
use App\Models\Course; | ||
use App\Models\User; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\CourseRegistration> | ||
*/ | ||
class CourseRegistrationFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'course_id' => Course::factory(), | ||
'user_id' => User::factory(), | ||
'status' => RegistrationStatus::PENDING->value, | ||
]; | ||
} | ||
} |