Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Oct 5, 2023
2 parents 353540d + e7a7cf4 commit 349b09c
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 96 deletions.
3 changes: 0 additions & 3 deletions src/Http/Controllers/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ public function show(string|int $id): RoleResource|JsonResponse
* Update a specified role resource using id.
*
* @lrd:end
* @param UpdateRoleRequest $request
* @param int|string $id
* @return JsonResponse
*/
public function update(UpdateRoleRequest $request, string|int $id): JsonResponse
{
Expand Down
27 changes: 8 additions & 19 deletions src/Http/Controllers/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ public function index(IndexTeamRequest $request): TeamCollection|JsonResponse
* Create a new team resource in storage.
*
* @lrd:end
*
* @param StoreTeamRequest $request
* @return JsonResponse
*/
public function store(StoreTeamRequest $request): JsonResponse
{
Expand All @@ -70,7 +67,7 @@ public function store(StoreTeamRequest $request): JsonResponse

$team = Auth::team()->create($inputs);

if (!$team) {
if (! $team) {
throw (new StoreOperationException)->setModel(config('fintech.auth.team_model'));
}

Expand All @@ -90,16 +87,14 @@ public function store(StoreTeamRequest $request): JsonResponse
* Return a specified team resource found by id.
*
* @lrd:end
* @param int|string $id
* @return TeamResource|JsonResponse
*/
public function show(string|int $id): TeamResource|JsonResponse
{
try {

$team = Auth::team()->find($id);

if (!$team) {
if (! $team) {
throw (new ModelNotFoundException)->setModel(config('fintech.auth.team_model'), $id);
}

Expand All @@ -120,24 +115,20 @@ public function show(string|int $id): TeamResource|JsonResponse
* Update a specified team resource using id.
*
* @lrd:end
*
* @param UpdateTeamRequest $request
* @param int|string $id
* @return JsonResponse
*/
public function update(UpdateTeamRequest $request, string|int $id): JsonResponse
{
try {

$team = Auth::team()->find($id);

if (!$team) {
if (! $team) {
throw (new ModelNotFoundException)->setModel(config('fintech.auth.team_model'), $id);
}

$inputs = $request->validated();

if (!Auth::team()->update($id, $inputs)) {
if (! Auth::team()->update($id, $inputs)) {

throw (new UpdateOperationException)->setModel(config('fintech.auth.team_model'), $id);
}
Expand All @@ -160,21 +151,19 @@ public function update(UpdateTeamRequest $request, string|int $id): JsonResponse
*
* @lrd:end
*
* @param int|string $id
* @return JsonResponse
*
*/
public function destroy(string|int $id)
{
try {

$team = Auth::team()->find($id);

if (!$team) {
if (! $team) {
throw (new ModelNotFoundException)->setModel(config('fintech.auth.team_model'), $id);
}

if (!Auth::team()->destroy($id)) {
if (! Auth::team()->destroy($id)) {

throw (new DeleteOperationException)->setModel(config('fintech.auth.team_model'), $id);
}
Expand Down Expand Up @@ -206,11 +195,11 @@ public function restore(string|int $id)

$team = Auth::team()->find($id, true);

if (!$team) {
if (! $team) {
throw (new ModelNotFoundException)->setModel(config('fintech.auth.team_model'), $id);
}

if (!Auth::team()->restore($id)) {
if (! Auth::team()->restore($id)) {

throw (new RestoreOperationException)->setModel(config('fintech.auth.team_model'), $id);
}
Expand Down
1 change: 0 additions & 1 deletion src/Http/Requests/IndexRoleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ public function rules(): array
'dir' => ['string', 'min:3', 'max:4'],
];
}

}
2 changes: 1 addition & 1 deletion src/Http/Resources/PermissionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PermissionCollection extends ResourceCollection
/**
* Transform the resource collection into an array.
*
* @param Request $request
* @param Request $request
* @return array
*/
public function toArray($request)
Expand Down
22 changes: 11 additions & 11 deletions src/Http/Resources/RoleCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ class RoleCollection extends ResourceCollection
/**
* Transform the resource collection into an array.
*
* @param Request $request
* @param Request $request
* @return array
*/
public function toArray($request)
{
return $this->collection->map(function ($role) {
$return = [
"id" => $role->id,
"team_id" => $role->team_id ?? null,
"team_name" => ($role->team != null) ? $role->team->name : null,
"name" => $role->name ?? null,
"guard_name" => $role->guard_name ?? null,
"permissions" => [],
"created_at" => $role->created_at,
"updated_at" => $role->updated_at,
"links" => $role->links,
'id' => $role->id,
'team_id' => $role->team_id ?? null,
'team_name' => ($role->team != null) ? $role->team->name : null,
'name' => $role->name ?? null,
'guard_name' => $role->guard_name ?? null,
'permissions' => [],
'created_at' => $role->created_at,
'updated_at' => $role->updated_at,
'links' => $role->links,
];

if (!$role->permissions->isEmpty()) {
if (! $role->permissions->isEmpty()) {
foreach ($role->permissions as $permission) {
$return['permissions'][] = [
'id' => $permission->id,
Expand Down
16 changes: 8 additions & 8 deletions src/Http/Resources/TeamCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ class TeamCollection extends ResourceCollection
/**
* Transform the resource collection into an array.
*
* @param Request $request
* @param Request $request
* @return array
*/
public function toArray($request)
{
return $this->collection->map(function ($team) {
$return = [
"id" => $team->id,
"name" => $team->name ?? null,
"roles" => [],
"created_at" => $team->created_at,
"updated_at" => $team->updated_at,
"links" => $team->links,
'id' => $team->id,
'name' => $team->name ?? null,
'roles' => [],
'created_at' => $team->created_at,
'updated_at' => $team->updated_at,
'links' => $team->links,
];

if (!$team->roles->isEmpty()) {
if (! $team->roles->isEmpty()) {
foreach ($team->roles as $role) {
$return['roles'][] = [
'id' => $role->id,
Expand Down
29 changes: 8 additions & 21 deletions src/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
class Permission extends Model implements Auditable, PermissionContract
{
use BlameableTrait;
use \OwenIt\Auditing\Auditable;
use SoftDeletes;
use HasRoles;
use \OwenIt\Auditing\Auditable;
use RefreshesPermissionCache;
use SoftDeletes;

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -76,16 +76,13 @@ public static function create(array $attributes = [])
/**
* Find a permission by its name (and optionally guardName).
*
* @param string $name
* @param null $guardName
*
* @return PermissionContract
* @param null $guardName
*/
public static function findByName(string $name, $guardName = null): PermissionContract
{
$guardName = $guardName ?? Guard::getDefaultName(static::class);
$permission = static::getPermission(['name' => $name, 'guard_name' => $guardName]);
if (!$permission) {
if (! $permission) {
throw PermissionDoesNotExist::create($name, $guardName);
}

Expand All @@ -95,17 +92,14 @@ public static function findByName(string $name, $guardName = null): PermissionCo
/**
* Find a permission by its id (and optionally guardName).
*
* @param int $id
* @param null $guardName
*
* @return PermissionContract
* @param null $guardName
*/
public static function findById(int $id, $guardName = null): PermissionContract
{
$guardName = $guardName ?? Guard::getDefaultName(static::class);
$permission = static::getPermission([(new static())->getKeyName() => $id, 'guard_name' => $guardName]);

if (!$permission) {
if (! $permission) {
throw PermissionDoesNotExist::withId($id, $guardName);
}

Expand All @@ -115,16 +109,14 @@ public static function findById(int $id, $guardName = null): PermissionContract
/**
* Find or create permission by its name (and optionally guardName).
*
* @param string $name
* @param null $guardName
* @return PermissionContract
* @param null $guardName
*/
public static function findOrCreate(string $name, $guardName = null): PermissionContract
{
$guardName = $guardName ?? Guard::getDefaultName(static::class);
$permission = static::getPermission(['name' => $name, 'guard_name' => $guardName]);

if (!$permission) {
if (! $permission) {
return static::query()->create(['name' => $name, 'guard_name' => $guardName]);
}

Expand All @@ -133,9 +125,6 @@ public static function findOrCreate(string $name, $guardName = null): Permission

/**
* Get the current cached permissions.
* @param array $params
* @param bool $onlyOne
* @return Collection
*/
protected static function getPermissions(array $params = [], bool $onlyOne = false): Collection
{
Expand All @@ -146,8 +135,6 @@ protected static function getPermissions(array $params = [], bool $onlyOne = fal

/**
* Get the current cached first permission.
*
* @return PermissionContract
*/
protected static function getPermission(array $params = []): ?PermissionContract
{
Expand Down
Loading

0 comments on commit 349b09c

Please sign in to comment.