Skip to content

Commit

Permalink
LP-15 user status duplicate api merged
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Nov 19, 2023
2 parents 703de19 + 43f00d4 commit 595bde3
Show file tree
Hide file tree
Showing 13 changed files with 326 additions and 61 deletions.
20 changes: 20 additions & 0 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@
'documents.*.type' => ['string', 'required'],
'documents.*.back' => ['string', 'required_without:documents.*.front'],
'documents.*.front' => ['string', 'required_without:documents.*.back'],
'employer' => ['array', 'nullable'],
'employer.employer_name' => ['string', 'nullable'],
'employer.company_address' => ['string', 'nullable'],
'employer.company_registration_number' => ['string', 'nullable'],
'proof_of_address' => ['array', 'required', 'min:1'],
'proof_of_address.*.type' => ['string', 'required'],
'proof_of_address.*.back' => ['string', 'required_without:proof_of_address.*.front'],
Expand Down Expand Up @@ -238,6 +242,22 @@
//'middleware' => ['auth:sanctum'],
'middleware' => [],

/*
|--------------------------------------------------------------------------
| Constant
|--------------------------------------------------------------------------
|
| This value will be used across systems where a constant instance is needed
*/

'proof_of_address_types' => [
'tenancy_contract' => 'Tenancy Contract',
'utility_bill' => 'Utility Bill',
'bank_statement' => 'Bank Statement',
'credit_card_statement' => 'Credit Card Statement',
'telephone_bill' => 'Telephone Bill',
],

/*
|--------------------------------------------------------------------------
| Repositories
Expand Down
14 changes: 11 additions & 3 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Fintech\Auth\Http\Controllers\AuthenticatedController;
use Fintech\Auth\Http\Controllers\IdDocTypeController;
use Fintech\Auth\Http\Controllers\OneTimePinController;
use Fintech\Auth\Http\Controllers\PasswordResetController;
use Fintech\Auth\Http\Controllers\PermissionController;
Expand Down Expand Up @@ -53,7 +54,6 @@
->name('verify-otp');

Route::middleware(config('fintech.auth.middleware'))->group(function () {
Route::get('users/user-status', [UserController::class, 'userStatus'])->name('users.user-status');
Route::apiResource('users', UserController::class);
Route::post('users/{user}/restore', [UserController::class, 'restore'])->name('users.restore');
Route::post('users/{user}/reset/{field}', [UserController::class, 'reset'])
Expand All @@ -74,10 +74,18 @@

Route::apiResource('audits', \Fintech\Auth\Http\Controllers\AuditController::class)->only('index', 'show', 'destroy');

Route::apiResource('id-doc-types', \Fintech\Auth\Http\Controllers\IdDocTypeController::class);
Route::post('id-doc-types/{id_doc_type}/restore', [\Fintech\Auth\Http\Controllers\IdDocTypeController::class, 'restore'])->name('id-doc-types.restore');
Route::apiResource('id-doc-types', IdDocTypeController::class);
Route::post('id-doc-types/{id_doc_type}/restore', [IdDocTypeController::class, 'restore'])->name('id-doc-types.restore');

//DO NOT REMOVE THIS LINE//
});
});
Route::prefix('dropdown')->name('auth.')->group(function () {
Route::get('id-doc-types', [IdDocTypeController::class, 'dropdown'])->name('id-doc-types.dropdown');
Route::get('roles', [RoleController::class, 'dropdown'])->name('roles.dropdown');
// Route::get('teams', [\Fintech\Auth\Http\Controllers\TeamController::class, 'dropdown'])->name('teams.dropdown');
Route::get('users', [UserController::class, 'dropdown'])->name('users.dropdown');
Route::get('user-statuses', [UserController::class, 'statusDropdown'])->name('user-statuses.dropdown');
Route::get('proof-of-addresses', [UserController::class, 'proofOfAddressDropdown'])->name('user-proof-of-address.dropdown');
});
}
2 changes: 1 addition & 1 deletion src/Http/Controllers/AuthenticatedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function login(LoginRequest $request): LoginResource|JsonResponse
if ($attemptUser->wrong_password > config('fintech.auth.password_threshold', 10)) {

\Fintech\Auth\Facades\Auth::user()->update($attemptUser->getKey(), [
'status' => UserStatus::InActive->value,
'status' => UserStatus::Suspended->value,
]);

AccountFreezed::dispatch($attemptUser);
Expand Down
39 changes: 39 additions & 0 deletions src/Http/Controllers/IdDocTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Fintech\Core\Exceptions\UpdateOperationException;
use Fintech\Core\Exceptions\DeleteOperationException;
use Fintech\Core\Exceptions\RestoreOperationException;
use Fintech\Core\Http\Requests\DropDownRequest;
use Fintech\Core\Http\Resources\DropDownCollection;
use Fintech\Core\Traits\ApiResponseTrait;
use Fintech\Auth\Facades\Auth;
use Fintech\Auth\Http\Resources\IdDocTypeResource;
Expand Down Expand Up @@ -283,4 +285,41 @@ public function import(ImportIdDocTypeRequest $request): JsonResponse
return $this->failed($exception->getMessage());
}
}

/**
* @param DropDownRequest $request
* @return DropDownCollection|JsonResponse
*/
public function dropdown(DropDownRequest $request): DropDownCollection|JsonResponse
{
try {
$filters = $request->all();

$label = 'name';

$attribute = 'id';

if (!empty($filters['label'])) {
$label = $filters['label'];
unset($filters['label']);
}

if (!empty($filters['attribute'])) {
$attribute = $filters['attribute'];
unset($filters['attribute']);
}

$entries = Auth::idDocType()->list($filters)->map(function ($entry) use ($label, $attribute) {
return [
'label' => $entry->{$label} ?? 'name',
'attribute' => $entry->{$attribute} ?? 'id'
];
});

return new DropDownCollection($entries);

} catch (Exception $exception) {
return $this->failed($exception->getMessage());
}
}
}
39 changes: 39 additions & 0 deletions src/Http/Controllers/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Fintech\Core\Exceptions\RestoreOperationException;
use Fintech\Core\Exceptions\StoreOperationException;
use Fintech\Core\Exceptions\UpdateOperationException;
use Fintech\Core\Http\Requests\DropDownRequest;
use Fintech\Core\Http\Resources\DropDownCollection;
use Fintech\Core\Traits\ApiResponseTrait;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -339,4 +341,41 @@ public function import(ImportRoleRequest $request): RoleCollection|JsonResponse
return $this->failed($exception->getMessage());
}
}

/**
* @param DropDownRequest $request
* @return DropDownCollection|JsonResponse
*/
public function dropdown(DropDownRequest $request): DropDownCollection|JsonResponse
{
try {
$filters = $request->all();

$label = 'name';

$attribute = 'id';

if (!empty($filters['label'])) {
$label = $filters['label'];
unset($filters['label']);
}

if (!empty($filters['attribute'])) {
$attribute = $filters['attribute'];
unset($filters['attribute']);
}

$entries = Auth::role()->list($filters)->map(function ($entry) use ($label, $attribute) {
return [
'attribute' => $entry->{$attribute} ?? 'id',
'label' => $entry->{$label} ?? 'name',
];
})->toArray();

return new DropDownCollection($entries);

} catch (Exception $exception) {
return $this->failed($exception->getMessage());
}
}
}
39 changes: 39 additions & 0 deletions src/Http/Controllers/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Fintech\Core\Exceptions\RestoreOperationException;
use Fintech\Core\Exceptions\StoreOperationException;
use Fintech\Core\Exceptions\UpdateOperationException;
use Fintech\Core\Http\Requests\DropDownRequest;
use Fintech\Core\Http\Resources\DropDownCollection;
use Fintech\Core\Traits\ApiResponseTrait;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -276,4 +278,41 @@ public function import(ImportTeamRequest $request): TeamCollection|JsonResponse
return $this->failed($exception->getMessage());
}
}

/**
* @param DropDownRequest $request
* @return DropDownCollection|JsonResponse
*/
public function dropdown(DropDownRequest $request): DropDownCollection|JsonResponse
{
try {
$filters = $request->all();

$label = 'name';

$attribute = 'id';

if (!empty($filters['label'])) {
$label = $filters['label'];
unset($filters['label']);
}

if (!empty($filters['attribute'])) {
$attribute = $filters['attribute'];
unset($filters['attribute']);
}

$entries = Auth::team()->list($filters)->map(function ($entry) use ($label, $attribute) {
return [
'label' => $entry->{$label} ?? 'name',
'attribute' => $entry->{$attribute} ?? 'id'
];
});

return new DropDownCollection($entries);

} catch (Exception $exception) {
return $this->failed($exception->getMessage());
}
}
}
81 changes: 74 additions & 7 deletions src/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Fintech\Core\Exceptions\RestoreOperationException;
use Fintech\Core\Exceptions\StoreOperationException;
use Fintech\Core\Exceptions\UpdateOperationException;
use Fintech\Core\Http\Requests\DropDownRequest;
use Fintech\Core\Http\Resources\DropDownCollection;
use Fintech\Core\Traits\ApiResponseTrait;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -266,6 +268,7 @@ public function export(IndexUserRequest $request): JsonResponse
*
* @lrd:end
*
* @param ImportUserRequest $request
* @return UserCollection|JsonResponse
*/
public function import(ImportUserRequest $request): UserCollection|JsonResponse
Expand All @@ -291,6 +294,7 @@ public function import(ImportUserRequest $request): UserCollection|JsonResponse
* @lrd:end
*
* @param int|string $id
* @param string $field
* @param UserAuthResetRequest $request
* @return JsonResponse
*/
Expand Down Expand Up @@ -326,16 +330,79 @@ public function reset(string|int $id, string $field, UserAuthResetRequest $reque
}

/**
* @return array
* @param DropDownRequest $request
* @return DropDownCollection|JsonResponse
*/
public function userStatus(): array
public function dropdown(DropDownRequest $request): DropDownCollection|JsonResponse
{
$userStatus = UserStatus::cases();
$array = [];
foreach($userStatus as $case) {
$array[$case->value] = $case->name;
try {
$filters = $request->all();

$label = 'name';

$attribute = 'id';

if (!empty($filters['label'])) {
$label = $filters['label'];
unset($filters['label']);
}

if (!empty($filters['attribute'])) {
$attribute = $filters['attribute'];
unset($filters['attribute']);
}

$entries = Auth::user()->list($filters)->map(function ($entry) use ($label, $attribute) {
return [
'label' => $entry->{$label} ?? 'name',
'attribute' => $entry->{$attribute} ?? 'id'
];
});

return new DropDownCollection($entries);

} catch (Exception $exception) {
return $this->failed($exception->getMessage());
}
return $array;
}

/**
* @param DropDownRequest $request
* @return DropDownCollection|JsonResponse
*/
public function statusDropdown(DropDownRequest $request): DropDownCollection|JsonResponse
{
try {
$entries = collect();

foreach (UserStatus::toArray() as $key => $status) {
$entries->push(['label' => $status, 'attribute' => $key]);
}

return new DropDownCollection($entries);

} catch (Exception $exception) {
return $this->failed($exception->getMessage());
}
}

/**
* @param DropDownRequest $request
* @return DropDownCollection|JsonResponse
*/
public function proofOfAddressDropdown(DropDownRequest $request): DropDownCollection|JsonResponse
{
try {
$entries = collect();

foreach (config('fintech.auth.proof_of_address_types', []) as $key => $status) {
$entries->push(['label' => $status, 'attribute' => $key]);
}

return new DropDownCollection($entries);

} catch (Exception $exception) {
return $this->failed($exception->getMessage());
}
}
}
Loading

0 comments on commit 595bde3

Please sign in to comment.