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("/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);
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
@ -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,12 +6,12 @@ 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("");
|
||||||
const [proprio_id,setProprio_id] = useState(user?.id);
|
const [proprio_id, setProprio_id] = useState(user?.id);
|
||||||
const [batterieType,setBatterieType] = useState("");
|
const [batterieType, setBatterieType] = useState("");
|
||||||
const [status, setStatus] = useState("active");
|
const [status, setStatus] = useState("active");
|
||||||
const [nom, setNom] = useState("");
|
const [nom, setNom] = useState("");
|
||||||
const [Response, setResponse] = useState(null);
|
const [Response, setResponse] = useState(null);
|
||||||
@ -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");
|
||||||
@ -56,7 +62,7 @@ function FormNewObject({ isAdmin }) {
|
|||||||
setType("");
|
setType("");
|
||||||
setLocalisation("");
|
setLocalisation("");
|
||||||
setBatterieType("");
|
setBatterieType("");
|
||||||
if(isAdmin)set_id("");
|
if (isAdmin) set_id("");
|
||||||
setActive(true);
|
setActive(true);
|
||||||
}
|
}
|
||||||
function handleCancel() {
|
function handleCancel() {
|
||||||
@ -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">
|
||||||
@ -195,7 +207,7 @@ function FormNewObject({ isAdmin }) {
|
|||||||
value={proprio_id}
|
value={proprio_id}
|
||||||
onChange={(e) => setProprio_id(e.target.value)}
|
onChange={(e) => setProprio_id(e.target.value)}
|
||||||
required
|
required
|
||||||
disabled={verif||!isAdmin}
|
disabled={verif || !isAdmin}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user