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