-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
audit items tests, controllers and UI
- Loading branch information
1 parent
d1516aa
commit f527ca9
Showing
28 changed files
with
1,295 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
app/Http/Controllers/Api/V1/Admin/ApiAdminAuditItemsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
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\AuditItem; | ||
use Illuminate\Http\JsonResponse; | ||
|
||
class ApiAdminAuditItemsController extends Controller | ||
{ | ||
use HandlesAPIRequests; | ||
|
||
/** | ||
* Set the related data the GET request is allowed to ask for | ||
*/ | ||
public array $availableRelations = [ | ||
'team' | ||
]; | ||
|
||
public static array $searchableFields = []; | ||
|
||
/** | ||
* GET / | ||
* | ||
* @return JsonResponse | ||
* | ||
* @throws DisallowedApiFieldException | ||
*/ | ||
public function index(): JsonResponse | ||
{ | ||
$this->query = AuditItem::with($this->associatedData); | ||
$this->query = $this->updateReadQueryBasedOnUrl(); | ||
$this->data = $this->query->paginate($this->limit); | ||
|
||
return $this->respond(); | ||
} | ||
|
||
/** | ||
* POST / | ||
* | ||
* @return JsonResponse | ||
*/ | ||
public function store(): JsonResponse | ||
{ | ||
$this->responseCode = 403; | ||
$this->message = ApiResponse::RESPONSE_METHOD_NOT_ALLOWED->value; | ||
|
||
return $this->respond(); | ||
} | ||
|
||
/** | ||
* GET /{id} | ||
* | ||
* @param int $id | ||
* | ||
* @return JsonResponse | ||
* | ||
* @throws DisallowedApiFieldException | ||
*/ | ||
public function show(int $id) | ||
{ | ||
$this->query = AuditItem::with($this->associatedData); | ||
$this->query = $this->updateReadQueryBasedOnUrl(); | ||
$this->data = $this->query->find($id); | ||
|
||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
app/Http/Controllers/Api/V1/ApiMyTeamAuditItemsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1; | ||
|
||
use App\Enums\ApiResponse; | ||
use App\Exceptions\DisallowedApiFieldException; | ||
use App\Http\Controllers\Api\HandlesAPIRequests; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\AuditItem; | ||
use Auth; | ||
use Illuminate\Http\JsonResponse; | ||
|
||
class ApiMyTeamAuditItemsController 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 | ||
* | ||
* @throws DisallowedApiFieldException | ||
*/ | ||
public function index(): JsonResponse | ||
{ | ||
$this->query = AuditItem::where('team_id', Auth::user()->current_team_id)->with($this->associatedData); | ||
$this->query = $this->updateReadQueryBasedOnUrl(); | ||
$this->data = $this->query->paginate($this->limit); | ||
|
||
return $this->respond(); | ||
} | ||
|
||
/** | ||
* POST / | ||
* | ||
* @return JsonResponse | ||
*/ | ||
public function store(): JsonResponse | ||
{ | ||
$this->responseCode = 403; | ||
$this->message = ApiResponse::RESPONSE_METHOD_NOT_ALLOWED->value; | ||
|
||
return $this->respond(); | ||
} | ||
|
||
/** | ||
* GET /{id} | ||
* | ||
* @param int $id | ||
* | ||
* @return JsonResponse | ||
*/ | ||
public function show(int $id) | ||
{ | ||
$this->query = AuditItem::where('team_id', Auth::user()->current_team_id)->with($this->associatedData); | ||
$this->query = $this->updateReadQueryBasedOnUrl(); | ||
$this->data = $this->query->find($id); | ||
|
||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\Relations\HasOne; | ||
use Illuminate\Database\Eloquent\Relations\MorphTo; | ||
|
||
class AuditItem extends Model | ||
{ | ||
use HasFactory; | ||
|
||
public function auditable(): MorphTo | ||
{ | ||
return $this->morphTo(); | ||
} | ||
|
||
public function team(): BelongsTo | ||
{ | ||
return $this->belongsTo( Team::class, 'team_id', 'id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Team; | ||
use App\Models\User; | ||
use App\Models\Voucher; | ||
use App\Models\VoucherSet; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AuditItem> | ||
*/ | ||
class AuditItemFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
$num = rand(0, 3); | ||
|
||
// If $num == 0, stays as user | ||
$auditable = User::factory()->createQuietly(); | ||
|
||
if ($num === 1) { | ||
$auditable = Team::factory()->createQuietly(); | ||
} | ||
|
||
if ($num === 2) { | ||
$auditable = Voucher::factory()->createQuietly(); | ||
} | ||
|
||
if ($num === 3) { | ||
$auditable = VoucherSet::factory()->createQuietly(); | ||
} | ||
|
||
return [ | ||
'auditable_type' => get_class($auditable), | ||
'auditable_id' => $auditable->id, | ||
'auditable_text' => $this->faker->randomElement(['created', 'updated', 'deleted']), | ||
'team_id' => $this->faker->randomDigitNotNull(), | ||
]; | ||
} | ||
} |
Oops, something went wrong.