Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions .env.example

This file was deleted.

File renamed without changes.
58 changes: 58 additions & 0 deletions app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Http\Controllers;

use App\Models\Task;
use App\Jobs\StartTaskJob;
use App\Notifications\TaskStatusChanged;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class TaskController extends Controller
{

public function index()
{

$tasks = Cache::remember('tasks', 60, function () {
return Task::with('user')->get();
});

return response()->json($tasks);
}


public function store(Request $request)
{
$task = Task::create($request->all());

$startTime = $request->input('start_time');

if ($startTime) {
StartTaskJob::dispatch($task)->delay($startTime);
}
Cache::forget('tasks');

return response()->json($task, 201);
}


public function update(Request $request, Task $task)
{
$task->update($request->all());
$task->notify(new TaskStatusChanged($task));

Cache::forget('tasks');

return response()->json($task);
}

// Görev silme
public function destroy(Task $task)
{
$task->delete();
Cache::forget('tasks');

return response()->json(null, 204);
}
}
27 changes: 27 additions & 0 deletions app/Jobs/StartTaskJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace App\Jobs;

use App\Task;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class StartTaskJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

protected $task;

public function __construct(Task $task)
{
$this->task = $task;
}

public function handle()
{
// Görevi başlatıyoruz
$this->task->update(['status' => 'in_progress']);
}
}
13 changes: 13 additions & 0 deletions app/Models/Task.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\User;
class Task extends Model
{

public function user()
{
return $this->belongsTo(User::class);
}
}
31 changes: 31 additions & 0 deletions app/Notifications/TaskStatusChanged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class TaskStatusChanged extends Notification implements ShouldQueue
{
use Queueable;

protected $task;

public function __construct($task)
{
$this->task = $task;
}

public function via($notifiable)
{
return ['database']; // Veritabanı üzerinden bildirim gönderiyoruz
}

public function toDatabase($notifiable)
{
return [
'message' => 'Task "' . $this->task->title . '" is now ' . $this->task->status,
];
}
}
5 changes: 5 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Models\Task;

class User extends Authenticatable implements JWTSubject, Uploader
{
Expand Down Expand Up @@ -65,4 +66,8 @@ public function getUploadAttributes() : array
{
return $this->uploadAttributes;
}
public function tasks()
{
return $this->hasMany(Task::class); // Kullanıcının görevleri
}
}
Loading