Skip to content

Commit

Permalink
Added custom scribe theme (scalar)
Browse files Browse the repository at this point in the history
Added file upload to alerts
Updated API
Fixed Unsplash URL
Added utm source to env
Added login url to emails.php
Fixed sendLink in ForgotPassword.php
  • Loading branch information
RealZone22 committed Dec 30, 2023
1 parent 3df72d4 commit e38ada9
Show file tree
Hide file tree
Showing 57 changed files with 2,552 additions and 23,239 deletions.
172 changes: 172 additions & 0 deletions app/Http/Controllers/API/Admin/Alerts/AdminAlertAPIController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php

namespace App\Http\Controllers\API\Admin\Alerts;

use App\Http\Controllers\Controller;
use App\Models\Alert;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Knuckles\Scribe\Attributes\Authenticated;
use Knuckles\Scribe\Attributes\BodyParam;
use Knuckles\Scribe\Attributes\Group;
use Knuckles\Scribe\Attributes\Subgroup;

#[Group("Admin", "Admin Management")]
#[Subgroup("Alerts", "Manage Alerts")]
#[Authenticated]
class AdminAlertAPIController extends Controller
{

public function getAllAlerts()
{
return Alert::all();
}

public function getAlert($alertId)
{
return Alert::find($alertId);
}

#[BodyParam("title", description: "Title of the alert", example: "New Update")]
#[BodyParam("type", description: "Type of the alert", example: "info", enum: ["info", "warning", "update", "important"])]
#[BodyParam("icon", description: "Icon of the alert (See lucide.dev)", example: "icon-bell")]
#[BodyParam("message", description: "Message of the alert", required: false, example: "**I support markdown**")]
#[BodyParam("files", description: "Files attached to the alert", required: false, example: "file.txt")]
public function createAlert(Request $request)
{
$this->validate($request, [
'title' => 'required|string',
'type' => 'required|string|in:info,warning,update,important',
'icon' => 'required|string',
'message' => 'nullable|string',
'files' => 'nullable|array|file',
]);

$alert = new Alert();
$alert->title = $request->input('title');
$alert->type = $request->input('type');
$alert->icon = $request->input('icon');
if ($request->input('message')) {
$alert->message = $request->input('message');
}

try {
$alert->save();
} catch (Exception $e) {
return response()->json([
'message' => 'Failed to create alert',
'errors' => [
'alert' => $e->getMessage(),
],
], 500);
}

if ($request->hasFile('files')) {
$files = $request->file('files');
foreach ($files as $file) {
Storage::disk('public')->putFileAs('alerts/' . $alert->id, $file, $file->getClientOriginalName());
}
}

activity('system')
->performedOn($alert)
->causedBy(auth()->user())
->withProperty('name', $alert->title . ' (' . $alert->type . ')')
->withProperty('ip', request()->ip())
->log('alert.created');

return $alert;
}

#[BodyParam("title", description: "Title of the alert", required: false, example: "New Update")]
#[BodyParam("type", description: "Type of the alert", required: false, example: "info", enum: ["info", "warning", "update", "important"])]
#[BodyParam("icon", description: "Icon of the alert (See lucide.dev)", required: false, example: "icon-bell")]
#[BodyParam("message", description: "Message of the alert", required: false, example: "**I support markdown**")]
#[BodyParam("files", description: "Files attached to the alert", required: false, example: "file.txt")]
public function updateAlert($alertId, Request $request)
{
$alert = Alert::find($alertId);
if (!$alert) {
return response()->json([
'message' => 'Alert not found'
], 404);
}

$this->validate($request, [
'title' => 'nullable|string',
'type' => 'nullable|string|in:info,warning,update,important',
'icon' => 'nullable|string',
'message' => 'nullable|string',
'files' => 'nullable|array|file',
]);

if ($request->input('title')) $alert->title = $request->input('title');
if ($request->input('type')) $alert->type = $request->input('type');
if ($request->input('icon')) $alert->icon = $request->input('icon');
if ($request->input('message')) $alert->message = $request->input('message');

try {
$alert->save();
} catch (Exception $e) {
return response()->json([
'message' => 'Failed to update alert',
'errors' => [
'alert' => $e->getMessage(),
],
], 500);
}

if ($request->hasFile('files')) {
$files = $request->file('files');
Storage::disk('public')->deleteDirectory('alerts/' . $alert->id);
foreach ($files as $file) {
Storage::disk('public')->putFileAs('alerts/' . $alert->id, $file, $file->getClientOriginalName());
}
}

activity('system')
->performedOn($alert)
->causedBy(auth()->user())
->withProperty('name', $alert->title . ' (' . $alert->type . ')')
->withProperty('ip', request()->ip())
->log('alert.updated');

return $alert;
}

public function deleteAlert($alertId)
{
$alert = Alert::find($alertId);
if (!$alert) {
return response()->json([
'message' => 'Alert not found'
], 404);
}

try {
$alert->delete();
} catch (Exception $e) {
return response()->json([
'message' => 'Failed to delete alert',
'errors' => [
'alert' => $e->getMessage(),
],
], 500);
}

Storage::disk('public')->deleteDirectory('alerts/' . $alert->id);

activity('system')
->performedOn($alert)
->causedBy(auth()->user())
->withProperty('name', $alert->title . ' (' . $alert->type . ')')
->withProperty('ip', request()->ip())
->log('alert.deleted');

return response()->json([
'message' => 'Alert deleted'
]);
}

}
77 changes: 61 additions & 16 deletions app/Http/Controllers/API/Admin/Roles/AdminRoleAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\Controller;
use App\Models\User;
use Exception;
use Illuminate\Http\Request;
use Knuckles\Scribe\Attributes\Authenticated;
use Knuckles\Scribe\Attributes\BodyParam;
Expand All @@ -28,11 +29,52 @@ public function getRole($userId)
return Role::find($userId);
}

#[BodyParam("name", description: "Name of the role", example: "Super Admin")]
#[BodyParam("guard_name", description: "Guard name of the role", example: "web")]
#[BodyParam("permissions", description: "Permissions of the role", example: "['create user']")]
public function createRole(Request $request)
{

$this->validate($request, [
'name' => 'required|string',
'guard_name' => 'required|string',
'permissions' => 'nullable|array',
]);

$role = new Role();
$role->name = $request->input('name');
$role->guard_name = $request->input('guard_name');

try {
$role->save();
} catch (Exception $e) {
return response()->json([
'message' => 'Failed to create role',
'errors' => [
'role' => $e->getMessage(),
],
], 500);
}

if ($request->input('permissions')) {
$role->syncPermissions($request->input('permissions'));
}

return $role;
}

#[BodyParam("name", description: "Name of the role", required: false, example: "Super Admin")]
#[BodyParam("guard_name", description: "Guard name of the role", required: false, example: "web")]
#[BodyParam("permissions", description: "Permissions of the role", required: false, example: "['create user']")]
public function updateRole($roleId, Request $request)
{

$this->validate($request, [
'name' => 'nullable|string',
'guard_name' => 'nullable|string',
'permissions' => 'nullable|array',
]);

$role = Role::find($roleId);
if (!$role) {
return response()->json([
Expand All @@ -43,23 +85,17 @@ public function updateRole($roleId, Request $request)
if ($request->input('name')) $role->name = $request->input('name');
if ($request->input('guard_name')) $role->guard_name = $request->input('guard_name');

if ($request->input('permissions')) {
$role->syncPermissions($request->input('permissions'));
try {
$role->save();
} catch (Exception $e) {
return response()->json([
'message' => 'Failed to update role',
'errors' => [
'role' => $e->getMessage(),
],
], 500);
}

return $role;
}

#[BodyParam("name", description: "Name of the role", example: "Super Admin")]
#[BodyParam("guard_name", description: "Guard name of the role", example: "web")]
#[BodyParam("permissions", description: "Permissions of the role", example: "['create user']")]
public function createRole(Request $request)
{
$role = new Role();
$role->name = $request->input('name');
$role->guard_name = $request->input('guard_name');
$role->save();

if ($request->input('permissions')) {
$role->syncPermissions($request->input('permissions'));
}
Expand All @@ -76,7 +112,16 @@ public function deleteRole($roleId)
], 404);
}

$role->delete();
try {
$role->delete();
} catch (Exception $e) {
return response()->json([
'message' => 'Failed to delete role',
'errors' => [
'role' => $e->getMessage(),
],
], 500);
}

return response()->json([
'message' => 'Role successfully deleted'
Expand Down
Loading

0 comments on commit e38ada9

Please sign in to comment.