| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Http\Controllers;
- use App\Http\Requests\ClientRequest;
- use App\Http\Resources\ClientResource;
- use App\Services\ClientService;
- use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
- use Illuminate\Http\JsonResponse;
- class ClientController extends Controller
- {
- // protected ClientService $clientService;
- // public function __construct(ClientService $clientService)
- // {
- // $this->clientService = $clientService;
- // }
- // public function index(): AnonymousResourceCollection
- // {
- // $clients = $this->clientService->getAll();
- // return ClientResource::collection($clients);
- // }
- // public function store(ClientRequest $request): ClientResource
- // {
- // $client = $this->clientService->create($request->validated());
- // return new ClientResource($client->load('user'));
- // }
- // public function show(string $id): ClientResource
- // {
- // $client = $this->clientService->findById($id);
- // return new ClientResource($client);
- // }
- // public function update(ClientRequest $request, string $id): JsonResponse
- // {
- // $this->clientService->update($request->validated(), $id);
- // return response()->json(['message' => 'Client updated successfully']);
- // }
- // public function destroy(string $id): JsonResponse
- // {
- // $this->clientService->delete($id);
- // return response()->json(['message' => 'Client deleted successfully']);
- // }
- public function __construct(protected ClientService $service) {}
- public function index(): JsonResponse
- {
- $items = $this->service->getAll();
- return $this->successResponse(
- payload: ClientResource::collection($items),
- );
- }
- public function store(ClientRequest $request): JsonResponse
- {
- $item = $this->service->create($request->validated());
- return $this->successResponse(
- payload: new ClientResource($item),
- message: __("messages.created"),
- code: 201,
- );
- }
- public function show(int $id): JsonResponse
- {
- $item = $this->service->findById($id);
- return $this->successResponse(payload: new ClientResource($item));
- }
- public function update(ClientRequest $request, int $id): JsonResponse
- {
- $item = $this->service->update($request->validated(), $id);
- return $this->successResponse(
- payload: new ClientResource($item),
- message: __("messages.updated"),
- );
- }
- public function destroy(int $id): JsonResponse
- {
- $this->service->delete($id);
- return $this->successResponse(
- message: __("messages.deleted"),
- code: 204,
- );
- }
- }
|