Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
Converts the AlbumFunctions class into a service (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
hermzz authored and ildyria committed Jan 30, 2019
1 parent 7f5c40a commit 6d8444b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
18 changes: 13 additions & 5 deletions app/Http/Controllers/AlbumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@
use Symfony\Component\HttpFoundation\StreamedResponse;
use ZipStream\ZipStream;


class AlbumController extends Controller
{
/**
* @var AlbumFunctions
*/
private $albumFunctions;

/**
* @param AlbumFunctions $albumFunctions
*/
public function __construct(AlbumFunctions $albumFunctions)
{
$this->albumFunctions = $albumFunctions;
}
/**
* Add a new Album
*
Expand All @@ -30,14 +41,11 @@ function add(Request $request)
'parent_id' => 'int|nullable'
]);

$album = AlbumFunctions::create($request['title'],$request['parent_id']);
$album = $this->albumFunctions->create($request['title'], $request['parent_id']);

return Response::json($album->id, JSON_NUMERIC_CHECK);

}



/**
* Provided an albumID, returns the album.
*
Expand Down
18 changes: 12 additions & 6 deletions app/Http/Controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ class ImportController extends Controller
*/
private $photoFunctions;

/**
* @var AlbumFunctions
*/
private $albumFunctions;

/**
* Create a new command instance.
*
* @param PhotoFunctions $photoFunctions
* @return void
*/
public function __construct(PhotoFunctions $photoFunctions)
public function __construct(PhotoFunctions $photoFunctions, AlbumFunctions $albumFunctions)
{
$this->photoFunctions = $photoFunctions;
$this->albumFunctions = $albumFunctions;
}

/**
Expand Down Expand Up @@ -129,7 +135,7 @@ public function server(Request $request)

$request->validate([
'path' => 'string|required',
'albumID' => 'string|required'
'albumID' => 'int|required'
]);

return $this->server_exec($request['path'], $request['albumID']);
Expand All @@ -139,14 +145,14 @@ public function server(Request $request)


/**
* @param $path
* @param $albumID
* @param string $path
* @param integer $albumID
* @return boolean|string Returns true when successful.
* Warning: Folder empty or no readable files to process!
* Notice: Import only contained albums!
* @throws \ImagickException
*/
public function server_exec($path, $albumID)
public function server_exec(string $path, integer $albumID)
{

// Parse path
Expand Down Expand Up @@ -199,7 +205,7 @@ public function server_exec($path, $albumID)
// Album creation

// Folder
$album = AlbumFunctions::create(basename($file), $albumID);
$album = $this->albumFunctions->create(basename($file), $albumID);
// this actually should not fail.
if ($album === false) {
$error = true;
Expand Down
8 changes: 6 additions & 2 deletions app/ModelFunctions/AlbumFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

class AlbumFunctions
{

public static function create($title, $parent_id)
/**
* @param string $title
* @param int $parent_id
* @return Album
*/
public function create(string $title, $parent_id) : Album
{
$num = Album::where('id', '=', $parent_id)->count();
// id cannot be 0, so by definition if $parent_id is 0 then...
Expand Down
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use App\ModelFunctions\AlbumFunctions;
use App\ModelFunctions\PhotoFunctions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
Expand All @@ -10,6 +11,7 @@
class AppServiceProvider extends ServiceProvider
{
public $singletons = [
AlbumFunctions::class => AlbumFunctions::class,
PhotoFunctions::class => PhotoFunctions::class
];

Expand Down

0 comments on commit 6d8444b

Please sign in to comment.