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