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
PromptLengthOfPostController
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\PromptLengthOfPost;
7use App\Http\Requests\v2\PromptLengthOfPost\DestroyPromptLengthOfPostRequest;
8use App\Http\Requests\v2\PromptLengthOfPost\IndexPromptLengthOfPostRequest;
9use App\Http\Requests\v2\PromptLengthOfPost\ShowPromptLengthOfPostRequest;
10use App\Http\Requests\v2\PromptLengthOfPost\StorePromptLengthOfPostRequest;
11use App\Http\Requests\v2\PromptLengthOfPost\UpdatePromptLengthOfPostRequest;
12use App\Http\Resources\v2\PromptLengthOfPostResource;
13use App\Http\Services\PromptLengthOfPostService;
14use Illuminate\Http\JsonResponse;
15use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
16
17/**
18 * Controller for managing prompt length of post configurations.
19 *
20 * Only accessible by users with the VENGRESO_ADMIN role.
21 * Provides CRUD operations for the prompt_length_of_post collection,
22 * which stores target word count options used by post AI features.
23 */
24class PromptLengthOfPostController extends Controller
25{
26    public function __construct(
27        private PromptLengthOfPostService $promptLengthOfPostService
28    ) {}
29
30    /**
31     * Get all prompt length of posts.
32     *
33     * @param  IndexPromptLengthOfPostRequest  $request  Validated request (authorization only)
34     *
35     * @response 200 {
36     *   "result": {
37     *     "data": [
38     *       {
39     *         "id": "684c1ce8dca2c6351807ec23",
40     *         "name": "Short",
41     *         "prompt": "Keep the post under 100 words.",
42     *         "created_at": 1718278600,
43     *         "updated_at": 1718278600
44     *       }
45     *     ]
46     *   }
47     * }
48     */
49    public function index(IndexPromptLengthOfPostRequest $request): AnonymousResourceCollection
50    {
51        $lengths = $this->promptLengthOfPostService->getAll();
52
53        return PromptLengthOfPostResource::collection($lengths);
54    }
55
56    /**
57     * Get a single prompt length of post by ID.
58     *
59     * @param  ShowPromptLengthOfPostRequest  $request  Validated request (authorization only)
60     * @param  PromptLengthOfPost  $promptLengthOfPost  The length to retrieve (route model binding)
61     */
62    public function show(ShowPromptLengthOfPostRequest $request, PromptLengthOfPost $promptLengthOfPost): PromptLengthOfPostResource
63    {
64        return new PromptLengthOfPostResource($promptLengthOfPost);
65    }
66
67    /**
68     * Create a new prompt length of post.
69     *
70     * @param  StorePromptLengthOfPostRequest  $request  Validated request with length data
71     */
72    public function store(StorePromptLengthOfPostRequest $request): JsonResponse
73    {
74        $length = $this->promptLengthOfPostService->create($request->validated());
75
76        return (new PromptLengthOfPostResource($length))
77            ->response()
78            ->setStatusCode(201);
79    }
80
81    /**
82     * Update an existing prompt length of post.
83     *
84     * @param  UpdatePromptLengthOfPostRequest  $request  Validated request with update data
85     * @param  PromptLengthOfPost  $promptLengthOfPost  The length to update (route model binding)
86     */
87    public function update(UpdatePromptLengthOfPostRequest $request, PromptLengthOfPost $promptLengthOfPost): PromptLengthOfPostResource
88    {
89        $length = $this->promptLengthOfPostService->update($promptLengthOfPost, $request->validated());
90
91        return new PromptLengthOfPostResource($length);
92    }
93
94    /**
95     * Delete a prompt length of post.
96     *
97     * @param  DestroyPromptLengthOfPostRequest  $request  Validated request (authorization only)
98     * @param  PromptLengthOfPost  $promptLengthOfPost  The length to delete (route model binding)
99     *
100     * @response 204 No content
101     */
102    public function destroy(DestroyPromptLengthOfPostRequest $request, PromptLengthOfPost $promptLengthOfPost): JsonResponse
103    {
104        $this->promptLengthOfPostService->delete($promptLengthOfPost);
105
106        return response()->json(null, 204);
107    }
108}