9d2b63c8f4
SyncController now handles the full mutation vocabulary: - inspection.create (idempotent by uuid; project/layer derived from feature; authz member + 'create inspections'; status defaults to completed). - issue.create (idempotent; authz member + 'create issues'). - issue.update (by server id; authz member + 'edit issues'; sets resolved_at when resolved/closed; last-write-wins conflict). - feature.update (by server id; authz member + 'update progress'; recomputes phase progress; last-write-wins conflict). - Conflict detection: client_updated_at vs server updated_at → returns 'conflict' with the current server value. Added uuid + client_updated_at to features/inspections/issues (guarded migration) and their fillables. Tests: 16 passing (added inspection/issue/feature + conflict). Note: 2 PRE-EXISTING test failures remain (not from this work, sqlite-only): ExampleTest expects '/'=200 (app redirects), and the dashboard route uses MySQL FIELD() which sqlite lacks. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use App\Traits\LogsActivity;
|
|
|
|
class Feature extends Model
|
|
{
|
|
use SoftDeletes, LogsActivity;
|
|
|
|
const STATUSES = ['planned', 'started', 'in_progress', 'completed', 'verified'];
|
|
|
|
protected $fillable = [
|
|
'layer_id', 'name', 'geometry', 'properties', 'template_id',
|
|
'progress', 'status', 'responsible', 'responsible_user_id',
|
|
'uuid', 'client_updated_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'geometry' => 'array',
|
|
'properties' => 'array',
|
|
];
|
|
|
|
public function layer()
|
|
{
|
|
return $this->belongsTo(Layer::class);
|
|
}
|
|
|
|
public function template()
|
|
{
|
|
return $this->belongsTo(InspectionTemplate::class);
|
|
}
|
|
|
|
public function inspections()
|
|
{
|
|
return $this->hasMany(Inspection::class, 'feature_id');
|
|
}
|
|
|
|
public function issues()
|
|
{
|
|
return $this->hasMany(Issue::class);
|
|
}
|
|
|
|
public function responsibleUser()
|
|
{
|
|
return $this->belongsTo(User::class, 'responsible_user_id');
|
|
}
|
|
|
|
public function media()
|
|
{
|
|
return $this->morphMany(Media::class, 'mediable');
|
|
}
|
|
|
|
public function images()
|
|
{
|
|
return $this->morphMany(Media::class, 'mediable')->where('category', 'image');
|
|
}
|
|
|
|
public function getStatusColorAttribute(): string
|
|
{
|
|
return match($this->status) {
|
|
'planned' => '#6b7280',
|
|
'started' => '#3b82f6',
|
|
'in_progress' => '#f59e0b',
|
|
'completed' => '#10b981',
|
|
'verified' => '#8b5cf6',
|
|
default => '#6b7280',
|
|
};
|
|
}
|
|
}
|