forked from magonysandormate/PeePal
Backend frissítve
This commit is contained in:
@@ -13,6 +13,65 @@ class WcController extends Controller
|
|||||||
return response()->json($mosdok);
|
return response()->json($mosdok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$validatedData = $request->validate([
|
||||||
|
'nev' => 'required|string',
|
||||||
|
'kerulet_id' => 'required|integer|exists:keruletek,id',
|
||||||
|
'kozeli_megall' => 'required|string',
|
||||||
|
'akadalym' => 'nullable|boolean',
|
||||||
|
'ar' => 'nullable|numeric',
|
||||||
|
'nyitva' => 'nullable|string',
|
||||||
|
'utvonal' => 'required|string',
|
||||||
|
'koordinatak' => 'required|string',
|
||||||
|
'felhasznalo_id' => 'nullable|numeric'
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$szelesseg = null;
|
||||||
|
$hosszusag = null;
|
||||||
|
|
||||||
|
if (!empty($validatedData['koordinatak'])) {
|
||||||
|
$koordinatak = explode(',', $validatedData['koordinatak']);
|
||||||
|
|
||||||
|
if (count($koordinatak) == 2) {
|
||||||
|
$hosszusag = trim($koordinatak[0]);
|
||||||
|
$szelesseg = trim($koordinatak[1]);
|
||||||
|
|
||||||
|
if (!is_numeric($szelesseg) || !is_numeric($hosszusag)) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Érvénytelen a koordináták formátuma'
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$mosdo = WcAdatok::create([
|
||||||
|
'nev' => $validatedData['nev'],
|
||||||
|
'kerulet_id' => $validatedData['kerulet_id'],
|
||||||
|
'kozeli_megall' => $validatedData['kozeli_megall'],
|
||||||
|
'akadalym' => $validatedData['akadalym'],
|
||||||
|
'ar' => $validatedData['ar'],
|
||||||
|
'nyitva' => $validatedData['nyitva'],
|
||||||
|
'utvonal' => $validatedData['utvonal'],
|
||||||
|
'szel_koord' => $szelesseg,
|
||||||
|
'hossz_koord' => $hosszusag,
|
||||||
|
'felhasznalo_id' => $validatedData['felhasznalo_id']
|
||||||
|
]);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Sikeres rögzítés',
|
||||||
|
'data' => $mosdo
|
||||||
|
], 201);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Hiba történt a mentés során',
|
||||||
|
'error' => $e->getMessage()
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$wc = WcAdatok::find($id);
|
$wc = WcAdatok::find($id);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\HozzaadasController;
|
|
||||||
use App\Http\Controllers\UserController;
|
use App\Http\Controllers\UserController;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
@@ -10,6 +9,6 @@ Route::get('/mosdok', [WcController::class, 'index']);
|
|||||||
|
|
||||||
Route::get('/mosdok/{id}', [WcController::class, 'show']);
|
Route::get('/mosdok/{id}', [WcController::class, 'show']);
|
||||||
|
|
||||||
Route::get('/users', [UserController::class, 'index']);
|
Route::post('/hozzaadas', [WcController::class, 'store']);
|
||||||
|
|
||||||
Route::post('/hozzaadas', [HozzaadasController::class, 'store']);
|
Route::get('/users', [UserController::class, 'index']);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useNavigate } from "react-router-dom";
|
|||||||
|
|
||||||
export default function HozzaadForm() {
|
export default function HozzaadForm() {
|
||||||
const [nev, setNev] = useState("");
|
const [nev, setNev] = useState("");
|
||||||
const [kerulet, setKerulet] = useState("");
|
const [kerulet_id, setKeruletId] = useState("");
|
||||||
const [kozeli_megall, setKozeli] = useState("");
|
const [kozeli_megall, setKozeli] = useState("");
|
||||||
const [akadalym, setAkadalym] = useState(false);
|
const [akadalym, setAkadalym] = useState(false);
|
||||||
const [ar, setAr] = useState("");
|
const [ar, setAr] = useState("");
|
||||||
@@ -17,7 +17,7 @@ export default function HozzaadForm() {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const wcInfo = {
|
const wcInfo = {
|
||||||
nev: nev,
|
nev: nev,
|
||||||
kerulet: kerulet,
|
kerulet_id: kerulet_id,
|
||||||
kozeli_megall: kozeli_megall,
|
kozeli_megall: kozeli_megall,
|
||||||
akadalym: akadalym,
|
akadalym: akadalym,
|
||||||
ar: ar,
|
ar: ar,
|
||||||
@@ -36,7 +36,7 @@ export default function HozzaadForm() {
|
|||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((newWC) => {
|
.then((newWC) => {
|
||||||
setNev("");
|
setNev("");
|
||||||
setKerulet("");
|
setKeruletId("");
|
||||||
setKozeli("");
|
setKozeli("");
|
||||||
setAkadalym(false);
|
setAkadalym(false);
|
||||||
setAr("");
|
setAr("");
|
||||||
@@ -82,10 +82,15 @@ export default function HozzaadForm() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<label className="block text-gray-700">Kerület:</label>
|
<label className="block text-gray-700">Kerület:</label>
|
||||||
|
|
||||||
|
<select name="kerulet_id">
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="kerulet"
|
name="kerulet"
|
||||||
value={kerulet}
|
value={kerulet_id}
|
||||||
onChange={(event) => setKerulet(event.target.value)}
|
onChange={(event) => setKerulet(event.target.value)}
|
||||||
placeholder="Kerület"
|
placeholder="Kerület"
|
||||||
className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
|
|||||||
Reference in New Issue
Block a user