Ajout de la requete pour les catégorie et implémentation dans creer un objet

This commit is contained in:
Mathis 2025-04-12 10:25:23 +02:00
parent 4a43437b47
commit 72d3211d5e
3 changed files with 43 additions and 10 deletions

View File

@ -63,6 +63,7 @@ public class MainVerticle extends AbstractVerticle {
router.post("/updateProfil").handler(setUser::updateUserProfile); router.post("/updateProfil").handler(setUser::updateUserProfile);
router.post("/changePassword").handler(setUser::changeUserPassword); router.post("/changePassword").handler(setUser::changeUserPassword);
router.post("/publicUser").handler(queryUsers::getPublicUser); router.post("/publicUser").handler(queryUsers::getPublicUser);
router.get("/getCategories").handler(queryObjects::getCategories);
// Routes d'authentification // Routes d'authentification
router.post("/signup").handler(authHandler::handleSignup); router.post("/signup").handler(authHandler::handleSignup);
router.post("/login").handler(authHandler::handleLogin); router.post("/login").handler(authHandler::handleLogin);

View File

@ -40,6 +40,26 @@ public class QueryObjects {
}); });
} }
public void getCategories(RoutingContext context) {
databaseService.pool
.query("SELECT DISTINCT type FROM weather_objects;")
.execute()
.onFailure(e -> {
System.err.println("Erreur de récupération de la BDD :" + e.getMessage());
context.response()
.setStatusCode(500)
.end(new JsonObject().put("error", "Erreur de récupération de la BDD").encode());
})
.onSuccess(rows -> {
JsonArray types = new JsonArray();
rows.forEach(row -> types.add(row.getString("type")));
context.response()
.putHeader("content-type", "application/json; charset=UTF-8")
.end(types.encode());
});
}
public void getParticularObject(RoutingContext context) { public void getParticularObject(RoutingContext context) {
JsonObject body = context.body().asJsonObject(); JsonObject body = context.body().asJsonObject();
if (body == null) { if (body == null) {

View File

@ -1,4 +1,4 @@
import React, { useState } from "react"; import React, { useEffect, useState } from "react";
import { BadgePlus } from "lucide-react"; import { BadgePlus } from "lucide-react";
import axios from "axios"; import axios from "axios";
import { API_BASE_URL } from "../config"; import { API_BASE_URL } from "../config";
@ -6,7 +6,7 @@ import { useAuth } from "../AuthContext";
function FormNewObject({ isAdmin }) { function FormNewObject({ isAdmin }) {
const { user } = useAuth(); const { user } = useAuth();
const [categorie, setCategorie] = useState({});
const [description, setDescription] = useState(""); const [description, setDescription] = useState("");
const [type, setType] = useState(""); const [type, setType] = useState("");
const [location, setLocalisation] = useState(""); const [location, setLocalisation] = useState("");
@ -32,7 +32,7 @@ function FormNewObject({ isAdmin }) {
location, location,
status, status,
batterieType, batterieType,
proprio_id proprio_id,
}) })
.then((response) => { .then((response) => {
setMessRequete("Votre objet à bien été enregistré !"); setMessRequete("Votre objet à bien été enregistré !");
@ -49,6 +49,12 @@ function FormNewObject({ isAdmin }) {
setVerif(true); setVerif(true);
} }
} }
useEffect(() => {
axios.get(`${API_BASE_URL}/getCategories`).then((response) => {
setCategorie(response.data);
console.log(response.data);
});
}, []);
function resetForm() { function resetForm() {
setNom(""); setNom("");
setStatus("active"); setStatus("active");
@ -136,15 +142,21 @@ function FormNewObject({ isAdmin }) {
> >
Type : Type :
</label> </label>
<input <select
id="type" id="type"
className="text-gray-600 border rounded-lg p-2 w-full" className="text-gray-600 border rounded-lg p-2 w-full"
type="text"
value={type} value={type}
onChange={(e) => setType(e.target.value)} onChange={(e) => setType(e.target.value)}
required required
disabled={verif} disabled={verif}
/> >
<option value="">-- Sélectionner un type --</option>
{categorie.map((cat, index) => (
<option key={index} value={cat}>
{cat}
</option>
))}
</select>
</div> </div>
<div className="mb-5"> <div className="mb-5">