add api calculator
Tests & Lint & Deploy to Railway / deploy (push) Blocked by required conditions Details
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Has been cancelled Details

This commit is contained in:
aslan 2024-03-07 13:58:54 +03:00
parent cc89ecabe8
commit 19b075c755
2 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,38 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Direction;
use App\Models\EntranceExamination;
use Illuminate\Http\Request;
use function _PHPStan_cc8d35ffb\React\Promise\map;
class CalculatorController extends Controller
{
public function findDirectionFromSubjects(Request $request)
{
$getsSubjects = $request->input();
$countUserSubjects = count($getsSubjects);
// $entranceExamination = EntranceExamination::all()
// ->whereIn('subject_id', $result)
// ->where('subject_type_id','=',1)
// ->select('subject_id','direction_id')
// ->whereIn('subject_id', $result)
// ->groupBy('direction_id')
// ->toArray();
// dd($entranceExamination);
// $directions = Direction::all();
$findIds = EntranceExamination::all()
->select("direction_id", "subject_id")
->groupBy('direction_id')
->map(function ($direction) {
return $direction->map(fn($item) => $item['subject_id']);
})
->filter(fn ($direction) => count($direction) <= $countUserSubjects)
->keys();
$directions = Direction::whereIn('id', $findIds)->get();
return response()->json($directions);
}
}

View File

@ -1,6 +1,7 @@
<?php <?php
use App\Http\Controllers\admin\PageController; use App\Http\Controllers\admin\PageController;
use App\Http\Controllers\Api\CalculatorController;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
@ -19,4 +20,4 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user(); return $request->user();
}); });
Route::post('/calc', [PageController::class, 'calculator'])->name('calculator'); Route::post('/calculator', [CalculatorController::class, 'findDirectionFromSubjects'])->name('calculator');