API Feature (#334)

This commit is contained in:
Saeed Vaziry
2024-11-01 16:49:57 +01:00
committed by GitHub
parent da7b24640e
commit 417bf73e44
143 changed files with 36520 additions and 586 deletions

View File

@ -2,6 +2,7 @@
namespace App\Actions\StorageProvider;
use App\Models\Project;
use App\Models\StorageProvider;
use App\Models\User;
use Illuminate\Validation\Rule;
@ -12,13 +13,13 @@ class CreateStorageProvider
/**
* @throws ValidationException
*/
public function create(User $user, array $input): void
public function create(User $user, Project $project, array $input): StorageProvider
{
$storageProvider = new StorageProvider([
'user_id' => $user->id,
'provider' => $input['provider'],
'profile' => $input['name'],
'project_id' => isset($input['global']) && $input['global'] ? null : $user->current_project_id,
'project_id' => isset($input['global']) && $input['global'] ? null : $project->id,
]);
$storageProvider->credentials = $storageProvider->provider()->credentialData($input);
@ -36,6 +37,8 @@ public function create(User $user, array $input): void
}
$storageProvider->save();
return $storageProvider;
}
public static function rules(array $input): array

View File

@ -3,17 +3,16 @@
namespace App\Actions\StorageProvider;
use App\Models\StorageProvider;
use Exception;
use Illuminate\Validation\ValidationException;
class DeleteStorageProvider
{
/**
* @throws Exception
*/
public function delete(StorageProvider $storageProvider): void
{
if ($storageProvider->backups()->exists()) {
throw new Exception('This storage provider is being used by a backup.');
throw ValidationException::withMessages([
'provider' => __('This storage provider is being used by a backup.'),
]);
}
$storageProvider->delete();

View File

@ -2,18 +2,20 @@
namespace App\Actions\StorageProvider;
use App\Models\Project;
use App\Models\StorageProvider;
use App\Models\User;
use Illuminate\Validation\ValidationException;
class EditStorageProvider
{
public function edit(StorageProvider $storageProvider, User $user, array $input): void
public function edit(StorageProvider $storageProvider, Project $project, array $input): StorageProvider
{
$storageProvider->profile = $input['name'];
$storageProvider->project_id = isset($input['global']) && $input['global'] ? null : $user->current_project_id;
$storageProvider->project_id = isset($input['global']) && $input['global'] ? null : $project->id;
$storageProvider->save();
return $storageProvider;
}
/**