Compare commits
3 Commits
3f0465fb5a
...
544a59b92e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
544a59b92e | ||
|
|
03b81b65e5 | ||
|
|
7faeb32b14 |
@@ -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'] ?? null
|
||||||
|
]);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ class WcAdatok extends Model
|
|||||||
return $this->belongsTo(Keruletek::class);
|
return $this->belongsTo(Keruletek::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function felhasznalo(){
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
protected $table = 'wc_adatok';
|
protected $table = 'wc_adatok';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ return new class extends Migration
|
|||||||
$table->double('hossz_koord');
|
$table->double('hossz_koord');
|
||||||
$table->double('szel_koord');
|
$table->double('szel_koord');
|
||||||
$table->string('utvonal', 1000);
|
$table->string('utvonal', 1000);
|
||||||
$table->foreignId('felhasznalo_id')->references('id')->on('felhasznalok');
|
$table->foreignId('felhasznalo_id')->nullable()->references('id')->on('felhasznalok');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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']);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import React, {useState} from "react";
|
import React, { useState} from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
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,37 +17,50 @@ 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,
|
||||||
nyitva: nyitva,
|
nyitva: nyitva,
|
||||||
utvonal: utvonal,
|
utvonal: utvonal,
|
||||||
koordinatak: koordinatak
|
koordinatak: koordinatak,
|
||||||
|
felhasznalo_id: null
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch("http://192.168.0.78:8000/api/hozzaadas", {
|
fetch("http://localhost:8000/api/hozzaadas", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body: JSON.stringify(wcInfo)
|
body: JSON.stringify(wcInfo)
|
||||||
})
|
})
|
||||||
.then((response) => response.json())
|
.then(async (response) => {
|
||||||
.then((newWC) => {
|
if (!response.ok) {
|
||||||
setNev("");
|
const errorData = await response.json();
|
||||||
setKerulet("");
|
console.error("Hiba a POST kérésnél:", errorData);
|
||||||
setKozeli("");
|
alert("Hiba történt az adatok mentésekor.");
|
||||||
setAkadalym(false);
|
return;
|
||||||
setAr("");
|
}
|
||||||
setNyitva("");
|
|
||||||
setUtvonal("");
|
const newWC = await response.json();
|
||||||
setKoordinatak("");
|
|
||||||
navigate("/");
|
console.log("Sikeres mentés:", newWC);
|
||||||
})
|
|
||||||
.catch((error) => {
|
// csak siker után törlünk mindent és navigálunk
|
||||||
console.log(error);
|
setNev("");
|
||||||
})
|
setKeruletId("");
|
||||||
|
setKozeli("");
|
||||||
|
setAkadalym(false);
|
||||||
|
setAr("");
|
||||||
|
setNyitva("");
|
||||||
|
setUtvonal("");
|
||||||
|
setKoordinatak("");
|
||||||
|
navigate("/");
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("Hálózati hiba:", error);
|
||||||
|
alert("Nem sikerült csatlakozni a szerverhez.");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const ToolTip = ({children, text}) => {
|
const ToolTip = ({children, text}) => {
|
||||||
@@ -82,14 +95,31 @@ export default function HozzaadForm() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<label className="block text-gray-700">Kerület:</label>
|
<label className="block text-gray-700">Kerület:</label>
|
||||||
|
|
||||||
|
<select
|
||||||
|
id="kerulet"
|
||||||
|
name="kerulet_id"
|
||||||
|
value={kerulet_id}
|
||||||
|
onChange={(event) => setKeruletId(event.target.value)}
|
||||||
|
>
|
||||||
|
<option value="">Válassz kerületet</option>
|
||||||
|
{Array.from({ length: 23 }, (_, i) => (
|
||||||
|
<option key={i + 1} value={i + 1}>
|
||||||
|
{i + 1}. kerület
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</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"
|
||||||
/>
|
/>
|
||||||
|
*/}
|
||||||
|
|
||||||
<label className="block text-gray-700">Legközelebbi megálló:</label>
|
<label className="block text-gray-700">Legközelebbi megálló:</label>
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export async function mosdokFetch() {
|
export async function mosdokFetch() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('http://192.168.0.78:8000/api/mosdok');
|
const response = await fetch('http://localhost:8000/api/mosdok');
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Hiba: ${response.status}`);
|
throw new Error(`Hiba: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user