Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
PromptWritingGoalController
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 index
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 show
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 store
100.00% covered (success)
100.00%
4 / 4
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
 destroy
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Controllers\v2\Admin;
4
5use App\Http\Controllers\Controller;
6use App\Http\Models\PromptWritingGoal;
7use App\Http\Requests\v2\PromptWritingGoal\DestroyPromptWritingGoalRequest;
8use App\Http\Requests\v2\PromptWritingGoal\IndexPromptWritingGoalRequest;
9use App\Http\Requests\v2\PromptWritingGoal\ShowPromptWritingGoalRequest;
10use App\Http\Requests\v2\PromptWritingGoal\StorePromptWritingGoalRequest;
11use App\Http\Requests\v2\PromptWritingGoal\UpdatePromptWritingGoalRequest;
12use App\Http\Resources\v2\PromptWritingGoalResource;
13use App\Http\Services\PromptWritingGoalService;
14use Illuminate\Http\JsonResponse;
15use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
16
17/**
18 * Controller for managing prompt writing goal configurations.
19 *
20 * Only accessible by users with the VENGRESO_ADMIN role.
21 * Provides CRUD operations for the prompt_writing_goal collection,
22 * which stores writing goal options used by engage and post AI features.
23 */
24class PromptWritingGoalController extends Controller
25{
26    public function __construct(
27        private PromptWritingGoalService $promptWritingGoalService
28    ) {}
29
30    /**
31     * Get all prompt writing goals.
32     *
33     * @param  IndexPromptWritingGoalRequest  $request  Validated request (authorization only)
34     *
35     * @response 200 {
36     *   "result": {
37     *     "data": [
38     *       {
39     *         "id": "684c1ce8dca2c6351807ec23",
40     *         "title": "Thought Leadership",
41     *         "description": "Establish authority in your field.",
42     *         "prompt": "Write content that positions the author as a thought leader...",
43     *         "created_at": 1718278600,
44     *         "updated_at": 1718278600
45     *       }
46     *     ]
47     *   }
48     * }
49     */
50    public function index(IndexPromptWritingGoalRequest $request): AnonymousResourceCollection
51    {
52        $goals = $this->promptWritingGoalService->getAll();
53
54        return PromptWritingGoalResource::collection($goals);
55    }
56
57    /**
58     * Get a single prompt writing goal by ID.
59     *
60     * @param  ShowPromptWritingGoalRequest  $request  Validated request (authorization only)
61     * @param  PromptWritingGoal  $promptWritingGoal  The goal to retrieve (route model binding)
62     */
63    public function show(ShowPromptWritingGoalRequest $request, PromptWritingGoal $promptWritingGoal): PromptWritingGoalResource
64    {
65        return new PromptWritingGoalResource($promptWritingGoal);
66    }
67
68    /**
69     * Create a new prompt writing goal.
70     *
71     * @param  StorePromptWritingGoalRequest  $request  Validated request with goal data
72     */
73    public function store(StorePromptWritingGoalRequest $request): JsonResponse
74    {
75        $goal = $this->promptWritingGoalService->create($request->validated());
76
77        return (new PromptWritingGoalResource($goal))
78            ->response()
79            ->setStatusCode(201);
80    }
81
82    /**
83     * Update an existing prompt writing goal.
84     *
85     * @param  UpdatePromptWritingGoalRequest  $request  Validated request with update data
86     * @param  PromptWritingGoal  $promptWritingGoal  The goal to update (route model binding)
87     */
88    public function update(UpdatePromptWritingGoalRequest $request, PromptWritingGoal $promptWritingGoal): PromptWritingGoalResource
89    {
90        $goal = $this->promptWritingGoalService->update($promptWritingGoal, $request->validated());
91
92        return new PromptWritingGoalResource($goal);
93    }
94
95    /**
96     * Delete a prompt writing goal.
97     *
98     * @param  DestroyPromptWritingGoalRequest  $request  Validated request (authorization only)
99     * @param  PromptWritingGoal  $promptWritingGoal  The goal to delete (route model binding)
100     *
101     * @response 204 No content
102     */
103    public function destroy(DestroyPromptWritingGoalRequest $request, PromptWritingGoal $promptWritingGoal): JsonResponse
104    {
105        $this->promptWritingGoalService->delete($promptWritingGoal);
106
107        return response()->json(null, 204);
108    }
109}