Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
44.44% |
4 / 9 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| AIRequestLogRepository | |
44.44% |
4 / 9 |
|
33.33% |
1 / 3 |
6.74 | |
0.00% |
0 / 1 |
| create | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| updateStatus | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| findByUser | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Repositories; |
| 4 | |
| 5 | use App\Http\Models\FlyMsgAI\AIRequestLog; |
| 6 | |
| 7 | /** |
| 8 | * Data access layer for AI request log records. |
| 9 | */ |
| 10 | class AIRequestLogRepository |
| 11 | { |
| 12 | /** |
| 13 | * Create a new AI request log entry. |
| 14 | * |
| 15 | * @param array<string, mixed> $data Log fields (see AIRequestLog::$fillable) |
| 16 | */ |
| 17 | public function create(array $data): AIRequestLog |
| 18 | { |
| 19 | return AIRequestLog::create($data); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Update the status and optional extra fields of an existing log entry. |
| 24 | * |
| 25 | * @param string $id The log document ID |
| 26 | * @param string $status New status (success | error | pending) |
| 27 | * @param array<string, mixed> $extra Additional fields to update |
| 28 | */ |
| 29 | public function updateStatus(string $id, string $status, array $extra = []): bool |
| 30 | { |
| 31 | $log = AIRequestLog::find($id); |
| 32 | |
| 33 | if (! $log) { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | return $log->update(array_merge(['status' => $status], $extra)); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Find log entries for a specific user, ordered by most recent first. |
| 42 | * |
| 43 | * @return \Illuminate\Database\Eloquent\Collection<int, AIRequestLog> |
| 44 | */ |
| 45 | public function findByUser(string $userId, int $limit = 50): \Illuminate\Database\Eloquent\Collection |
| 46 | { |
| 47 | return AIRequestLog::where('user_id', $userId) |
| 48 | ->orderBy('created_at', 'desc') |
| 49 | ->limit($limit) |
| 50 | ->get(); |
| 51 | } |
| 52 | } |