Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
milwad-dev committed Nov 1, 2024
1 parent 1b8baab commit c4f1174
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Modules/Category/Http/Requests/CategoryUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function rules(): array
'string',
'min:3',
'max:250',
Rule::unique('categories', 'title')->ignore($this->route()->parameter('category')), // TODO: Improve validation
Rule::unique('categories', 'title')->ignore($this->route()->parameter('category')),
],
];
}
Expand Down
20 changes: 0 additions & 20 deletions Modules/Common/helpers.php
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
<?php

if (!function_exists('get_enum_values')) {
/**
* Get values from enum file.
*
* @param array $data
*
* @return array
*/
function get_enum_values(array $data)
{
$values = [];

foreach ($data as $value) {
$values[] = $value->value;
}

return $values;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ public function up(): void
{
Schema::create('tasks', function (Blueprint $table) {
$table->id();

$table->string('title');
$table->string('priority');
$table->string('status')->nullable();

$table->longText('description');
$table->timestamp('remind_date')->nullable();
$table->enum('priority', get_enum_values(TaskPriorityEnum::cases()));
$table->enum('status', get_enum_values(TaskStatusEnum::cases()))->nullable();
// TODO: Add label
$table->timestamps();
});
Expand Down
7 changes: 3 additions & 4 deletions Modules/Task/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,20 @@ public function show(Task $task)
/**
* Update the specified resource in storage.
*/
public function update(UpdateTaskRequest $request, Task $task)
public function update(UpdateTaskRequest $request, Task $task): \Illuminate\Http\JsonResponse
{
resolve(TaskService::class)->update($request->validated(), $task);

return (new TaskResource($task))
->response()
->setStatusCode(202); // TODO: Refresh new task
->setStatusCode(204);
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Task $task)
public function destroy(Task $task): \Illuminate\Foundation\Application|\Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
{
// TODO: Add some condition
$task->delete();

return response([], Response::HTTP_NO_CONTENT);
Expand Down
4 changes: 1 addition & 3 deletions Modules/Task/Http/Requests/StoreTaskRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ public function authorize(): bool

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
public function rules(): array
{
return [
'title' => 'required|string|min:3|max:255',
'description' => 'required|string|min:3',
'remind_date' => 'required|string', // TODO: ADD MORE RULES
'remind_date' => 'required|string',
'priority' => ['required', 'string', new Enum(TaskPriorityEnum::class), 'max:250'],
'status' => ['required', 'string', new Enum(TaskStatusEnum::class), 'max:250'],
];
Expand Down
4 changes: 1 addition & 3 deletions Modules/Task/Http/Requests/UpdateTaskRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ public function authorize(): bool

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
public function rules(): array
{
return [
'title' => 'required|string|min:3|max:255',
'description' => 'required|string|min:3',
'remind_date' => 'required|string', // TODO: ADD MORE RULES
'remind_date' => 'required|string',
'priority' => ['required', 'string', new Enum(TaskPriorityEnum::class), 'max:250'],
'status' => ['required', 'string', new Enum(TaskStatusEnum::class), 'max:250'],
];
Expand Down
24 changes: 14 additions & 10 deletions Modules/Task/Models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ class Task extends Model
use HasFactory;

/**
* Set factory.
* Fillable columns.
*
* @return TaskFactory
* @var string[]
*/
protected static function newFactory()
{
return TaskFactory::new();
}
protected $fillable = [
'title',
'description',
'remind_date',
'priority',
'status'
];

/**
* Fillable columns.
*
* @var string[]
* Set factory for model.
*/
protected $fillable = ['title', 'description', 'remind_date', 'priority', 'status'];
protected static function newFactory(): TaskFactory
{
return TaskFactory::new();
}
}

0 comments on commit c4f1174

Please sign in to comment.