Added services
This commit moves most controller logic onto Services. Services are part of the Service-Repository pattern. The models act as repositories. Services are easily testable and are needed for the upcoming API, in order to avoid duplicated code and to maintain a single source of "truth". The User, Vacancy and Vote controllers still need their logic moved onto services.
This commit is contained in:
42
app/Services/TeamFileService.php
Normal file
42
app/Services/TeamFileService.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Exceptions\FileUploadException;
|
||||
use App\TeamFile;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class TeamFileService
|
||||
{
|
||||
|
||||
public function addFile(UploadedFile $upload, $uploader, $team, $caption, $description) {
|
||||
|
||||
$file = $upload->store('uploads');
|
||||
$originalFileName = $upload->getClientOriginalName();
|
||||
$originalFileExtension = $upload->extension();
|
||||
$originalFileSize = $upload->getSize();
|
||||
|
||||
$fileEntry = TeamFile::create([
|
||||
'uploaded_by' => $uploader,
|
||||
'team_id' => $team,
|
||||
'name' => $originalFileName,
|
||||
'caption' => $caption,
|
||||
'description' => $description,
|
||||
'fs_location' => $file,
|
||||
'extension' => $originalFileExtension,
|
||||
'size' => $originalFileSize
|
||||
]);
|
||||
|
||||
if ($fileEntry && !is_bool($file))
|
||||
{
|
||||
return $fileEntry;
|
||||
}
|
||||
|
||||
throw new FileUploadException("There was an unknown error whilst trying to upload your file.");
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user