refactor: Remove extensive unused administrative UI, styling, and JavaScript assets, and introduce a new payment API controller.
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Payment;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\PaymentRequest;
|
||||
use App\Models\Payment;
|
||||
use App\Repositories\Payment\PaymentReppositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PaymentReppositoryInterface $paymentRepository
|
||||
) {}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$payments = $this->paymentRepository->filter($request->all());
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $payments
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(PaymentRequest $request): JsonResponse
|
||||
{
|
||||
$request->validated();
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$payment = $this->paymentRepository->create($request->all());
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Payment method created successfully',
|
||||
'data' => $payment
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$payment = $this->paymentRepository->find($id);
|
||||
|
||||
if (!$payment) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => "Can't find payment method by ID #" . $id
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $payment
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(int $id, PaymentRequest $request): JsonResponse
|
||||
{
|
||||
$payment = $this->paymentRepository->find($id);
|
||||
|
||||
if (!$payment) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => "Can't find payment method by ID #" . $id
|
||||
], 404);
|
||||
}
|
||||
|
||||
$request->validated();
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$this->paymentRepository->update($id, $request->all());
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Payment method updated successfully',
|
||||
'data' => $this->paymentRepository->find($id)
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$payment = $this->paymentRepository->find($id);
|
||||
|
||||
if (!$payment) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => "Can't find payment method by ID #" . $id
|
||||
], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$this->paymentRepository->delete($id);
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Payment method deleted successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user