DONE: investment types crud for admin; remove logger when login
This commit is contained in:
committed by
ISMAIL MASSERAN
parent
92bfc501fa
commit
1cf08e4ae0
@@ -19,8 +19,6 @@ class ActivityLogController extends Controller
|
||||
{
|
||||
$this->authorize('viewAny', Activity::class);
|
||||
|
||||
// ActivityLogger::logView(new Activity, 'Viewed activity logs');
|
||||
|
||||
$perPage = $request->get('per_page', 10);
|
||||
$perPage = min($perPage, 1000); // Limit max per page to 100
|
||||
$search = trim((string) $request->get('search', ''));
|
||||
|
||||
@@ -11,6 +11,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Activitylog\Facades\Activity;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
use Spatie\Permission\Contracts\Permission;
|
||||
@@ -105,6 +106,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
|
||||
public function ensurePublicProfileToken(): string
|
||||
{
|
||||
return Activity::withoutLogs(function () {
|
||||
$expiryDays = self::publicProfileTokenTtlDays();
|
||||
|
||||
if (blank($this->public_profile_token) || $this->isPublicProfileTokenExpired()) {
|
||||
@@ -121,6 +123,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
])->save();
|
||||
|
||||
return $this->public_profile_token;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,6 +192,12 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
return LogOptions::defaults()
|
||||
->logAll()
|
||||
->logExcept([
|
||||
'public_profile_token',
|
||||
'public_profile_token_expires_at',
|
||||
'remember_token',
|
||||
'updated_at',
|
||||
])
|
||||
->logOnlyDirty()
|
||||
->dontSubmitEmptyLogs()
|
||||
->setDescriptionForEvent(fn (string $eventName) => "User {$this->name} was {$eventName}");
|
||||
|
||||
@@ -7,11 +7,13 @@ use App\Support\AuthCookie;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Auth\Entities\User;
|
||||
use Modules\Auth\Transformers\UserResource;
|
||||
use Spatie\Activitylog\Facades\Activity;
|
||||
|
||||
class AuthSessionService
|
||||
{
|
||||
public function createAuthResponse(User $user, string $message, int $status = 200): JsonResponse
|
||||
{
|
||||
return Activity::withoutLogs(function () use ($user, $message, $status) {
|
||||
$user->ensurePublicProfileToken();
|
||||
|
||||
if (config('app.env') !== 'local') {
|
||||
@@ -47,5 +49,6 @@ class AuthSessionService
|
||||
$response = response()->json($payload, $status);
|
||||
|
||||
return AuthCookie::attachAuthToken($response, $token->plainTextToken);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => 'Investment',
|
||||
];
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('investment_types', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
|
||||
$table->string('code');
|
||||
$table->index('code');
|
||||
$table->string('name');
|
||||
$table->text('description')->nullable();
|
||||
|
||||
$table->string('status')->default('ACTIVE');
|
||||
|
||||
$table->decimal('minimum_amount', 15, 2)->default(0);
|
||||
$table->decimal('maximum_amount', 15, 2)->nullable();
|
||||
$table->decimal('total_fund_limit', 15, 2)->nullable();
|
||||
$table->decimal('reserved_amount', 15, 2)->default(0);
|
||||
|
||||
$table->date('start_date')->nullable();
|
||||
$table->date('end_date')->nullable();
|
||||
|
||||
$table->boolean('allow_billplz')->default(true);
|
||||
$table->boolean('allow_salary_deduction')->default(false);
|
||||
|
||||
$table->string('billplz_collection_id')->nullable();
|
||||
|
||||
$table->foreignUuid('created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->foreignUuid('updated_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('investment_types');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class InvestmentDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
InvestmentTypePermissionSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Database\Seeders;
|
||||
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class InvestmentTypePermissionSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$permissions = [
|
||||
'lihat jenis pelaburan',
|
||||
'tambah jenis pelaburan',
|
||||
'kemaskini jenis pelaburan',
|
||||
'hapus jenis pelaburan',
|
||||
];
|
||||
|
||||
foreach ($permissions as $name) {
|
||||
Permission::firstOrCreate(
|
||||
['name' => $name, 'guard_name' => 'api'],
|
||||
['name' => $name, 'guard_name' => 'api']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Modules\Auth\Entities\User;
|
||||
use Modules\Investment\Enums\InvestmentTypeStatus;
|
||||
|
||||
class InvestmentType extends Model
|
||||
{
|
||||
use HasUuids, SoftDeletes;
|
||||
|
||||
protected $table = 'investment_types';
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'description',
|
||||
'status',
|
||||
'minimum_amount',
|
||||
'maximum_amount',
|
||||
'total_fund_limit',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'allow_billplz',
|
||||
'allow_salary_deduction',
|
||||
'billplz_collection_id',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'status' => InvestmentTypeStatus::class,
|
||||
'minimum_amount' => 'decimal:2',
|
||||
'maximum_amount' => 'decimal:2',
|
||||
'total_fund_limit' => 'decimal:2',
|
||||
'reserved_amount' => 'decimal:2',
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
'allow_billplz' => 'boolean',
|
||||
'allow_salary_deduction' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function createdBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function updatedBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'updated_by');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Enums;
|
||||
|
||||
enum InvestmentTypeStatus: string
|
||||
{
|
||||
case Active = 'ACTIVE';
|
||||
case Inactive = 'INACTIVE';
|
||||
case Closed = 'CLOSED';
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InvestmentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('investment::index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('investment::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request) {}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('investment::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('investment::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id) {}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id) {}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\BaseCrudController;
|
||||
use Modules\Investment\Entities\InvestmentType;
|
||||
use Modules\Investment\Http\Requests\InvestmentTypeRequest;
|
||||
use Modules\Investment\Repositories\Contracts\InvestmentTypeRepositoryInterface;
|
||||
use Modules\Investment\Transformers\InvestmentTypeResource;
|
||||
|
||||
class InvestmentTypeController extends BaseCrudController
|
||||
{
|
||||
protected $modelClass = InvestmentType::class;
|
||||
|
||||
protected $resourceClass = InvestmentTypeResource::class;
|
||||
|
||||
protected $requestClass = InvestmentTypeRequest::class;
|
||||
|
||||
protected $resourceName = 'jenis pelaburan';
|
||||
|
||||
protected $resourceNamePlural = 'jenis pelaburan';
|
||||
|
||||
public function __construct(
|
||||
InvestmentTypeRepositoryInterface $repository,
|
||||
) {
|
||||
parent::__construct($repository);
|
||||
}
|
||||
|
||||
protected function prepareStoreData(array $validated): array
|
||||
{
|
||||
$validated['created_by'] = auth()->id();
|
||||
$validated['updated_by'] = auth()->id();
|
||||
|
||||
return $validated;
|
||||
}
|
||||
|
||||
protected function prepareUpdateData(array $validated, $item): array
|
||||
{
|
||||
$validated['updated_by'] = auth()->id();
|
||||
|
||||
return $validated;
|
||||
}
|
||||
|
||||
protected function getItemName($item): string
|
||||
{
|
||||
return $item->name ?? $item->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Investment\Enums\InvestmentTypeStatus;
|
||||
|
||||
class InvestmentTypeRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$isCreate = $this->isMethod('POST');
|
||||
$isUpdate = $this->isMethod('PUT') || $this->isMethod('PATCH');
|
||||
|
||||
if (! $isCreate && ! $isUpdate) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$codeRule = Rule::unique('investment_types', 'code')->whereNull('deleted_at');
|
||||
|
||||
if ($isUpdate) {
|
||||
$codeRule = $codeRule->ignore($this->route('investment_type'));
|
||||
}
|
||||
|
||||
return [
|
||||
'code' => ['required', 'string', 'max:50', 'alpha_dash', $codeRule],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'status' => ['required', Rule::enum(InvestmentTypeStatus::class)],
|
||||
'minimum_amount' => ['required', 'numeric', 'min:0'],
|
||||
'maximum_amount' => ['nullable', 'numeric', 'gte:minimum_amount'],
|
||||
'total_fund_limit' => ['nullable', 'numeric', 'min:0'],
|
||||
'start_date' => ['nullable', 'date'],
|
||||
'end_date' => ['nullable', 'date', 'after_or_equal:start_date'],
|
||||
'allow_billplz' => ['required', 'boolean'],
|
||||
'allow_salary_deduction' => ['required', 'boolean'],
|
||||
'billplz_collection_id' => ['nullable', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'code.required' => 'Kod jenis pelaburan diperlukan.',
|
||||
'code.unique' => 'Kod jenis pelaburan sudah wujud.',
|
||||
'code.alpha_dash' => 'Kod jenis pelaburan hanya boleh mengandungi huruf, nombor, sempang dan garis bawah.',
|
||||
'name.required' => 'Nama jenis pelaburan diperlukan.',
|
||||
'status.required' => 'Status jenis pelaburan diperlukan.',
|
||||
'minimum_amount.required' => 'Jumlah minimum diperlukan.',
|
||||
'minimum_amount.min' => 'Jumlah minimum tidak boleh negatif.',
|
||||
'maximum_amount.gte' => 'Jumlah maksimum mestilah sama atau lebih besar daripada jumlah minimum.',
|
||||
'end_date.after_or_equal' => 'Tarikh tamat mestilah pada atau selepas tarikh mula.',
|
||||
'allow_billplz.required' => 'Pilihan Billplz diperlukan.',
|
||||
'allow_salary_deduction.required' => 'Pilihan potongan gaji diperlukan.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Modules\Investment\Entities\InvestmentType;
|
||||
|
||||
class InvestmentTypePolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function viewAny($user): bool
|
||||
{
|
||||
return $user->hasPermissionTo('lihat jenis pelaburan');
|
||||
}
|
||||
|
||||
public function view($user, ?InvestmentType $investmentType = null): bool
|
||||
{
|
||||
return $user->hasPermissionTo('lihat jenis pelaburan');
|
||||
}
|
||||
|
||||
public function create($user): bool
|
||||
{
|
||||
return $user->hasPermissionTo('tambah jenis pelaburan');
|
||||
}
|
||||
|
||||
public function update($user, ?InvestmentType $investmentType = null): bool
|
||||
{
|
||||
return $user->hasPermissionTo('kemaskini jenis pelaburan');
|
||||
}
|
||||
|
||||
public function deleteAny($user): bool
|
||||
{
|
||||
return $user->hasPermissionTo('hapus jenis pelaburan');
|
||||
}
|
||||
|
||||
public function delete($user, ?InvestmentType $investmentType = null): bool
|
||||
{
|
||||
return $user->hasPermissionTo('hapus jenis pelaburan');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event handler mappings for the application.
|
||||
*
|
||||
* @var array<string, array<int, string>>
|
||||
*/
|
||||
protected $listen = [];
|
||||
|
||||
/**
|
||||
* Indicates if events should be discovered.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $shouldDiscoverEvents = true;
|
||||
|
||||
/**
|
||||
* Configure the proper event listeners for email verification.
|
||||
*/
|
||||
protected function configureEmailVerification(): void {}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Investment\Entities\InvestmentType;
|
||||
use Modules\Investment\Policies\InvestmentTypePolicy;
|
||||
use Nwidart\Modules\Traits\PathNamespace;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
class InvestmentServiceProvider extends ServiceProvider
|
||||
{
|
||||
use PathNamespace;
|
||||
|
||||
protected string $name = 'Investment';
|
||||
|
||||
protected string $nameLower = 'investment';
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerCommands();
|
||||
$this->registerCommandSchedules();
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
$this->loadMigrationsFrom(module_path($this->name, 'Database/Migrations'));
|
||||
$this->registerPolicies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(EventServiceProvider::class);
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
|
||||
$this->app->bind(
|
||||
\Modules\Investment\Repositories\Contracts\InvestmentTypeRepositoryInterface::class,
|
||||
\Modules\Investment\Repositories\InvestmentTypeRepository::class
|
||||
);
|
||||
}
|
||||
|
||||
protected function registerPolicies(): void
|
||||
{
|
||||
Gate::policy(InvestmentType::class, InvestmentTypePolicy::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register commands in the format of Command::class
|
||||
*/
|
||||
protected function registerCommands(): void
|
||||
{
|
||||
// $this->commands([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register command Schedules.
|
||||
*/
|
||||
protected function registerCommandSchedules(): void
|
||||
{
|
||||
// $this->app->booted(function () {
|
||||
// $schedule = $this->app->make(Schedule::class);
|
||||
// $schedule->command('inspire')->hourly();
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*/
|
||||
public function registerTranslations(): void
|
||||
{
|
||||
$langPath = resource_path('lang/modules/'.$this->nameLower);
|
||||
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, $this->nameLower);
|
||||
$this->loadJsonTranslationsFrom($langPath);
|
||||
} else {
|
||||
$this->loadTranslationsFrom(module_path($this->name, '$PATH_LANG$'), $this->nameLower);
|
||||
$this->loadJsonTranslationsFrom(module_path($this->name, '$PATH_LANG$'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*/
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$configPath = module_path($this->name, config('modules.paths.generator.config.path'));
|
||||
|
||||
if (is_dir($configPath)) {
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->isFile() && $file->getExtension() === 'php') {
|
||||
$config = str_replace($configPath.DIRECTORY_SEPARATOR, '', $file->getPathname());
|
||||
$config_key = str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $config);
|
||||
$segments = explode('.', $this->nameLower.'.'.$config_key);
|
||||
|
||||
// Remove duplicated adjacent segments
|
||||
$normalized = [];
|
||||
foreach ($segments as $segment) {
|
||||
if (end($normalized) !== $segment) {
|
||||
$normalized[] = $segment;
|
||||
}
|
||||
}
|
||||
|
||||
$key = ($config === 'config.php') ? $this->nameLower : implode('.', $normalized);
|
||||
|
||||
$this->publishes([$file->getPathname() => config_path($config)], 'config');
|
||||
$this->merge_config_from($file->getPathname(), $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge config from the given path recursively.
|
||||
*/
|
||||
protected function merge_config_from(string $path, string $key): void
|
||||
{
|
||||
$existing = config($key, []);
|
||||
$module_config = require $path;
|
||||
|
||||
config([$key => array_replace_recursive($existing, $module_config)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*/
|
||||
public function registerViews(): void
|
||||
{
|
||||
$viewPath = resource_path('views/modules/'.$this->nameLower);
|
||||
$sourcePath = module_path($this->name, '$PATH_VIEWS$');
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
|
||||
|
||||
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
|
||||
|
||||
Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*/
|
||||
public function provides(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getPublishableViewPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
foreach (config('view.paths') as $path) {
|
||||
if (is_dir($path.'/modules/'.$this->nameLower)) {
|
||||
$paths[] = $path.'/modules/'.$this->nameLower;
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $name = 'Investment';
|
||||
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*/
|
||||
public function map(): void
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*/
|
||||
protected function mapWebRoutes(): void
|
||||
{
|
||||
Route::middleware('web')->group(module_path($this->name, '/Routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*/
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::middleware('api')->name('api.')->group(module_path($this->name, '/Routes/api.php'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Repositories\Contracts;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\Investment\Entities\InvestmentType;
|
||||
|
||||
interface InvestmentTypeRepositoryInterface
|
||||
{
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '');
|
||||
|
||||
public function getAllWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $sortBy = 'name',
|
||||
string $sortOrder = 'asc'
|
||||
);
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection;
|
||||
|
||||
public function create(array $data): InvestmentType;
|
||||
|
||||
public function findById(string $id): ?InvestmentType;
|
||||
|
||||
public function delete(string $id): bool;
|
||||
|
||||
public function all(string $search = ''): Collection;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\Investment\Entities\InvestmentType;
|
||||
use Modules\Investment\Repositories\Contracts\InvestmentTypeRepositoryInterface;
|
||||
|
||||
class InvestmentTypeRepository implements InvestmentTypeRepositoryInterface
|
||||
{
|
||||
protected function baseQuery()
|
||||
{
|
||||
return InvestmentType::query()->orderBy('name');
|
||||
}
|
||||
|
||||
protected function applySearch($query, string $search)
|
||||
{
|
||||
if ($search !== '') {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%")
|
||||
->orWhere('code', 'ILIKE', "%{$search}%")
|
||||
->orWhere('description', 'ILIKE', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '')
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getAllWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $sortBy = 'name',
|
||||
string $sortOrder = 'asc'
|
||||
) {
|
||||
$allowedSortColumns = [
|
||||
'id',
|
||||
'code',
|
||||
'name',
|
||||
'status',
|
||||
'minimum_amount',
|
||||
'maximum_amount',
|
||||
'total_fund_limit',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'created_at',
|
||||
];
|
||||
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'name';
|
||||
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
$query = InvestmentType::query()->orderBy($sortBy, $sortOrder);
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function create(array $data): InvestmentType
|
||||
{
|
||||
return InvestmentType::create($data);
|
||||
}
|
||||
|
||||
public function findById(string $id): ?InvestmentType
|
||||
{
|
||||
return InvestmentType::query()->find($id);
|
||||
}
|
||||
|
||||
public function delete(string $id): bool
|
||||
{
|
||||
$investmentType = $this->findById($id);
|
||||
|
||||
if ($investmentType) {
|
||||
return (bool) $investmentType->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function all(string $search = ''): Collection
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Investment\Http\Controllers\InvestmentTypeController;
|
||||
|
||||
Route::middleware(['auth:sanctum', 'single.session'])->prefix('v1')->group(function () {
|
||||
Route::apiResource('investment-types', InvestmentTypeController::class)->names('investment-type');
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Investment\Http\Controllers\InvestmentController;
|
||||
|
||||
Route::middleware(['auth', 'verified'])->group(function () {
|
||||
Route::resource('investments', InvestmentController::class)->names('investment');
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investment\Transformers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InvestmentTypeResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'status' => $this->status?->value ?? $this->status,
|
||||
'minimum_amount' => $this->minimum_amount,
|
||||
'maximum_amount' => $this->maximum_amount,
|
||||
'total_fund_limit' => $this->total_fund_limit,
|
||||
'reserved_amount' => $this->reserved_amount,
|
||||
'start_date' => $this->start_date?->toDateString(),
|
||||
'end_date' => $this->end_date?->toDateString(),
|
||||
'allow_billplz' => (bool) $this->allow_billplz,
|
||||
'allow_salary_deduction' => (bool) $this->allow_salary_deduction,
|
||||
'billplz_collection_id' => $this->billplz_collection_id,
|
||||
'created_by' => $this->created_by,
|
||||
'updated_by' => $this->updated_by,
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'updated_at' => $this->updated_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "nwidart/investment",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Widart",
|
||||
"email": "n.widart@gmail.com"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [],
|
||||
"aliases": {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\Investment\\": "App",
|
||||
"Modules\\Investment\\Database\\Factories\\": "database/factories/",
|
||||
"Modules\\Investment\\Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Modules\\Investment\\Tests\\": "tests/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "Investment",
|
||||
"alias": "investment",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"priority": 0,
|
||||
"providers": [
|
||||
"Modules\\Investment\\Providers\\InvestmentServiceProvider"
|
||||
],
|
||||
"files": []
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"axios": "^1.1.2",
|
||||
"laravel-vite-plugin": "^0.7.5",
|
||||
"sass": "^1.69.5",
|
||||
"postcss": "^8.3.7",
|
||||
"vite": "^4.0.0"
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Modules\Role\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\BaseCrudController;
|
||||
use App\Services\ActivityLogger;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -69,8 +68,6 @@ class RoleController extends BaseCrudController
|
||||
// Use repository update method to handle permissions
|
||||
$updatedItem = $this->repository->update($id, $data);
|
||||
|
||||
ActivityLogger::log("Updated {$this->resourceName}: {$this->getItemName($updatedItem)}", $updatedItem);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => new $this->resourceClass($updatedItem),
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Modules\User\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\BaseCrudController;
|
||||
use App\Services\ActivityLogger;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -324,8 +323,6 @@ class UserController extends BaseCrudController
|
||||
], 404);
|
||||
}
|
||||
|
||||
ActivityLogger::log("Restored {$this->resourceName}: {$user->name}", $user);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'User restored successfully.',
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\ActivityLogger;
|
||||
use App\Traits\NotifiesAdmins;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
@@ -22,23 +22,6 @@ class ActivityLogger
|
||||
return $activity;
|
||||
}
|
||||
|
||||
public static function logLogin(string $email): void
|
||||
{
|
||||
self::log("User logged in with email: {$email}", null, [
|
||||
'email' => $email,
|
||||
'ip_address' => request()->ip(),
|
||||
'user_agent' => request()->userAgent(),
|
||||
], 'authentication');
|
||||
}
|
||||
|
||||
public static function logLogout(): void
|
||||
{
|
||||
self::log('User logged out', null, [
|
||||
'ip_address' => request()->ip(),
|
||||
'user_agent' => request()->userAgent(),
|
||||
], 'authentication');
|
||||
}
|
||||
|
||||
public static function logView(Model $model, ?string $customDescription = null): void
|
||||
{
|
||||
$modelName = class_basename($model);
|
||||
|
||||
@@ -9,5 +9,6 @@
|
||||
"MembershipApplication": true,
|
||||
"Activity": true,
|
||||
"ExternalSystem": true,
|
||||
"Feedback": true
|
||||
"Feedback": true,
|
||||
"Investment": true
|
||||
}
|
||||
Reference in New Issue
Block a user