Files
wticreatorstudio/Modules/StudioPlus/Repositories/VideoResolutionsRepository.php
Fritz Ramirez 10d0c477c8 Initial commit
2024-02-12 22:54:20 -05:00

110 lines
2.8 KiB
PHP

<?php
namespace Modules\StudioPlus\Repositories;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Modules\StudioPlus\Entities\VideoResolution;
class VideoResolutionsRepository
{
public function getAll()
{
return VideoResolution::get();
}
public function getActive()
{
return VideoResolution::where('status', true)->get();
}
public function store($request): array
{
$width = $request->width;
$height = $request->height;
VideoResolution::create([
'width' => $width,
'height' => $height,
]);
$resolutions = VideoResolution::get();
return [
'data' => [
'message' => 'Video resolution has been saved.',
'resolutions' => $resolutions,
],
'status' => 200,
];
}
public function update($request): array
{
$id = $request->id;
$width = $request->width;
$height = $request->height;
$resolution = VideoResolution::find($id);
if ($resolution) {
$other_resolution = VideoResolution::where('width', $width)->where('height', $height)->where('id', '<>', $id)->first();
if ($other_resolution) {
return [
'data' => [
'message' => 'Video resolution already exists.',
'resolution' => $other_resolution,
],
'status' => 409,
];
}
$resolution->fill($request->all());
$resolution->update();
$resolutions = VideoResolution::get();
return [
'data' => [
'message' => 'Video resolution has been udpated.',
'resolutions' => $resolutions
],
'status' => 200,
];
}
return [
'data' => [
'message' => 'Video resolution not found.',
],
'status' => 404,
];
}
public function destroy($request): array
{
$resolution = VideoResolution::find($request->id);
if ($resolution) {
$resolution->delete();
$resolutions = VideoResolution::get();
return [
'data' => [
'message' => 'Video resolution has been deleted.',
'resolutions' => $resolutions,
],
'status' => 200,
];
}
return [
'data' => [
'message' => 'Vide resolution not found.',
],
'status' => 404,
];
}
}