ProviderPaymentMethodController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Requests\ProviderPaymentMethodRequest;
  4. use App\Http\Resources\ProviderPaymentMethodResource;
  5. use App\Services\ProviderPaymentMethodService;
  6. use Illuminate\Http\JsonResponse;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  9. class ProviderPaymentMethodController extends Controller
  10. {
  11. public function __construct(
  12. private readonly ProviderPaymentMethodService $service
  13. ) {}
  14. public function index($id): JsonResponse
  15. {
  16. $paymentMethods = $this->service->getByProvider($id);
  17. return $this->successResponse(
  18. payload: ProviderPaymentMethodResource::collection($paymentMethods)
  19. );
  20. }
  21. public function show(int $id): ProviderPaymentMethodResource
  22. {
  23. $paymentMethod = $this->service->findById($id);
  24. return new ProviderPaymentMethodResource($paymentMethod);
  25. }
  26. public function store(ProviderPaymentMethodRequest $request): JsonResponse
  27. {
  28. $paymentMethod = $this->service->create($request->validated());
  29. return $this->successResponse(
  30. payload: new ProviderPaymentMethodResource($paymentMethod)
  31. );
  32. }
  33. public function update(ProviderPaymentMethodRequest $request, int $id): JsonResponse
  34. {
  35. $paymentMethod = $this->service->findById($id);
  36. $paymentMethod = $this->service->update($paymentMethod, $request->validated());
  37. return $this->successResponse(
  38. payload: new ProviderPaymentMethodResource($paymentMethod)
  39. );
  40. }
  41. public function destroy(int $id): JsonResponse
  42. {
  43. $paymentMethod = $this->service->findById($id);
  44. $this->service->delete($paymentMethod);
  45. return $this->successResponse(
  46. message: __("messages.deleted"),
  47. code: 204,
  48. );
  49. }
  50. }