update controllers logic

This commit is contained in:
root
2026-04-23 00:04:35 -04:00
parent 1977a513df
commit ca4ba272fc
353 changed files with 13402 additions and 1301 deletions
@@ -2,7 +2,7 @@
namespace App\Http\Controllers\Api\Grading;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Controllers\Api\Core\BaseApiController;
use App\Http\Requests\Grading\BelowSixtyEmailRequest;
use App\Http\Requests\Grading\BelowSixtyMeetingRequest;
use App\Http\Requests\Grading\BelowSixtyMeetingSaveRequest;
@@ -79,20 +79,30 @@ class GradingController extends BaseApiController
public function update(GradingScoreUpdateRequest $request): JsonResponse
{
$userId = $this->authenticatedUserIdOrUnauthorized();
if ($userId instanceof JsonResponse) {
return $userId;
}
$payload = $request->validated();
$this->scoreService->update($payload, (int) (auth()->id() ?? 0));
$this->scoreService->update($payload, $userId);
return response()->json(['ok' => true]);
}
public function toggleLock(GradingLockRequest $request): JsonResponse
{
$userId = $this->authenticatedUserIdOrUnauthorized();
if ($userId instanceof JsonResponse) {
return $userId;
}
$payload = $request->validated();
$locked = $this->lockService->toggle(
(int) $payload['class_section_id'],
(string) $payload['semester'],
(string) $payload['school_year'],
(int) (auth()->id() ?? 0)
$userId
);
return response()->json(['ok' => true, 'locked' => $locked]);
@@ -100,11 +110,16 @@ class GradingController extends BaseApiController
public function lockAll(GradingLockAllRequest $request): JsonResponse
{
$userId = $this->authenticatedUserIdOrUnauthorized();
if ($userId instanceof JsonResponse) {
return $userId;
}
$payload = $request->validated();
$count = $this->lockService->lockAll(
(string) $payload['semester'],
(string) $payload['school_year'],
(int) (auth()->id() ?? 0)
$userId
);
return response()->json(['ok' => true, 'locked_count' => $count]);
@@ -137,12 +152,17 @@ class GradingController extends BaseApiController
public function updatePlacementLevel(PlacementLevelRequest $request): JsonResponse
{
$userId = $this->authenticatedUserIdOrUnauthorized();
if ($userId instanceof JsonResponse) {
return $userId;
}
$payload = $request->validated();
$this->placementService->updatePlacementLevel(
(int) $payload['student_id'],
(string) $payload['school_year'],
$payload['placement_level'] ?? null,
(int) (auth()->id() ?? 0)
$userId
);
return response()->json(['ok' => true]);
@@ -150,12 +170,17 @@ class GradingController extends BaseApiController
public function updatePlacementLevels(PlacementLevelsRequest $request): JsonResponse
{
$userId = $this->authenticatedUserIdOrUnauthorized();
if ($userId instanceof JsonResponse) {
return $userId;
}
$payload = $request->validated();
$this->placementService->updatePlacementLevels(
(int) $payload['class_section_id'],
(string) $payload['school_year'],
$payload['placement_level'] ?? [],
(int) (auth()->id() ?? 0)
$userId
);
return response()->json(['ok' => true]);
@@ -163,12 +188,17 @@ class GradingController extends BaseApiController
public function createPlacementBatch(PlacementBatchRequest $request): JsonResponse
{
$userId = $this->authenticatedUserIdOrUnauthorized();
if ($userId instanceof JsonResponse) {
return $userId;
}
$payload = $request->validated();
$batchId = $this->placementService->createPlacementBatch(
(string) $payload['school_year'],
(string) $payload['placement_test'],
$payload['placement_level'] ?? [],
(int) (auth()->id() ?? 0)
$userId
);
return response()->json(['ok' => true, 'batch_id' => $batchId]);
@@ -183,12 +213,17 @@ class GradingController extends BaseApiController
public function updatePlacementBatch(PlacementBatchUpdateRequest $request, int $batchId): JsonResponse
{
$userId = $this->authenticatedUserIdOrUnauthorized();
if ($userId instanceof JsonResponse) {
return $userId;
}
$payload = $request->validated();
$this->placementService->updatePlacementBatch(
$batchId,
(string) $payload['school_year'],
$payload['placement_level'] ?? [],
(int) (auth()->id() ?? 0)
$userId
);
return response()->json(['ok' => true]);
@@ -246,6 +281,11 @@ class GradingController extends BaseApiController
public function updateBelowSixtyStatus(BelowSixtyStatusRequest $request): JsonResponse
{
$userId = $this->authenticatedUserIdOrUnauthorized();
if ($userId instanceof JsonResponse) {
return $userId;
}
$payload = $request->validated();
$this->belowSixtyService->updateStatus(
(int) $payload['student_id'],
@@ -253,7 +293,7 @@ class GradingController extends BaseApiController
(string) $payload['school_year'],
(string) $payload['status'],
(string) ($payload['note'] ?? ''),
(int) (auth()->id() ?? 0)
$userId
);
return response()->json(['ok' => true]);
@@ -273,9 +313,27 @@ class GradingController extends BaseApiController
public function saveBelowSixtyMeeting(BelowSixtyMeetingSaveRequest $request): JsonResponse
{
$userId = $this->authenticatedUserIdOrUnauthorized();
if ($userId instanceof JsonResponse) {
return $userId;
}
$payload = $request->validated();
$this->belowSixtyService->saveMeeting($payload, (int) (auth()->id() ?? 0));
$this->belowSixtyService->saveMeeting($payload, $userId);
return response()->json(['ok' => true]);
}
/**
* @return int|JsonResponse
*/
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
if ($userId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
return $userId;
}
}
@@ -2,7 +2,7 @@
namespace App\Http\Controllers\Api\Grading;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Controllers\Api\Core\BaseApiController;
use App\Http\Requests\Grading\HomeworkTrackingRequest;
use App\Http\Resources\Grading\HomeworkTrackingTeacherResource;
use App\Services\Grading\HomeworkTrackingService;