-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: e-coffee with employees (#530)
- Loading branch information
Showing
56 changed files
with
2,288 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Company\Company; | ||
use Illuminate\Console\Command; | ||
use App\Jobs\CreateNewECoffeeSession; | ||
|
||
class GenerateNewECoffeeSession extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'ecoffee:start'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Generate new eCoffee sessions for all companies in the instance'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): void | ||
{ | ||
Company::chunk(100, function ($companies) { | ||
$companies->each(function (Company $company) { | ||
CreateNewECoffeeSession::dispatch($company)->onQueue('low'); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/Http/Controllers/Company/Adminland/AdminECoffeeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Company\Adminland; | ||
|
||
use Inertia\Inertia; | ||
use Inertia\Response; | ||
use Illuminate\Http\Request; | ||
use App\Helpers\InstanceHelper; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Helpers\NotificationHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\ViewHelpers\Adminland\AdminECoffeeViewHelper; | ||
use App\Services\Company\Adminland\ECoffee\ToggleECoffeeProcess; | ||
|
||
class AdminECoffeeController extends Controller | ||
{ | ||
/** | ||
* Show the eCoffee page. | ||
* | ||
* @return Response | ||
*/ | ||
public function index(): Response | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
|
||
$eCoffeeDetails = AdminECoffeeViewHelper::eCoffee($company); | ||
|
||
return Inertia::render('Adminland/ECoffee/Index', [ | ||
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()), | ||
'ecoffee' => $eCoffeeDetails, | ||
]); | ||
} | ||
|
||
/** | ||
* Toggle the eCoffee session in the company. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @return JsonResponse | ||
*/ | ||
public function store(Request $request, int $companyId): JsonResponse | ||
{ | ||
$loggedEmployee = InstanceHelper::getLoggedEmployee(); | ||
$company = InstanceHelper::getLoggedCompany(); | ||
|
||
$data = [ | ||
'company_id' => $company->id, | ||
'author_id' => $loggedEmployee->id, | ||
]; | ||
|
||
$company = (new ToggleECoffeeProcess)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => [ | ||
'enabled' => $company->e_coffee_enabled, | ||
], | ||
], 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/Http/Controllers/Company/Dashboard/DashboardMeECoffeeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Company\Dashboard; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use App\Helpers\InstanceHelper; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Http\Controllers\Controller; | ||
use App\Services\Company\Employee\ECoffee\MarkECoffeeSessionAsHappened; | ||
|
||
class DashboardMeECoffeeController extends Controller | ||
{ | ||
/** | ||
* Mark an e-coffee match as happened. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @param int $eCoffeeId | ||
* @param int $eCoffeeMatchId | ||
* @return JsonResponse | ||
*/ | ||
public function store(Request $request, int $companyId, int $eCoffeeId, int $eCoffeeMatchId): JsonResponse | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
$employee = InstanceHelper::getLoggedEmployee(); | ||
|
||
$data = [ | ||
'company_id' => $company->id, | ||
'author_id' => $employee->id, | ||
'e_coffee_id' => $eCoffeeId, | ||
'e_coffee_match_id' => $eCoffeeMatchId, | ||
]; | ||
|
||
(new MarkECoffeeSessionAsHappened)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => true, | ||
], 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/Http/Controllers/Company/Employee/EmployeeECoffeeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Company\Employee; | ||
|
||
use Inertia\Inertia; | ||
use Illuminate\Http\Request; | ||
use App\Helpers\InstanceHelper; | ||
use App\Models\Company\Employee; | ||
use App\Helpers\NotificationHelper; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use App\Http\ViewHelpers\Employee\EmployeeECoffeeViewHelper; | ||
|
||
class EmployeeECoffeeController extends Controller | ||
{ | ||
/** | ||
* Show the list of current and past eCoffee sessions. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @param int $employeeId | ||
* @return mixed | ||
*/ | ||
public function index(Request $request, int $companyId, int $employeeId) | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
|
||
try { | ||
$employee = Employee::where('company_id', $companyId) | ||
->where('id', $employeeId) | ||
->firstOrFail(); | ||
} catch (ModelNotFoundException $e) { | ||
return redirect('home'); | ||
} | ||
|
||
// information about the eCoffee sessions | ||
$eCoffees = EmployeeECoffeeViewHelper::index($employee, $company); | ||
|
||
return Inertia::render('Employee/ECoffee/Index', [ | ||
'employee' => [ | ||
'id' => $employeeId, | ||
'name' => $employee->name, | ||
], | ||
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()), | ||
'eCoffees' => $eCoffees, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\ViewHelpers\Adminland; | ||
|
||
use App\Models\Company\Company; | ||
use Illuminate\Support\Collection; | ||
|
||
class AdminECoffeeViewHelper | ||
{ | ||
/** | ||
* Collection containing all the information about the expense categories | ||
* used in the company. | ||
* | ||
* @param Company $company | ||
* @return array|null | ||
*/ | ||
public static function eCoffee(Company $company): ?array | ||
{ | ||
return [ | ||
'enabled' => $company->e_coffee_enabled, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.