Skip to content

Commit

Permalink
feat: delete on tables
Browse files Browse the repository at this point in the history
  • Loading branch information
crisfel committed Jan 30, 2023
1 parent aa8350f commit 960fa8e
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 82 deletions.
12 changes: 6 additions & 6 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mail.pcpplasticos.co
MAIL_PORT=2525
MAIL_USERNAME=no-[email protected]
MAIL_PASSWORD='V]b+(,d&&?cY'
MAIL_HOST=mail.portoamericas.com
MAIL_PORT=465
MAIL_USERNAME=no-[email protected]
MAIL_PASSWORD=A;~N7W4;#Rk{
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=no-[email protected]
MAIL_FROM_NAME="${APP_NAME}"
MAIL_FROM_ADDRESS=no-[email protected]
MAIL_FROM_NAME=Portoamericas

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class AdminrecepsDeleteController extends Controller
{
public function delete(Request $request)
{
User::destroy($request->id);
$user = User::find($request->input('id'));
$user->is_deleted = 1;
$user->save();

return redirect()->back();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AdminrecepsIndexController extends Controller
{
public function index()
{
$users = User::all();
$users = User::where('is_deleted', 0)->get();
return view('adminreceps.index', compact('users'));
}
}
4 changes: 3 additions & 1 deletion app/Http/Controllers/Residents/ResidentsIndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
class ResidentsIndexController extends Controller
{
public function index(){
$users = User::all();
$users = User::where([['role', 'Resident'],
['is_deleted',0]])->get();

return view('residents.index', compact('users'));
}
}
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ class Kernel extends HttpKernel
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'isUserDeleted' => \App\Http\Middleware\IsUserDeletedMiddleware::class
];
}
27 changes: 27 additions & 0 deletions app/Http/Middleware/IsUserDeletedMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class IsUserDeletedMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if (Auth::user()->is_deleted == 1) {
Auth::logout();
return redirect('/');
}

return $next($request);
}
}
2 changes: 1 addition & 1 deletion app/UseCases/Bookings/IndexBookingsUseCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class IndexBookingsUseCase implements IndexBookingsUseCaseInterface
{
public function handle(): array|\Illuminate\Database\Eloquent\Collection
{
$services = Service::all();
$services = Service::where('is_deleted',0)->get();
return $services;
}

Expand Down
10 changes: 9 additions & 1 deletion app/UseCases/Residents/DeleteResidentsUseCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace App\UseCases\Residents;


use App\Models\Booking;
use App\Models\User;
use App\UseCases\Contracts\Residents\DeleteResidentsUseCaseInterface;
use Illuminate\Http\Request;
Expand All @@ -13,6 +14,13 @@ class DeleteResidentsUseCase implements DeleteResidentsUseCaseInterface
{
public function handle(Request $request):void
{
User::destroy($request->input('id'));
$user = User::find($request->input('id'));
$user->is_deleted = 1;
$bookings = Booking::where('user_id', $user->id)->get();
foreach ($bookings as $booking) {
$booking->state = 'Perdida';
$booking->save();
}
$user->save();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddIsDeletedToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->boolean('is_deleted')->default(0);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
}
2 changes: 1 addition & 1 deletion resources/views/bookings/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<div class="justify-content-center" >
@if(Auth::user()->resident->status == 'Deshabilitado')
<div class="col-auto mt-2">
<h3 style="color:#ff0000">
<h3 style="color:#ff0000;" class="text-center">
Estimado residente usted no puede hacer uso de los servicios de clubhouse
</h3>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/bookings/detailBooking.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</div>

<script>
setTimeout("location.reload()", 30000);
function getState(id)
{
Expand Down
143 changes: 73 additions & 70 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,87 +23,90 @@
});

Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('superadmins/login', [App\Http\Controllers\Superadmins\SuperadminsLoginController::class, 'showLoginForm']);
Route::post('superadmins/login', [App\Http\Controllers\Superadmins\SuperadminsLoginController::class, 'login']);
Route::get('superadmins/area', [App\Http\Controllers\Superadmins\SuperadminsLoginController::class, 'secret']);
Route::get('/adminrecep/create', [App\Http\Controllers\Adminreceps\AdminrecepsCreateController::class, 'create'])->middleware('auth');
Route::post('/adminrecep/store', App\Http\Controllers\Adminreceps\AdminrecepsStoreController::class)->middleware('auth');
Route::get('/adminrecep', [App\Http\Controllers\Adminreceps\AdminrecepsIndexController::class, 'index'])->middleware('auth');
Route::get('/adminrecep/edit/{id}', [App\Http\Controllers\Adminreceps\AdminrecepsEditController::class, 'edit'])->middleware('auth');
Route::post('/adminrecep/update', [App\Http\Controllers\Adminreceps\AdminrecepsUpdateController::class, 'update'])->middleware('auth');
Route::post('/adminrecep/delete', [App\Http\Controllers\Adminreceps\AdminrecepsDeleteController::class, 'delete'])->middleware('auth');
Route::get('/role/create', [App\Http\Controllers\Roles\RolesCreateController::class, 'create'])->middleware('auth');
Route::post('/role/store', [App\Http\Controllers\Roles\RolesStoreController::class, 'store'])->middleware('auth');
Route::post('/role/edit', [App\Http\Controllers\Roles\RolesStoreController::class, 'store'])->middleware('auth');
Route::post('/rol/delete', [App\Http\Controllers\Roles\RolesStoreController::class, 'store'])->middleware('auth');
Route::get('/role', [App\Http\Controllers\Roles\RolesIndexController::class, 'index'])->middleware('auth');
/* PERMISSIONS */
Route::get('/permission/create', [App\Http\Controllers\Permissions\PermissionsCreateController::class, 'create'])->middleware('auth');
Route::post('/permission/store', [App\Http\Controllers\Permissions\PermissionsStoreController::class, 'store'])->middleware('auth');

/* Setting */
Route::get('/setting/create', [App\Http\Controllers\Settings\SettingsCreateController::class, 'create'])->middleware('auth');
Route::post('/setting/store', [App\Http\Controllers\Settings\SettingsStoreController::class, 'store'])->middleware('auth');
Route::get('/setting', [App\Http\Controllers\Settings\SettingsIndexController::class, 'index'])->middleware('auth');
Route::post('/setting/edit', [App\Http\Controllers\Settings\SettingsEditController::class, 'edit'])->middleware('auth');
Route::post('/setting/update', [App\Http\Controllers\Settings\SettingsUpdateController::class, 'update'])->middleware('auth');
Route::post('/setting/delete', [App\Http\Controllers\Settings\SettingsDeleteController::class, 'delete'])->middleware('auth');

/* Residents */
Route::get('/residents/create', [App\Http\Controllers\Residents\ResidentsCreateController::class, 'create'])->middleware('auth');
Route::post('/residents/store', [App\Http\Controllers\Residents\ResidentsStoreController::class, 'store'])->middleware('auth');
Route::get('/residents', [App\Http\Controllers\Residents\ResidentsIndexController::class, 'index'])->middleware('auth');
Route::post('/changeStatusResident', [App\Http\Controllers\Residents\ResidentsChangeStatusController::class, 'changeStatus'])->middleware('auth');
Route::get('/residents/edit/{id}', [App\Http\Controllers\Residents\ResidentsEditController::class, 'edit'])->middleware('auth');
Route::post('/residents/update', [App\Http\Controllers\Residents\ResidentsUpdateController::class, 'update'])->middleware('auth');
Route::post('/residents/delete', [App\Http\Controllers\Residents\ResidentsDeleteController::class, 'delete'])->middleware('auth');

/* Services */
Route::get('/services/create', [App\Http\Controllers\Services\ServicesCreateController::class, 'create'])->middleware('auth');
Route::post('/services/store', [App\Http\Controllers\Services\ServicesStoreController::class, 'store'])->middleware('auth');
Route::get('/services', [App\Http\Controllers\Services\ServicesIndexController::class, 'index'])->middleware('auth');
Route::post('/services/edit', [App\Http\Controllers\Services\ServicesEditController::class, 'edit'])->middleware('auth');
Route::post('/services/update', [App\Http\Controllers\Services\ServicesUpdateController::class, 'update'])->middleware('auth');
Route::post('/services/delete', [App\Http\Controllers\Services\ServicesDeleteController::class, 'delete'])->middleware('auth');

/* Booking */
Route::get('/bookings/create', [App\Http\Controllers\Bookings\BookingsCreateController::class, 'create'])->middleware('auth');
Route::post('/bookings/schedule', [App\Http\Controllers\Bookings\BookingsScheduleController::class, 'schedule'])->middleware('auth');
Route::post('/bookings/store', [App\Http\Controllers\Bookings\BookingsStoreController::class, 'store'])->middleware('auth');
Route::get('/bookings', [App\Http\Controllers\Bookings\BookingsIndexController::class, 'index'])->middleware('auth');
Route::get('/detailBooking/{service}', [App\Http\Controllers\Bookings\BookingsDetailBookingController::class, 'detailBooking'])->middleware('auth');
Route::post('/booking/cancel', [App\Http\Controllers\Bookings\BookingsCancelController::class, 'cancel'])->middleware('auth');
Route::post('/bookings/changeState', [App\Http\Controllers\Bookings\BookingsChangeStateController::class, 'changeState'])->middleware('auth');
Route::get('/bookings/changeState', [App\Http\Controllers\Bookings\BookingsChangeStateController::class, 'changeState'])->middleware('auth');
Route::group(['middleware' => ['auth', 'isUserDeleted']], static function() {
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('superadmins/login', [App\Http\Controllers\Superadmins\SuperadminsLoginController::class, 'showLoginForm']);
Route::post('superadmins/login', [App\Http\Controllers\Superadmins\SuperadminsLoginController::class, 'login']);
Route::get('superadmins/area', [App\Http\Controllers\Superadmins\SuperadminsLoginController::class, 'secret']);
Route::get('/adminrecep/create', [App\Http\Controllers\Adminreceps\AdminrecepsCreateController::class, 'create']);
Route::post('/adminrecep/store', App\Http\Controllers\Adminreceps\AdminrecepsStoreController::class);
Route::get('/adminrecep', [App\Http\Controllers\Adminreceps\AdminrecepsIndexController::class, 'index']);
Route::get('/adminrecep/edit/{id}', [App\Http\Controllers\Adminreceps\AdminrecepsEditController::class, 'edit']);
Route::post('/adminrecep/update', [App\Http\Controllers\Adminreceps\AdminrecepsUpdateController::class, 'update']);
Route::post('/adminrecep/delete', [App\Http\Controllers\Adminreceps\AdminrecepsDeleteController::class, 'delete']);
Route::get('/role/create', [App\Http\Controllers\Roles\RolesCreateController::class, 'create']);
Route::post('/role/store', [App\Http\Controllers\Roles\RolesStoreController::class, 'store']);
Route::post('/role/edit', [App\Http\Controllers\Roles\RolesStoreController::class, 'store']);
Route::post('/rol/delete', [App\Http\Controllers\Roles\RolesStoreController::class, 'store']);
Route::get('/role', [App\Http\Controllers\Roles\RolesIndexController::class, 'index']);
/* PERMISSIONS */
Route::get('/permission/create', [App\Http\Controllers\Permissions\PermissionsCreateController::class, 'create']);
Route::post('/permission/store', [App\Http\Controllers\Permissions\PermissionsStoreController::class, 'store']);

/* Setting */
Route::get('/setting/create', [App\Http\Controllers\Settings\SettingsCreateController::class, 'create']);
Route::post('/setting/store', [App\Http\Controllers\Settings\SettingsStoreController::class, 'store']);
Route::get('/setting', [App\Http\Controllers\Settings\SettingsIndexController::class, 'index']);
Route::post('/setting/edit', [App\Http\Controllers\Settings\SettingsEditController::class, 'edit']);
Route::post('/setting/update', [App\Http\Controllers\Settings\SettingsUpdateController::class, 'update']);
Route::post('/setting/delete', [App\Http\Controllers\Settings\SettingsDeleteController::class, 'delete']);

/* Residents */
Route::get('/residents/create', [App\Http\Controllers\Residents\ResidentsCreateController::class, 'create']);
Route::post('/residents/store', [App\Http\Controllers\Residents\ResidentsStoreController::class, 'store']);
Route::get('/residents', [App\Http\Controllers\Residents\ResidentsIndexController::class, 'index']);
Route::post('/changeStatusResident', [App\Http\Controllers\Residents\ResidentsChangeStatusController::class, 'changeStatus']);
Route::get('/residents/edit/{id}', [App\Http\Controllers\Residents\ResidentsEditController::class, 'edit']);
Route::post('/residents/update', [App\Http\Controllers\Residents\ResidentsUpdateController::class, 'update']);
Route::post('/residents/delete', [App\Http\Controllers\Residents\ResidentsDeleteController::class, 'delete']);

/* Services */
Route::get('/services/create', [App\Http\Controllers\Services\ServicesCreateController::class, 'create']);
Route::post('/services/store', [App\Http\Controllers\Services\ServicesStoreController::class, 'store']);
Route::get('/services', [App\Http\Controllers\Services\ServicesIndexController::class, 'index']);
Route::post('/services/edit', [App\Http\Controllers\Services\ServicesEditController::class, 'edit']);
Route::post('/services/update', [App\Http\Controllers\Services\ServicesUpdateController::class, 'update']);
Route::post('/services/delete', [App\Http\Controllers\Services\ServicesDeleteController::class, 'delete']);

/* Booking */
Route::get('/bookings/create', [App\Http\Controllers\Bookings\BookingsCreateController::class, 'create']);
Route::post('/bookings/schedule', [App\Http\Controllers\Bookings\BookingsScheduleController::class, 'schedule']);
Route::post('/bookings/store', [App\Http\Controllers\Bookings\BookingsStoreController::class, 'store']);
Route::get('/bookings', [App\Http\Controllers\Bookings\BookingsIndexController::class, 'index']);
Route::get('/detailBooking/{service}', [App\Http\Controllers\Bookings\BookingsDetailBookingController::class, 'detailBooking']);
Route::post('/booking/cancel', [App\Http\Controllers\Bookings\BookingsCancelController::class, 'cancel']);
Route::post('/bookings/changeState', [App\Http\Controllers\Bookings\BookingsChangeStateController::class, 'changeState']);
Route::get('/bookings/changeState', [App\Http\Controllers\Bookings\BookingsChangeStateController::class, 'changeState']);

// Extra information
Route::get('/preinformation', [App\Http\Controllers\Extrainfo\PreinfoChangeStateController::class, 'preinfo'])->middleware('auth');
Route::post('/extrainfo/create', [App\Http\Controllers\Extrainfo\ExtrainfoCreateController::class, 'create'])->middleware('auth');
Route::post('/extrainfo/store', [App\Http\Controllers\Extrainfo\ExtrainfoStoreController::class, 'store'])->middleware('auth');
Route::get('/extrainfo/index/{id}', [App\Http\Controllers\Extrainfo\ExtrainfoIndexController::class, 'index'])->middleware('auth');
Route::get('/preinformation', [App\Http\Controllers\Extrainfo\PreinfoChangeStateController::class, 'preinfo']);
Route::post('/extrainfo/create', [App\Http\Controllers\Extrainfo\ExtrainfoCreateController::class, 'create']);
Route::post('/extrainfo/store', [App\Http\Controllers\Extrainfo\ExtrainfoStoreController::class, 'store']);
Route::get('/extrainfo/index/{id}', [App\Http\Controllers\Extrainfo\ExtrainfoIndexController::class, 'index']);

//Habitants
Route::get('/habitants/create/{id}', [App\Http\Controllers\Habitants\HabitantsCreateController::class, 'create'])->middleware('auth');
Route::post('/habitants/store', [App\Http\Controllers\Habitants\HabitantsStoreController::class, 'store'])->middleware('auth');
Route::get('/habitants/delete/{id}', [App\Http\Controllers\Habitants\HabitantsDeleteController::class, 'delete'])->middleware('auth');
Route::get('/habitants/create/{id}', [App\Http\Controllers\Habitants\HabitantsCreateController::class, 'create']);
Route::post('/habitants/store', [App\Http\Controllers\Habitants\HabitantsStoreController::class, 'store']);
Route::get('/habitants/delete/{id}', [App\Http\Controllers\Habitants\HabitantsDeleteController::class, 'delete']);

//Transports
Route::get('/transports/create/{id}', [App\Http\Controllers\Transports\TransportsCreateController::class, 'create'])->middleware('auth');
Route::post('/transports/store', [App\Http\Controllers\Transports\TransportsStoreController::class, 'store'])->middleware('auth');
Route::get('/transports/delete/{id}', [App\Http\Controllers\Transports\TransportsDeleteController::class, 'delete'])->middleware('auth');
Route::get('/transports/create/{id}', [App\Http\Controllers\Transports\TransportsCreateController::class, 'create']);
Route::post('/transports/store', [App\Http\Controllers\Transports\TransportsStoreController::class, 'store']);
Route::get('/transports/delete/{id}', [App\Http\Controllers\Transports\TransportsDeleteController::class, 'delete']);

//Pets
Route::get('/pets/create/{id}', [App\Http\Controllers\Pets\PetsCreateController::class, 'create'])->middleware('auth');
Route::post('/pets/store', [App\Http\Controllers\Pets\PetsStoreController::class, 'store'])->middleware('auth');
Route::get('/pets/delete/{id}', [App\Http\Controllers\Pets\PetsDeleteController::class, 'delete'])->middleware('auth');
Route::get('/pets/create/{id}', [App\Http\Controllers\Pets\PetsCreateController::class, 'create']);
Route::post('/pets/store', [App\Http\Controllers\Pets\PetsStoreController::class, 'store']);
Route::get('/pets/delete/{id}', [App\Http\Controllers\Pets\PetsDeleteController::class, 'delete']);

//Receptionists
Route::get('/receptionists/create', [App\Http\Controllers\Receptionists\ReceptionistsCreateController::class, 'create'])->middleware('auth');
Route::get('/receptionists/create', [App\Http\Controllers\Receptionists\ReceptionistsCreateController::class, 'create']);

//CHANGE PASSWORD
Route::get('/user/passwordEdit/{id}', [App\Http\Controllers\User\UserPasswordEditController::class, 'passwordEdit'])->middleware('auth');
Route::post('/changePassword', [App\Http\Controllers\User\UserChangePasswordController::class, 'changePassword'])->middleware('auth');
Route::get('/user/passwordEdit/{id}', [App\Http\Controllers\User\UserPasswordEditController::class, 'passwordEdit']);
Route::post('/changePassword', [App\Http\Controllers\User\UserChangePasswordController::class, 'changePassword']);

//update booking states
Route::get('/updateBookingStates', [App\Http\Controllers\Bookings\BookingsUpdateStatesController::class, 'updateStates'])->middleware('auth');
Route::get('/updateBookingStates', [App\Http\Controllers\Bookings\BookingsUpdateStatesController::class, 'updateStates']);

});
Loading

0 comments on commit 960fa8e

Please sign in to comment.