Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
5 / 6
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
PromptWritingGoalRepository
83.33% covered (warning)
83.33%
5 / 6
80.00% covered (warning)
80.00%
4 / 5
5.12
0.00% covered (danger)
0.00%
0 / 1
 getAll
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 findById
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 create
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 update
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 delete
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Repositories;
4
5use App\Http\Models\PromptWritingGoal;
6use App\Http\Repositories\interfaces\IPromptWritingGoalRepository;
7use Illuminate\Support\Collection;
8
9/**
10 * Repository for prompt writing goal data access operations.
11 *
12 * Handles all database queries related to prompt writing goals,
13 * keeping data access logic separate from business logic.
14 */
15class PromptWritingGoalRepository implements IPromptWritingGoalRepository
16{
17    /**
18     * Get all prompt writing goals ordered by newest first.
19     *
20     * @return Collection<int, PromptWritingGoal> Collection of goals
21     */
22    public function getAll(): Collection
23    {
24        return PromptWritingGoal::query()->orderBy('created_at', 'desc')->get();
25    }
26
27    /**
28     * Find a prompt writing goal by its ID.
29     *
30     * @param  string  $id  The goal ID
31     * @return PromptWritingGoal|null The goal or null if not found
32     */
33    public function findById(string $id): ?PromptWritingGoal
34    {
35        return PromptWritingGoal::find($id);
36    }
37
38    /**
39     * Create a new prompt writing goal.
40     *
41     * @param  array  $data  The goal data
42     * @return PromptWritingGoal The created goal
43     */
44    public function create(array $data): PromptWritingGoal
45    {
46        return PromptWritingGoal::create($data);
47    }
48
49    /**
50     * Update an existing prompt writing goal.
51     *
52     * @param  PromptWritingGoal  $promptWritingGoal  The goal to update
53     * @param  array  $data  The update data
54     * @return PromptWritingGoal The updated goal
55     */
56    public function update(PromptWritingGoal $promptWritingGoal, array $data): PromptWritingGoal
57    {
58        $promptWritingGoal->update($data);
59
60        return $promptWritingGoal->fresh();
61    }
62
63    /**
64     * Delete a prompt writing goal.
65     *
66     * @param  PromptWritingGoal  $promptWritingGoal  The goal to delete
67     * @return bool True if deleted successfully
68     */
69    public function delete(PromptWritingGoal $promptWritingGoal): bool
70    {
71        return $promptWritingGoal->delete();
72    }
73}