REFACTORING: move creating directories into repository
This commit is contained in:
@@ -31,22 +31,13 @@ class CreateDirectory implements Interaction
|
|||||||
{
|
{
|
||||||
$data['parentDirectory'] = isset($data['parentDirectory']) ? $data['parentDirectory'] : null;
|
$data['parentDirectory'] = isset($data['parentDirectory']) ? $data['parentDirectory'] : null;
|
||||||
|
|
||||||
// todo this should probably go into validation, but we are not able to get $data in getValidationRules
|
|
||||||
// check if created folder does not exist in current directory
|
// check if created folder does not exist in current directory
|
||||||
if ($this->repository->checkIfNameExists($data['name'], $data['parentDirectory'])) {
|
if ($this->repository->checkIfNameExists($data['name'], $data['parentDirectory'])) {
|
||||||
throw new SubdirectoryExistsInDirectory();
|
throw new SubdirectoryExistsInDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo use Directory::create() and rename columns/fields in request
|
|
||||||
// create new database entry
|
// create new database entry
|
||||||
$directory = new Directory();
|
return $this->repository->create($data);
|
||||||
$directory->name = $data['name'];
|
|
||||||
$directory->parent_id = $data['parentDirectory'];
|
|
||||||
$directory->user_id = \Auth::user()->id;
|
|
||||||
$directory->description = $data['description'];
|
|
||||||
$directory->save();
|
|
||||||
|
|
||||||
return $directory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\CMS\Repositories\FileManager;
|
namespace App\CMS\Repositories\FileManager;
|
||||||
|
|
||||||
use App\CMS\Helpers\RootDirectory;
|
use App\CMS\Helpers\RootDirectory;
|
||||||
@@ -25,7 +26,33 @@ class Directory
|
|||||||
return $exists->exists();
|
return $exists->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(DirectoryModel $directory, $data) {
|
/**
|
||||||
|
* Create new directory
|
||||||
|
*
|
||||||
|
* @param $data
|
||||||
|
*
|
||||||
|
* @return DirectoryModel
|
||||||
|
*/
|
||||||
|
public function create($data)
|
||||||
|
{
|
||||||
|
$directory = new DirectoryModel();
|
||||||
|
$directory->name = $data['name'];
|
||||||
|
$directory->parent_id = $data['parentDirectory'];
|
||||||
|
$directory->user_id = \Auth::user()->id;
|
||||||
|
$directory->description = $data['description'];
|
||||||
|
$directory->save();
|
||||||
|
|
||||||
|
return $directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update given directory
|
||||||
|
*
|
||||||
|
* @param DirectoryModel $directory
|
||||||
|
* @param $data
|
||||||
|
*/
|
||||||
|
public function update(DirectoryModel $directory, $data)
|
||||||
|
{
|
||||||
$directory->name = $data['name'];
|
$directory->name = $data['name'];
|
||||||
$directory->description = $data['description'];
|
$directory->description = $data['description'];
|
||||||
$directory->save();
|
$directory->save();
|
||||||
|
|||||||
Reference in New Issue
Block a user