Ajout de la requete pour les catégorie et implémentation dans creer un objet
This commit is contained in:
parent
4a43437b47
commit
72d3211d5e
@ -63,6 +63,7 @@ public class MainVerticle extends AbstractVerticle {
|
||||
router.post("/updateProfil").handler(setUser::updateUserProfile);
|
||||
router.post("/changePassword").handler(setUser::changeUserPassword);
|
||||
router.post("/publicUser").handler(queryUsers::getPublicUser);
|
||||
router.get("/getCategories").handler(queryObjects::getCategories);
|
||||
// Routes d'authentification
|
||||
router.post("/signup").handler(authHandler::handleSignup);
|
||||
router.post("/login").handler(authHandler::handleLogin);
|
||||
|
||||
@ -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) {
|
||||
JsonObject body = context.body().asJsonObject();
|
||||
if (body == null) {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import React, { useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { BadgePlus } from "lucide-react";
|
||||
import axios from "axios";
|
||||
import { API_BASE_URL } from "../config";
|
||||
@ -6,7 +6,7 @@ import { useAuth } from "../AuthContext";
|
||||
|
||||
function FormNewObject({ isAdmin }) {
|
||||
const { user } = useAuth();
|
||||
|
||||
const [categorie, setCategorie] = useState({});
|
||||
const [description, setDescription] = useState("");
|
||||
const [type, setType] = useState("");
|
||||
const [location, setLocalisation] = useState("");
|
||||
@ -32,7 +32,7 @@ function FormNewObject({ isAdmin }) {
|
||||
location,
|
||||
status,
|
||||
batterieType,
|
||||
proprio_id
|
||||
proprio_id,
|
||||
})
|
||||
.then((response) => {
|
||||
setMessRequete("Votre objet à bien été enregistré !");
|
||||
@ -49,6 +49,12 @@ function FormNewObject({ isAdmin }) {
|
||||
setVerif(true);
|
||||
}
|
||||
}
|
||||
useEffect(() => {
|
||||
axios.get(`${API_BASE_URL}/getCategories`).then((response) => {
|
||||
setCategorie(response.data);
|
||||
console.log(response.data);
|
||||
});
|
||||
}, []);
|
||||
function resetForm() {
|
||||
setNom("");
|
||||
setStatus("active");
|
||||
@ -136,15 +142,21 @@ function FormNewObject({ isAdmin }) {
|
||||
>
|
||||
Type :
|
||||
</label>
|
||||
<input
|
||||
<select
|
||||
id="type"
|
||||
className="text-gray-600 border rounded-lg p-2 w-full"
|
||||
type="text"
|
||||
value={type}
|
||||
onChange={(e) => setType(e.target.value)}
|
||||
required
|
||||
disabled={verif}
|
||||
/>
|
||||
>
|
||||
<option value="">-- Sélectionner un type --</option>
|
||||
{categorie.map((cat, index) => (
|
||||
<option key={index} value={cat}>
|
||||
{cat}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="mb-5">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user