Miguel N
8942623bde
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.
43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?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.");
|
|
|
|
}
|
|
|
|
}
|