Skip to content

Commit

Permalink
Feature: Merging up from other repo - a few small test upda=ates stil…
Browse files Browse the repository at this point in the history
…l required
  • Loading branch information
ok200paul committed Aug 16, 2024
1 parent b5dea8e commit 13f4da2
Show file tree
Hide file tree
Showing 42 changed files with 1,831 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ class ApiAdminTeamMerchantTeamsController extends Controller
/**
* Set the related data the GET request is allowed to ask for
*/
public array $availableRelations = [];

public static array $searchableFields = [];
public array $availableRelations = [
'team',
'merchantTeam',
];

public static array $searchableFields = [
'team_id',
'merchant_team_id',
];

/**
* GET /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace App\Http\Controllers\Api\V1\Admin;

use App\Enums\ApiResponse;
use App\Exceptions\DisallowedApiFieldException;
use App\Http\Controllers\Api\HandlesAPIRequests;
use App\Http\Controllers\Controller;
use App\Models\TeamServiceTeam;
Expand All @@ -21,13 +22,22 @@ class ApiAdminTeamServiceTeamsController extends Controller
/**
* Set the related data the GET request is allowed to ask for
*/
public array $availableRelations = [];
public array $availableRelations = [
'team',
'serviceTeam',
];

public static array $searchableFields = [];
public static array $searchableFields = [
'team_id',
'service_team_id',
];

/**
* GET /
*
* @return JsonResponse
* GET /
*
* @throws DisallowedApiFieldException
*/
public function index(): JsonResponse
{
Expand All @@ -39,8 +49,9 @@ public function index(): JsonResponse
}

/**
* POST /
*
* @return JsonResponse
* POST /
*/
public function store(): JsonResponse
{
Expand Down Expand Up @@ -99,10 +110,11 @@ public function store(): JsonResponse
}

/**
* GET / {id}
*
* @param string $id
*
* @return JsonResponse
* GET / {id}
*/
public function show(string $id)
{
Expand All @@ -113,10 +125,11 @@ public function show(string $id)
}

/**
* PUT/ {id}
*
* @param string $id
*
* @return JsonResponse
* PUT/ {id}
*/
public function update(string $id)
{
Expand All @@ -127,10 +140,11 @@ public function update(string $id)
}

/**
* DELETE / {id}
*
* @param string $id
*
* @return JsonResponse
* DELETE / {id}
*/
public function destroy(string $id)
{
Expand Down
13 changes: 10 additions & 3 deletions app/Http/Controllers/Api/V1/Admin/ApiAdminTeamUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ class ApiAdminTeamUsersController extends Controller
/**
* Set the related data the GET request is allowed to ask for
*/
public array $availableRelations = [];

public static array $searchableFields = [];
public array $availableRelations = [
'team',
'user',
];

public static array $searchableFields = [
'id',
'team_id',
'user_id',
];

/**
* GET /
Expand Down
25 changes: 19 additions & 6 deletions app/Http/Controllers/Api/V1/Admin/ApiAdminTeamsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Http\Controllers\Api\V1\Admin;

use App\Enums\ApiResponse;
use App\Exceptions\DisallowedApiFieldException;
use App\Http\Controllers\Api\HandlesAPIRequests;
use App\Http\Controllers\Controller;
use App\Models\Team;
Expand All @@ -21,11 +22,17 @@ class ApiAdminTeamsController extends Controller
*/
public array $availableRelations = [];

public static array $searchableFields = [];
public static array $searchableFields = [
'id',
'name',
];

/**
* GET /
*
* @return JsonResponse
* GET /
*
* @throws DisallowedApiFieldException
*/
public function index(): JsonResponse
{
Expand All @@ -37,8 +44,9 @@ public function index(): JsonResponse
}

/**
* POST /
*
* @return JsonResponse
* POST /
*/
public function store(): JsonResponse
{
Expand Down Expand Up @@ -94,10 +102,13 @@ public function store(): JsonResponse
}

/**
* GET / {id}
*
* @param string $id
*
* @return JsonResponse
* GET / {id}
*
* @throws DisallowedApiFieldException
*/
public function show(string $id)
{
Expand All @@ -109,10 +120,11 @@ public function show(string $id)
}

/**
* PUT/ {id}
*
* @param string $id
*
* @return JsonResponse
* PUT/ {id}
*/
public function update(string $id)
{
Expand Down Expand Up @@ -171,10 +183,11 @@ public function update(string $id)
}

/**
* DELETE / {id}
*
* @param string $id
*
* @return JsonResponse
* DELETE / {id}
*/
public function destroy(string $id)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

/** @noinspection PhpUnusedParameterInspection */

/** @noinspection PhpUndefinedMethodInspection */

namespace App\Http\Controllers\Api\V1\Admin;

use App\Enums\ApiResponse;
use App\Enums\PersonalAccessTokenAbility;
use App\Http\Controllers\Api\HandlesAPIRequests;
use App\Http\Controllers\Controller;
use App\Models\User;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

class ApiAdminUserPersonalAccessTokensController extends Controller
{
use HandlesAPIRequests;

/**
* Set the related data the GET request is allowed to ask for
*/
public array $availableRelations = [];

public static array $searchableFields = [];

/**
* GET /
*
* @return JsonResponse
*/
public function index(): JsonResponse
{
$this->responseCode = 403;
$this->message = ApiResponse::RESPONSE_METHOD_NOT_ALLOWED->value;

return $this->respond();
}

/**
* POST /
*
* @return JsonResponse
*/
public function store(): JsonResponse
{
/**
* The validation array.
*/
$validationArray = [
'user_id' => [
'required',
Rule::exists('users', 'id'),
],
'name' => [
'required',
'string',
],
'token_abilities' => [
'required',
'array',
],
'token_abilities.*' => [
Rule::in(PersonalAccessTokenAbility::cases()),
],
];

$validator = Validator::make($this->request->all(), $validationArray);

if ($validator->fails()) {

$this->responseCode = 400;
$this->message = $validator->errors()
->first();

}
else {

try {

$userId = $this->request->get('user_id');
$name = $this->request->get('name');
$tokenAbilities = $this->request->get('token_abilities');

$user = User::find($userId);

$token = $user->createToken(
name: $name,
abilities: $tokenAbilities,
teamId: $user->current_team_id
);

$this->message = ApiResponse::RESPONSE_SAVED->value;
$this->data = ['token' => $token->plainTextToken];

}
catch (Exception $e) {

$this->responseCode = 500;
$this->message = ApiResponse::RESPONSE_ERROR->value . ': "' . $e->getMessage() . '".';

}
}

return $this->respond();

}

/**
* GET / {id}
*
* @param string $id
*
* @return JsonResponse
*/
public function show(string $id)
{
$this->responseCode = 403;
$this->message = ApiResponse::RESPONSE_METHOD_NOT_ALLOWED->value;

return $this->respond();
}

/**
* PUT/ {id}
*
* @param string $id
*
* @return JsonResponse
*/
public function update(string $id)
{
$this->responseCode = 403;
$this->message = ApiResponse::RESPONSE_METHOD_NOT_ALLOWED->value;

return $this->respond();
}

/**
* DELETE / {id}
*
* @param string $id
*
* @return JsonResponse
*/
public function destroy(string $id)
{
$this->responseCode = 403;
$this->message = ApiResponse::RESPONSE_METHOD_NOT_ALLOWED->value;

return $this->respond();
}
}
Loading

0 comments on commit 13f4da2

Please sign in to comment.