mdn-backend / app /Domain /Files /FileRepository.php
internationalscholarsprogram's picture
feat(membership): admin-driven account creation, real estate tier/investment work, in-progress monorepo migration state
b2dcf0f
Raw
History Blame Contribute Delete
1.25 kB
<?php
namespace App\Domain\Files;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use stdClass;
class FileRepository
{
public function create(array $attributes): string
{
$now = Carbon::now();
DB::table('stored_files')->insert(array_merge($attributes, [
'created_at' => $now,
'updated_at' => $now,
]));
return $attributes['id'];
}
public function find(string $id, bool $includeDeleted = false): ?stdClass
{
$query = DB::table('stored_files')->where('id', $id);
if (! $includeDeleted) {
$query->whereNull('deleted_at');
}
return $query->first();
}
public function archive(string $id): void
{
DB::table('stored_files')->where('id', $id)->whereNull('deleted_at')->update([
'archived_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
}
public function softDelete(string $id): void
{
DB::table('stored_files')->where('id', $id)->whereNull('deleted_at')->update([
'deleted_from_storage_at' => Carbon::now(),
'deleted_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
}
}