Initial commit
This commit is contained in:
69
api/app/Models/Event.php
Normal file
69
api/app/Models/Event.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class Event extends Model
|
||||
{
|
||||
protected $hidden = ['upload_password'];
|
||||
|
||||
protected $appends = ['has_password'];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'name',
|
||||
'description',
|
||||
'slug',
|
||||
'google_drive_folder_id',
|
||||
'google_drive_folder_name',
|
||||
'is_active',
|
||||
'upload_start_at',
|
||||
'upload_end_at',
|
||||
'max_file_size_mb',
|
||||
'allowed_extensions',
|
||||
'upload_password',
|
||||
'require_password',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'upload_start_at' => 'datetime',
|
||||
'upload_end_at' => 'datetime',
|
||||
'is_active' => 'boolean',
|
||||
'require_password' => 'boolean',
|
||||
'allowed_extensions' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function getAllowedExtensionsAttribute($value): array
|
||||
{
|
||||
$decoded = $value ? json_decode($value, true) : null;
|
||||
|
||||
return is_array($decoded) ? $decoded : ['mp4', 'mov', 'avi', 'mkv', 'webm'];
|
||||
}
|
||||
|
||||
public function getHasPasswordAttribute(): bool
|
||||
{
|
||||
return ! empty($this->attributes['upload_password'] ?? null);
|
||||
}
|
||||
|
||||
public function setUploadPasswordAttribute(?string $value): void
|
||||
{
|
||||
$this->attributes['upload_password'] = $value ? Hash::make($value) : null;
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function uploads(): HasMany
|
||||
{
|
||||
return $this->hasMany(Upload::class);
|
||||
}
|
||||
}
|
||||
31
api/app/Models/GoogleDriveConnection.php
Normal file
31
api/app/Models/GoogleDriveConnection.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class GoogleDriveConnection extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'access_token',
|
||||
'refresh_token',
|
||||
'token_expires_at',
|
||||
'account_email',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'token_expires_at' => 'datetime',
|
||||
'access_token' => 'encrypted',
|
||||
'refresh_token' => 'encrypted',
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
38
api/app/Models/Upload.php
Normal file
38
api/app/Models/Upload.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Upload extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'event_id',
|
||||
'original_filename',
|
||||
'stored_filename',
|
||||
'file_size',
|
||||
'mime_type',
|
||||
'google_drive_file_id',
|
||||
'google_drive_web_link',
|
||||
'status',
|
||||
'error_message',
|
||||
'uploader_name',
|
||||
'uploader_email',
|
||||
'upload_started_at',
|
||||
'upload_completed_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'upload_started_at' => 'datetime',
|
||||
'upload_completed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
}
|
||||
59
api/app/Models/User.php
Normal file
59
api/app/Models/User.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
public function googleDriveConnections(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(GoogleDriveConnection::class);
|
||||
}
|
||||
|
||||
public function events(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Event::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user