Initial Laravel API import
Some checks failed
continuous-integration/drone/push Build is failing

- Complete GGZ Ecademy Laravel backend application
- RESTful API for learning products, members, filters
- Authentication and authorization system
- Database migrations and seeders
- Custom CRUD generator commands
- Email notification system
- Integration with frontend applications
This commit is contained in:
Joris Slagter
2025-12-02 17:40:21 +01:00
parent 786b6b6a78
commit df155bb13d
341 changed files with 116385 additions and 2 deletions

View File

@@ -0,0 +1,127 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Artisan;
class CrudGenerator extends Command
{
protected $signature = 'crud:generator
{name : Class (singular) for example User}';
protected $description = 'Create CRUD operations';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$name = $this->argument('name');
$this->controller($name);
$this->model($name);
$this->service($name);
$this->migration($name);
// $this->validator($name);
//$this->request($name);
File::append(base_path('routes/api.php'), 'Route::resource(\'' . Str::plural(strtolower($name)) . "', '{$name}Controller');");
}
protected function controller($name)
{
$controllerTemplate = str_replace(
[
'{{modelName}}',
'{{modelNamePluralLowerCase}}',
'{{modelNameSingularLowerCase}}'
],
[
$name,
strtolower(Str::plural($name)),
strtolower($name)
],
$this->getStub('Controller')
);
file_put_contents(app_path("/Http/Controllers/{$name}Controller.php"), $controllerTemplate);
}
protected function model($name)
{
$modelTemplate = str_replace(
['{{modelName}}'],
[$name],
$this->getStub('Model')
);
if (!file_exists($path = app_path('/Repositories')))
mkdir($path, 0777, true);
file_put_contents(app_path("/Repositories/{$name}.php"), $modelTemplate);
}
protected function request($name)
{
$requestTemplate = str_replace(
['{{modelName}}'],
[$name],
$this->getStub('Request')
);
if (!file_exists($path = app_path('/Http/Requests')))
mkdir($path, 0777, true);
file_put_contents(app_path("/Http/Requests/{$name}Request.php"), $requestTemplate);
}
protected function service($name)
{
$modelTemplate = str_replace(
[
'{{modelName}}',
'{{modelNameSingularLowerCase}}'
],
[
$name,
strtolower($name)
],
$this->getStub('Service')
);
if (!file_exists($path = app_path('/Services')))
mkdir($path, 0777, true);
file_put_contents(app_path("/Services/{$name}Service.php"), $modelTemplate);
}
protected function migration($name)
{
$tableName = strtolower(Str::plural($name));
Artisan::call('make:migration', ['name' => "create_{$tableName}_table"]);
}
protected function validator($name)
{
$modelTemplate = str_replace(
['{{modelName}}'],
[$name],
$this->getStub('Validator')
);
if (!file_exists($path = app_path('/Validators')))
mkdir($path, 0777, true);
file_put_contents(app_path("/Validators/{$name}Validator.php"), $modelTemplate);
}
protected function getStub($type)
{
return file_get_contents(base_path("stubs/custom/$type.stub"));
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace App\Console\Commands;
use App\Services\UserService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use App\Mail\CourseNotificationMail;
use App\Services\CourseNotificationService;
class SendProductEmailNotifications extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'send:lp-notifications';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command that checks scheduled learning product notifications, sending emails to users specified.';
private $userService;
private $courseNotificationService;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(
UserService $userService,
CourseNotificationService $courseNotificationService
) {
parent::__construct();
$this->userService = $userService;
$this->courseNotificationService = $courseNotificationService;
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$course_notifications = $this->courseNotificationService->getExpiredToSendWithProducts();
// No notifications? Exit
if ($course_notifications->count() <= 0) return 0;
foreach ($course_notifications as $notification) {
$users = json_decode($notification->users);
$emails = json_decode($notification->emails);
// Send emails to not registered users
if (count($emails) > 0) {
foreach ($emails as $email) {
Mail::to($email)->queue(new CourseNotificationMail($notification));
}
}
// Send emails to specified registered users
foreach ($users as $userId) {
$user = $this->userService->get($userId);
Mail::to($user)->queue(new CourseNotificationMail($notification));
}
// Mark as sent
$notification->sent = true;
$notification->save();
}
return 0;
}
}

41
app/Console/Kernel.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}