Skip to content

Commit

Permalink
Merge pull request #95 from LavaLite/master
Browse files Browse the repository at this point in the history
Update user modules
  • Loading branch information
georgemjohn authored Jul 1, 2023
2 parents 6c55700 + d0a0bed commit ff8cf18
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Litepie\Notification\Database\Seeders;

use Illuminate\Database\Seeder;

class NotificationTableSeeder extends Seeder
{
public function run()
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

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

class CreateNotificationTemplatesTable extends Migration
{
/*
* Run the migrations.
*
* @return void
*/

public function up()
{

/*
* Table: notifications
*/
Schema::create('notification_templates', function ($table) {
$table->id();
$table->string('key', 250)->nullable();
$table->string('language', 3)->default('en')->nullable();
$table->string('subject', 100)->nullable();
$table->text('message')->nullable();
$table->softDeletes();
$table->nullableTimestamps();
});
}

/*
* Reverse the migrations.
*
* @return void
*/

public function down()
{
Schema::drop('notification_templates');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

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

class CreateNotificationsTable extends Migration
{
/*
* Run the migrations.
*
* @return void
*/

public function up()
{

/*
* Table: notifications
*/
Schema::create('notifications', function ($table) {
$table->string('id', 50);
$table->string('type', 250)->nullable();
$table->string('type_sub', 20)->nullable();
$table->integer('notifiable_id')->nullable();
$table->string('notifiable_type', 250)->nullable();
$table->text('data')->nullable();
$table->text('message')->nullable();
$table->text('actions')->nullable();
$table->string('variant', 20)->nullable();
$table->tinyInteger('pinned')->nullable();
$table->dateTime('read_at')->nullable();
$table->softDeletes();
$table->nullableTimestamps();
});
}

/*
* Reverse the migrations.
*
* @return void
*/

public function down()
{
Schema::drop('notifications');
}
}
27 changes: 11 additions & 16 deletions src/Litepie/User/Actions/ClientAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,30 @@
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Litepie\Actions\Concerns\AsAction;
use Litepie\Actions\Traits\LogsActions;
use Litepie\Notification\Traits\SendNotification;
use Litepie\User\Models\Client;


class ClientAction
{
use AsAction;
use LogsActions;
use SendNotification;

private $model;
protected $model;
protected $namespace = 'litepie.user.client';
protected $eventClass = \Litepie\User\Events\ClientAction::class;
protected $action;
protected $function;
protected $request;

public function handle(string $action, Client $client, array $request = [])
{
$this->action = $action;
$this->request = $request;
$this->model = $client;
$this->function = Str::camel($action);
$this->executeAction();
return $this->model;

$function = Str::camel($action);
event('user.client.action.' . $action . 'ing', [$client]);
$data = $this->$function($client, $request);
event('user.client.action.' . $action . 'ed', [$client]);

$this->logsAction();
$this->notify();
return $data;
}


public function store(Client $client, array $request)
{
$attributes = $request;
Expand Down Expand Up @@ -75,5 +71,4 @@ public function copy(Client $client, array $request)
return $client;
}


}
38 changes: 31 additions & 7 deletions src/Litepie/User/Actions/ClientActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,36 @@
namespace Litepie\User\Actions;

use Illuminate\Support\Str;
use Litepie\User\Models\Client;
use Litepie\User\Scopes\ClientResourceScope;
use Litepie\Actions\Concerns\AsAction;
use Litepie\Actions\Traits\LogsActions;
use Litepie\Database\RequestScope;
use Litepie\User\Models\Client;
use Litepie\User\Scopes\ClientResourceScope;

class ClientActions
{
use AsAction;
use LogsActions;

private $model;

protected $model;
protected $namespace = 'litepie.user.client';
protected $eventClass = \Litepie\User\Events\ClientAction::class;
protected $action;
protected $function;
protected $request;

public function handle(string $action, array $request)
{
$this->model = app(Client::class);
$this->action = $action;
$this->request = $request;
$this->function = Str::camel($action);

$function = Str::camel($action);

event('user.client.action.' . $action . 'ing', [$request]);
$this->dispatchActionBeforeEvent();
$data = $this->$function($request);
event('user.client.action.' . $action . 'ed', [$data]);
$this->dispatchActionAfterEvent();

$this->logsAction();
return $data;
Expand Down Expand Up @@ -57,7 +65,8 @@ function empty(array $request) {
return $this->model->forceDelete();
}

function restore(array $request) {
public function restore(array $request)
{
return $this->model->restore();
}

Expand All @@ -69,4 +78,19 @@ public function delete(array $request)
});
return $this->model->whereIn('id', $ids)->delete();
}

public function options(array $request)
{
return $this->model
->pushScope(new RequestScope())
->pushScope(new ClientResourceScope())
->take(30)->get()
->map(function ($row) {
return [
'key' => $row->id,
'value' => $row->id,
'text' => $row->name,
];
})->toArray();
}
}
27 changes: 11 additions & 16 deletions src/Litepie/User/Actions/UserAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,30 @@
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Litepie\Actions\Concerns\AsAction;
use Litepie\Actions\Traits\LogsActions;
use Litepie\Notification\Traits\SendNotification;
use Litepie\User\Models\User;


class UserAction
{
use AsAction;
use LogsActions;
use SendNotification;

private $model;
protected $model;
protected $namespace = 'litepie.user.user';
protected $eventClass = \Litepie\User\Events\UserAction::class;
protected $action;
protected $function;
protected $request;

public function handle(string $action, User $user, array $request = [])
{
$this->action = $action;
$this->request = $request;
$this->model = $user;
$this->function = Str::camel($action);
$this->executeAction();
return $this->model;

$function = Str::camel($action);
event('user.user.action.' . $action . 'ing', [$user]);
$data = $this->$function($user, $request);
event('user.user.action.' . $action . 'ed', [$user]);

$this->logsAction();
$this->notify();
return $data;
}


public function store(User $user, array $request)
{
$attributes = $request;
Expand Down Expand Up @@ -75,5 +71,4 @@ public function copy(User $user, array $request)
return $user;
}


}
38 changes: 31 additions & 7 deletions src/Litepie/User/Actions/UserActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,36 @@
namespace Litepie\User\Actions;

use Illuminate\Support\Str;
use Litepie\User\Models\User;
use Litepie\User\Scopes\UserResourceScope;
use Litepie\Actions\Concerns\AsAction;
use Litepie\Actions\Traits\LogsActions;
use Litepie\Database\RequestScope;
use Litepie\User\Models\User;
use Litepie\User\Scopes\UserResourceScope;

class UserActions
{
use AsAction;
use LogsActions;

private $model;

protected $model;
protected $namespace = 'litepie.user.user';
protected $eventClass = \Litepie\User\Events\UserAction::class;
protected $action;
protected $function;
protected $request;

public function handle(string $action, array $request)
{
$this->model = app(User::class);
$this->action = $action;
$this->request = $request;
$this->function = Str::camel($action);

$function = Str::camel($action);

event('user.user.action.' . $action . 'ing', [$request]);
$this->dispatchActionBeforeEvent();
$data = $this->$function($request);
event('user.user.action.' . $action . 'ed', [$data]);
$this->dispatchActionAfterEvent();

$this->logsAction();
return $data;
Expand Down Expand Up @@ -57,7 +65,8 @@ function empty(array $request) {
return $this->model->forceDelete();
}

function restore(array $request) {
public function restore(array $request)
{
return $this->model->restore();
}

Expand All @@ -69,4 +78,19 @@ public function delete(array $request)
});
return $this->model->whereIn('id', $ids)->delete();
}

public function options(array $request)
{
return $this->model
->pushScope(new RequestScope())
->pushScope(new UserResourceScope())
->take(30)->get()
->map(function ($row) {
return [
'key' => $row->id,
'value' => $row->id,
'text' => $row->name,
];
})->toArray();
}
}
Loading

0 comments on commit ff8cf18

Please sign in to comment.