From 1f9da456a548a948c712811cab7dda14ad2209a7 Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Sun, 21 Oct 2018 11:57:23 -0300 Subject: [PATCH] Bug Fixed: avoiding item waiting_user across take/return It happend once: a user asked to be added to the waiting list at the same time other user was returning the item. So the user ended up waiting for the user he was already using. --- app/Http/Controllers/AlertController.php | 7 +++++++ app/Http/Controllers/TakeController.php | 1 + resources/lang/pt-br.json | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/AlertController.php b/app/Http/Controllers/AlertController.php index 43cbd27..dd24300 100644 --- a/app/Http/Controllers/AlertController.php +++ b/app/Http/Controllers/AlertController.php @@ -22,6 +22,13 @@ class AlertController extends Controller public function store(Request $request) { $item = User::loggedIn()->items()->find(request('item')); + if (!$item->used_by) { + session()->flash( + FlashMessage::PRIMARY, + __('Oh! This item has just being returned. Take it before anyone else!') + ); + return redirect('home'); + } $item->waiting_user_id = Auth::id(); $item->timestamps = false; $item->save(); diff --git a/app/Http/Controllers/TakeController.php b/app/Http/Controllers/TakeController.php index 4c2060a..3206a2a 100644 --- a/app/Http/Controllers/TakeController.php +++ b/app/Http/Controllers/TakeController.php @@ -30,6 +30,7 @@ class TakeController extends Controller ); } $item->used_by = Auth::id(); + $item->waiting_user_id = null; $item->save(); return redirect('home'); } diff --git a/resources/lang/pt-br.json b/resources/lang/pt-br.json index 06d69f3..b509c13 100644 --- a/resources/lang/pt-br.json +++ b/resources/lang/pt-br.json @@ -46,5 +46,6 @@ "The item doesn't exist.": "O item não existe.", "The product doesn't exist or doesn't belongs to you.": "O produto não existe ou não é seu.", - "This item is already taken": "Esse item já está sendo usado" + "This item is already taken": "Esse item já está sendo usado", + "Oh! This item has just being returned. Take it before anyone else!": "Opa! Esse item acabou de ser devolvido. Aproveite!" } \ No newline at end of file