Packagify the TaskFighter part of the application#1
Conversation
JustinShift
left a comment
There was a problem hiding this comment.
The code that is in your /packages dir is missing from the PR
| public function boot() | ||
| { | ||
| // | ||
| } |
There was a problem hiding this comment.
This is a problem, I think you need to call parent or comment out the stub method.
| | Here is where you can register API routes for TaskFighter. | ||
| | | ||
| | Assumed: | ||
| | - prefix = api/tasks |
There was a problem hiding this comment.
This is a lie check service provider
| $taskFighter = new \App\Models\Task($task->name, $task->priority, $task->due_in); | ||
| $taskFighter->tick(); | ||
| DB::update("update tasks set priority = '{$taskFighter->priority}', due_in = '{$taskFighter->due_in}' where id = '{$task->id}'"); |
There was a problem hiding this comment.
You creating a model and then doing the update in plain SQL?
| */ | ||
|
|
||
|
|
||
| Route::get('list/tick', function (Response $response) { |
There was a problem hiding this comment.
Why is this not in a controller, why inline and why DB::table instead of Task:all().
| $tasks = DB::table('tasks')->select('*')->get(); | ||
| foreach ($tasks as $task) { | ||
| $taskFighter = new \App\Models\Task($task->name, $task->priority, $task->due_in); | ||
| $taskFighter->tick(); | ||
| DB::update("update tasks set priority = '{$taskFighter->priority}', due_in = '{$taskFighter->due_in}' where id = '{$task->id}'"); |
There was a problem hiding this comment.
This needs a rewrite. I suggest having a look at Collection higher order messages support.
I think you can do this with:
Task:all()->each->tick()->each->save();If that does not work and you want to do it in one loop you can do this.
Task::all()->each(function(Task $task) {
$task->tick();
$task->save();
});Rer: https://laravel.com/docs/5.5/collections#higher-order-messages
| "psr-4": { | ||
| "App\\": "app/" | ||
| "App\\": "app/", | ||
| "": "app/Packages/" |
| Route::get('list/tick', function (Response $response) { | ||
| $tasks = DB::table('tasks')->select('*')->get(); | ||
| foreach ($tasks as $task) { | ||
| $taskFighter = new \App\Task($task->name, $task->priority, $task->due_in); | ||
| $taskFighter->tick(); | ||
| DB::update("update tasks set priority = '{$taskFighter->priority}', due_in = '{$taskFighter->due_in}' where id = '{$task->id}'"); | ||
| } | ||
|
|
||
| return $response->setStatusCode(204); | ||
| }); |
There was a problem hiding this comment.
This is definitely a skills test honey pot.
| <?php | ||
|
|
||
| namespace Tests\Unit; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class TaskTest extends TestCase | ||
| { | ||
| /** | ||
| * A basic unit test example. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function testExample() | ||
| { | ||
| $this->assertTrue(true); | ||
| } | ||
| } |
Packigifying the TaskFighter App