From be4701cce0f09dae9d77228f6848c1e735e94730 Mon Sep 17 00:00:00 2001 From: Matteo Gheza Date: Thu, 23 Feb 2023 17:34:32 +0100 Subject: [PATCH] Working list/availability implementation --- .../Controllers/AvailabilityController.php | 43 ++++++++++++++ .../app/Http/Controllers/UserController.php | 57 +++++++++++++++++++ backend/app/Models/User.php | 2 + .../2023_02_20_230902_update_users_table.php | 2 + backend/routes/api.php | 9 ++- .../_components/table/table.component.html | 4 +- .../src/app/_routes/list/list.component.html | 2 +- .../src/app/_routes/list/list.component.ts | 10 +--- 8 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 backend/app/Http/Controllers/AvailabilityController.php create mode 100644 backend/app/Http/Controllers/UserController.php diff --git a/backend/app/Http/Controllers/AvailabilityController.php b/backend/app/Http/Controllers/AvailabilityController.php new file mode 100644 index 0000000..d6d12a2 --- /dev/null +++ b/backend/app/Http/Controllers/AvailabilityController.php @@ -0,0 +1,43 @@ + $request->user()->available, + "manual_mode" => $request->user()->availability_manual_mode + ]; + } + + public function updateAvailability(Request $request) + { + if($request->input("id")) { + $user = User::find($request->input("id")); + } else { + $user = $request->user(); + } + + $user->available = $request->input("available", false); + $user->save(); + + return [ + "updated_user_id" => $user->id, + "updated_user_name" => $user->name + ]; + } + + public function updateAvailabilityManualMode(Request $request) + { + $user = $request->user(); + $user->availability_manual_mode = $request->input("manual_mode", false); + $user->save(); + + return; + } +} diff --git a/backend/app/Http/Controllers/UserController.php b/backend/app/Http/Controllers/UserController.php new file mode 100644 index 0000000..6be69f8 --- /dev/null +++ b/backend/app/Http/Controllers/UserController.php @@ -0,0 +1,57 @@ +orderBy('available', 'desc') + ->orderBy('chief', 'desc') + ->orderBy('services', 'asc') + ->orderBy('trainings', 'desc') + ->orderBy('availability_minutes', 'asc') + ->orderBy('name', 'asc') + ->get(); + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + // + } + + /** + * Display the specified resource. + */ + public function show(User $user) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, User $user) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(User $user) + { + // + } +} diff --git a/backend/app/Models/User.php b/backend/app/Models/User.php index 1eb1bb2..e70516b 100644 --- a/backend/app/Models/User.php +++ b/backend/app/Models/User.php @@ -23,6 +23,8 @@ class User extends Authenticatable 'email', 'phone_number', 'available', + 'availability_manual_mode', + 'availability_minutes', 'chief', 'driver', 'services', diff --git a/backend/database/migrations/2023_02_20_230902_update_users_table.php b/backend/database/migrations/2023_02_20_230902_update_users_table.php index d4dd989..879f01c 100644 --- a/backend/database/migrations/2023_02_20_230902_update_users_table.php +++ b/backend/database/migrations/2023_02_20_230902_update_users_table.php @@ -15,6 +15,8 @@ return new class extends Migration $table->string('username')->unique(); $table->string('phone_number')->nullable(); //https://github.com/googlei18n/libphonenumber/blob/master/FALSEHOODS.md $table->boolean('available')->default(false); + $table->boolean('availability_manual_mode')->default(false); + $table->int('availability_minutes')->default(0); $table->boolean('chief')->default(false); $table->boolean('driver')->default(false); $table->integer('services')->default(0); diff --git a/backend/routes/api.php b/backend/routes/api.php index d9e0401..596913f 100644 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -1,8 +1,9 @@ group( function () { Route::get('/me', [AuthController::class, 'me']); Route::post('/me', [AuthController::class, 'me']); + Route::get('/list', [UserController::class, 'index']); + + Route::get('/availability', [AvailabilityController::class, 'get']); + Route::post('/availability', [AvailabilityController::class, 'updateAvailability']); + Route::post('/manual_mode', [AvailabilityController::class, 'updateAvailabilityManualMode']); + Route::post('/logout', [AuthController::class, 'logout']); }); diff --git a/frontend/src/app/_components/table/table.component.html b/frontend/src/app/_components/table/table.component.html index c54f322..706890f 100644 --- a/frontend/src/app/_components/table/table.component.html +++ b/frontend/src/app/_components/table/table.component.html @@ -18,8 +18,8 @@ red helmet red helmet - {{ row.name }} - {{ row.name }} + {{ row.name }} + {{ row.name }} diff --git a/frontend/src/app/_routes/list/list.component.html b/frontend/src/app/_routes/list/list.component.html index 50c8cd1..a01025d 100644 --- a/frontend/src/app/_routes/list/list.component.html +++ b/frontend/src/app/_routes/list/list.component.html @@ -28,7 +28,7 @@ - +
\ No newline at end of file diff --git a/frontend/src/app/_routes/list/list.component.ts b/frontend/src/app/_routes/list/list.component.ts index 3467f42..2d2e75e 100644 --- a/frontend/src/app/_routes/list/list.component.ts +++ b/frontend/src/app/_routes/list/list.component.ts @@ -117,18 +117,12 @@ export class ListComponent implements OnInit, OnDestroy { } ngOnInit(): void { - /* this.loadAvailabilityInterval = setInterval(() => { - console.log("Refreshing availability..."); this.loadAvailability(); - }, 10000); + }, 30000); this.auth.authChanged.subscribe({ - next: () => { - this.loadAvailability(); - this.loadAvailability(); - } + next: () => this.loadAvailability() }); - */ } ngOnDestroy(): void {