feat: initialisation complète du projet CESIZen
- Backend Laravel 11 (API REST, JWT auth, PostgreSQL) - Frontend Next.js 14 (React, TypeScript, Tailwind CSS) - Docker Compose (PostgreSQL, backend, frontend) - Modules : auth, profil, tracker émotions, informations, admin
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Audit extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'audits';
|
||||
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
protected $fillable = [
|
||||
'utilisateur_id',
|
||||
'action',
|
||||
'table_cible',
|
||||
'enregistrement_id',
|
||||
'anciennes_valeurs',
|
||||
'nouvelles_valeurs',
|
||||
'ip_address',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'anciennes_valeurs' => 'array',
|
||||
'nouvelles_valeurs' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
// ──── Relations ────
|
||||
|
||||
public function utilisateur(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Utilisateur::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ContactUrgence extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'contacts_urgence';
|
||||
|
||||
protected $fillable = [
|
||||
'utilisateur_id',
|
||||
'nom',
|
||||
'telephone',
|
||||
'relation',
|
||||
];
|
||||
|
||||
// ──── Relations ────
|
||||
|
||||
public function utilisateur(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Utilisateur::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Emotion extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'emotions';
|
||||
|
||||
protected $fillable = [
|
||||
'nom',
|
||||
'couleur',
|
||||
'icone',
|
||||
'niveau',
|
||||
'parent_id',
|
||||
'est_actif',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'niveau' => 'integer',
|
||||
'est_actif' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
// ──── Relations ────
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Emotion::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function enfants(): HasMany
|
||||
{
|
||||
return $this->hasMany(Emotion::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function saisieTrackers(): HasMany
|
||||
{
|
||||
return $this->hasMany(SaisieTracker::class);
|
||||
}
|
||||
|
||||
// ──── Scopes ────
|
||||
|
||||
public function scopeActives(Builder $query): Builder
|
||||
{
|
||||
return $query->where('est_actif', true);
|
||||
}
|
||||
|
||||
public function scopeNiveau(Builder $query, int $niveau): Builder
|
||||
{
|
||||
return $query->where('niveau', $niveau);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Feed extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'feeds';
|
||||
|
||||
protected $fillable = [
|
||||
'titre',
|
||||
'slug',
|
||||
'contenu',
|
||||
'image_url',
|
||||
'est_publie',
|
||||
'auteur_id',
|
||||
'ordre',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'est_publie' => 'boolean',
|
||||
'ordre' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
// ──── Relations ────
|
||||
|
||||
public function auteur(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Utilisateur::class, 'auteur_id');
|
||||
}
|
||||
|
||||
// ──── Scopes ────
|
||||
|
||||
public function scopePublie(Builder $query): Builder
|
||||
{
|
||||
return $query->where('est_publie', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'roles';
|
||||
|
||||
protected $fillable = [
|
||||
'nom',
|
||||
'description',
|
||||
];
|
||||
|
||||
public function utilisateurs(): HasMany
|
||||
{
|
||||
return $this->hasMany(Utilisateur::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SaisieTracker extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'saisie_trackers';
|
||||
|
||||
protected $fillable = [
|
||||
'tracker_id',
|
||||
'emotion_id',
|
||||
'intensite',
|
||||
'note',
|
||||
'date_saisie',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'date_saisie' => 'datetime',
|
||||
'intensite' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
// ──── Relations ────
|
||||
|
||||
public function tracker(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Tracker::class);
|
||||
}
|
||||
|
||||
public function emotion(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Emotion::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Tracker extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'trackers';
|
||||
|
||||
protected $fillable = [
|
||||
'utilisateur_id',
|
||||
'nom',
|
||||
];
|
||||
|
||||
// ──── Relations ────
|
||||
|
||||
public function utilisateur(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Utilisateur::class);
|
||||
}
|
||||
|
||||
public function saisies(): HasMany
|
||||
{
|
||||
return $this->hasMany(SaisieTracker::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
|
||||
class Utilisateur extends Authenticatable implements JWTSubject
|
||||
{
|
||||
use HasFactory, Notifiable, SoftDeletes;
|
||||
|
||||
protected $table = 'utilisateurs';
|
||||
|
||||
protected $fillable = [
|
||||
'nom',
|
||||
'prenom',
|
||||
'email',
|
||||
'password',
|
||||
'role_id',
|
||||
'est_actif',
|
||||
'consentement_rgpd',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'est_actif' => 'boolean',
|
||||
'consentement_rgpd' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
// ──── JWTSubject ────
|
||||
|
||||
public function getJWTIdentifier(): mixed
|
||||
{
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
public function getJWTCustomClaims(): array
|
||||
{
|
||||
return [
|
||||
'role' => $this->role->nom,
|
||||
];
|
||||
}
|
||||
|
||||
// ──── Relations ────
|
||||
|
||||
public function role(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Role::class);
|
||||
}
|
||||
|
||||
public function tracker(): HasOne
|
||||
{
|
||||
return $this->hasOne(Tracker::class);
|
||||
}
|
||||
|
||||
public function contactsUrgence(): HasMany
|
||||
{
|
||||
return $this->hasMany(ContactUrgence::class);
|
||||
}
|
||||
|
||||
// ──── Helpers ────
|
||||
|
||||
public function estAdmin(): bool
|
||||
{
|
||||
return $this->role->nom === 'administrateur';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user