add controllers, servoices
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Finance;
|
||||
|
||||
use App\Http\Controllers\Api\BaseApiController;
|
||||
use App\Http\Requests\Payments\PaymentEventChargesListRequest;
|
||||
use App\Http\Requests\Payments\PaymentEventChargesStoreRequest;
|
||||
use App\Services\Payments\PaymentEventChargesService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class PaymentEventChargesController extends BaseApiController
|
||||
{
|
||||
public function __construct(private PaymentEventChargesService $service)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index(PaymentEventChargesListRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$data = $this->service->listCharges($payload['school_year'] ?? null, $payload['semester'] ?? null);
|
||||
|
||||
return response()->json(['ok' => true] + $data);
|
||||
}
|
||||
|
||||
public function store(PaymentEventChargesStoreRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
$count = $this->service->addCharges($payload, $userId);
|
||||
if ($count === 0) {
|
||||
return response()->json(['ok' => false, 'message' => 'No student selected.'], 422);
|
||||
}
|
||||
|
||||
return response()->json(['ok' => true, 'inserted' => $count]);
|
||||
}
|
||||
|
||||
public function enrolledStudents(PaymentEventChargesListRequest $request, int $parentId): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$students = $this->service->getEnrolledStudents($parentId, $payload['school_year'] ?? null);
|
||||
|
||||
return response()->json(['ok' => true, 'students' => $students]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user