atcheck/app/Http/Controllers/UserCache.php

42 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class UserCache extends Controller
{
public function delete($classes_code) {
DB::table("usercache")->where("classcode", $classes_code)->delete();
}
public function get($classes_code) {
$object = DB::table("usercache")->where("classcode", $classes_code)->first();
return $object;
}
public function add(Request $request) {
$classes_code = $request->classes_code;
$classes = DB::table("classes")->where("classes_code", $classes_code)->first();
if(is_null($classes)) {
return response()->json(['message' => 'Nie ma takich zajęć'], 400);
} else {
$cache = DB::table("usercache")->where("classcode", $classes_code)->first();
if(!is_null($cache)) {
return response()->json(['message' => 'Użytkownik w cache'], 500);
}
}
DB::table("usercache")->insert([
"name" => $request->student_name,
"surname" => $request->student_surname,
"classcode" => $request->classes_code,
"index" => $request->student_index
]);
return response()->json(['message' => 'ADDED'], 200);
}
}