diff --git a/Back-end/pom.xml b/Back-end/pom.xml index d37428b..15670a8 100644 --- a/Back-end/pom.xml +++ b/Back-end/pom.xml @@ -49,7 +49,7 @@ io.agroal agroal-pool - 1.16 + 1.16 io.vertx diff --git a/Back-end/src/main/java/com/example/starter/MainVerticle.java b/Back-end/src/main/java/com/example/starter/MainVerticle.java index 5fa59f0..5054e48 100644 --- a/Back-end/src/main/java/com/example/starter/MainVerticle.java +++ b/Back-end/src/main/java/com/example/starter/MainVerticle.java @@ -16,6 +16,7 @@ public class MainVerticle extends AbstractVerticle { databaseService = new DatabaseService(vertx); QueryObjects queryObjects = new QueryObjects(databaseService); QueryWeatherData queryWeather = new QueryWeatherData(databaseService); + SetObjects setObjects = new SetObjects(databaseService); // Create a Router Router router = Router.router(vertx); router.route().handler(BodyHandler.create()); @@ -27,9 +28,10 @@ public class MainVerticle extends AbstractVerticle { .allowedHeader("Authorization")); router.get("/objets").handler(queryObjects::getObjects); router.get("/objet").handler(queryObjects::getParticularObject); - router.post("/modifObjet").handler(queryObjects::setInfoObjet); + router.post("/modifObjet").handler(setObjects::setInfoObjet); router.get("/wind").handler(queryWeather::getWindInfos); router.get("/meteo").handler(queryWeather::getMeteoInfos); + router.post("/addObject").handler(setObjects::newObject); vertx.createHttpServer() .requestHandler(router) diff --git a/Back-end/src/main/java/com/example/starter/QueryObjects.java b/Back-end/src/main/java/com/example/starter/QueryObjects.java index 4c7d3d5..0dba41c 100644 --- a/Back-end/src/main/java/com/example/starter/QueryObjects.java +++ b/Back-end/src/main/java/com/example/starter/QueryObjects.java @@ -81,44 +81,4 @@ public class QueryObjects { } return objects; } - - public void setInfoObjet(RoutingContext context) { - JsonObject body = context.body().asJsonObject(); - if (body == null) { - context.response() - .setStatusCode(400) - .end(new JsonObject().put("error", "Corps de la requête manquant").encode()); - return; - } - Integer id = body.getInteger("id"); - String description = body.getString("description"); - String type = body.getString("type"); - String location = body.getString("location"); - String status = body.getString("status"); - - databaseService.pool - .preparedQuery( - "UPDATE weather_objects SET description=?,type=?,location=?,status=?,last_update=CURRENT_TIMESTAMP WHERE id=?") - .execute(Tuple.of(description, type, location, status, id)) - .onFailure(e -> { - System.err.println("Erreur de récupération de la BDD :" + e.getMessage()); - context.response() - .setStatusCode(500) - .end(new JsonObject().put("Erreur", "Erreur de récupération de la BDD").encode()); - }) - .onSuccess(rows -> { - if (rows.rowCount() == 0) { - context.response() - .setStatusCode(404) - .end(new JsonObject().put("error", "Objet non trouvé").encode()); - return; - } - context.response() - .putHeader("content-type", "application/json: charset=UTF-8") - .end(new JsonObject().put("success", "L'objet à bien été mis à jour").encode()); - return; - }); - - } - } diff --git a/Back-end/src/main/java/com/example/starter/SetObjects.java b/Back-end/src/main/java/com/example/starter/SetObjects.java new file mode 100644 index 0000000..dd35436 --- /dev/null +++ b/Back-end/src/main/java/com/example/starter/SetObjects.java @@ -0,0 +1,89 @@ +package com.example.starter; + +import io.vertx.core.json.JsonObject; +import io.vertx.ext.web.RoutingContext; +import io.vertx.sqlclient.Tuple; + +public class SetObjects { + private DatabaseService databaseService; + + public SetObjects(DatabaseService ddbs) { + this.databaseService = ddbs; + } + + public void setInfoObjet(RoutingContext context) { + JsonObject body = context.body().asJsonObject(); + if (body == null) { + context.response() + .setStatusCode(400) + .end(new JsonObject().put("error", "Corps de la requête manquant").encode()); + return; + } + Integer id = body.getInteger("id"); + String description = body.getString("description"); + String type = body.getString("type"); + String location = body.getString("location"); + String status = body.getString("status"); + + databaseService.pool + .preparedQuery( + "UPDATE weather_objects SET description=?,type=?,location=?,status=?,last_update=CURRENT_TIMESTAMP WHERE id=?") + .execute(Tuple.of(description, type, location, status, id)) + .onFailure(e -> { + System.err.println("Erreur de récupération de la BDD :" + e.getMessage()); + context.response() + .setStatusCode(500) + .end(new JsonObject().put("Erreur", "Erreur de récupération de la BDD").encode()); + }) + .onSuccess(rows -> { + if (rows.rowCount() == 0) { + context.response() + .setStatusCode(404) + .end(new JsonObject().put("error", "Objet non trouvé").encode()); + return; + } + context.response() + .putHeader("content-type", "application/json: charset=UTF-8") + .end(new JsonObject().put("success", "L'objet à bien été mis à jour").encode()); + return; + }); + } + + public void newObject(RoutingContext context){ + JsonObject body = context.body().asJsonObject(); + if(body== null){ + context.response() + .setStatusCode(400) + .end(new JsonObject().put("error","Corps de la requête manquant").encode()); + return; + } + String name = body.getString("nom"); + String description = body.getString("description"); + String type = body.getString("type"); + String location = body.getString("location"); + String status = body.getString("status"); + databaseService.pool + .preparedQuery("INSERT INTO weather_objects (name,description,type,location,status) VALUES (?,?,?,?,?)") + .execute(Tuple.of(name,description,type,location,status)) + .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 -> { + if(rows.rowCount()==0){ + context.response() + .setStatusCode(404) + .end(new JsonObject().put("error", "Objet non trouvé").encode()); + return; + } + context.response() + .putHeader("content-type","application/json: charset=UTF-8") + .end(new JsonObject().put("success", "L'objet à bien été ajouté").encode()); + return; + }); + + } + +} diff --git a/Front-end/src/App.jsx b/Front-end/src/App.jsx index 82b5cd9..d76005c 100644 --- a/Front-end/src/App.jsx +++ b/Front-end/src/App.jsx @@ -5,6 +5,7 @@ import Gestion from "./pages/Gestion/Gestion.jsx"; import Header from "./components/Header.jsx"; import ObjectManagement from "./pages/Gestion/ObjectManagement.jsx"; import Objet from "./pages/Gestion/Objet.jsx"; +import AddObject from "./pages/Gestion/AddObject.jsx"; function App() { return ( @@ -17,6 +18,7 @@ function App() { } /> } /> } /> + } /> diff --git a/Front-end/src/components/InfoObject.jsx b/Front-end/src/components/InfoObject.jsx index e1208c2..9c16424 100644 --- a/Front-end/src/components/InfoObject.jsx +++ b/Front-end/src/components/InfoObject.jsx @@ -5,33 +5,32 @@ function InfoObject({ object,defafficherModif }) { return (
-
+

Informations

-
-
+

Description :

-

{object.description}

+

{object.description}

-
+

Type :

{object.type}

-
+

Localisation :

{object.location}

-
+

Status :

{object.status}

-
+

Derniere mise à jour :

@@ -40,7 +39,6 @@ function InfoObject({ object,defafficherModif }) { -
); } diff --git a/Front-end/src/components/ModifObject.jsx b/Front-end/src/components/ModifObject.jsx index d627245..f1d8b9c 100644 --- a/Front-end/src/components/ModifObject.jsx +++ b/Front-end/src/components/ModifObject.jsx @@ -1,6 +1,5 @@ -import React, { use } from "react"; -import { Check, Info } from "lucide-react"; -import { useState } from "react"; +import React, { useState } from "react"; +import { Info } from "lucide-react"; import axios from "axios"; import { API_BASE_URL } from "../config"; @@ -8,135 +7,144 @@ function ModifObject({ object, defafficherModif }) { const [description, setDescription] = useState(object.description || ""); const [type, setType] = useState(object.type || ""); const [location, setLocalisation] = useState(object.location || ""); - const [status, setStatus] = useState(object.status || ""); - const [Response, setResponse] = useState(null); - const [isActive,setActive] = useState(object.status==="active"); + const [status, setStatus] = useState(object.status || "inactive"); + const [isActive, setActive] = useState(object.status === "active"); - function makeChange() { + function handleSubmit(event) { + event.preventDefault(); // Empêche le rechargement de la page axios .post(`${API_BASE_URL}/modifObjet`, { id: object.id, - description: description, - type: type, - location: location, - status: status, + description, + type, + location, + status, }) .then((response) => { - setResponse(response.data[0]); + console.log("Modification réussie :", response.data); + }) + .catch((error) => { + console.error("Erreur lors de la modification :", error); }); defafficherModif(false); window.location.reload(); } - function cancelChange() { + + function handleCancel() { defafficherModif(false); } - function handleDescriptionChange(event) { - setDescription(event.target.value); - } - function handleTypeChange(event) { - setType(event.target.value); - } - function handleLocalisationChange(event) { - setLocalisation(event.target.value); - } - function handleStatusChange(event) { + + function handleStatusChange() { setActive((prevIsActive) => { const newIsActive = !prevIsActive; - const newStatus = newIsActive ? "active" : "inactive"; - console.log(newStatus); - setStatus(newStatus); + setStatus(newIsActive ? "active" : "inactive"); return newIsActive; }); } + return ( -
+
-

+

Modifier les infos

-
-
-

Description :

- -
+
+ + setDescription(e.target.value)} + required + /> +
-
-

Type :

- -
+
+ + setType(e.target.value)} + required + /> +
-
-

Localisation :

- -
+
+ + setLocalisation(e.target.value)} + required + /> +
-
-

Status :

-
+
+ +
+ +
+ - -
- - -
- - + className="absolute top-0 left-0 w-5 h-5 bg-white rounded-full border border-slate-300 shadow-sm transition-transform duration-300 peer-checked:translate-x-6 peer-checked:border-slate-800 cursor-pointer" + >
-
-
-
+ +
+ + +
+ ); } + export default ModifObject; diff --git a/Front-end/src/pages/Gestion/AddObject.jsx b/Front-end/src/pages/Gestion/AddObject.jsx new file mode 100644 index 0000000..0fcf593 --- /dev/null +++ b/Front-end/src/pages/Gestion/AddObject.jsx @@ -0,0 +1,206 @@ +import React, { useState } from "react"; +import { BadgePlus } from "lucide-react"; +import axios from "axios"; +import { API_BASE_URL } from "../../config"; + +function AddObject() { + const [description, setDescription] = useState(""); + const [type, setType] = useState(""); + const [location, setLocalisation] = useState(""); + const [status, setStatus] = useState("active"); + const [nom, setNom] = useState(""); + const [Response, setResponse] = useState(null); + const [isActive, setActive] = useState(true); + const [verif, setVerif] = useState(false); + + function handleSubmit(event) { + event.preventDefault(); + + if (verif) { + console.log("Envoi requete"); + axios + .post(`${API_BASE_URL}/addObject`, { + nom, + description, + type, + location, + status, + }) + .then((response) => { + console.log("Modification réussie :", response.data); + }) + .catch((error) => { + console.error("Erreur lors de la modification :", error); + }); + }else{ + setVerif(true); + } + } + function handleCancel() { + if(verif){ + setVerif(false); + }else{ + setNom(""); + setStatus(""); + setDescription(""); + setType(""); + setLocalisation(""); + setActive(true); + } + } + + function handleStatusChange() { + setActive((prevIsActive) => { + const newIsActive = !prevIsActive; + setStatus(newIsActive ? "active" : "inactive"); + return newIsActive; + }); + } + + return ( +
+
+
+

+ Nouvel objet +

+
+
+
+
+ +
+

+ {(!verif)?("Entrez les données de votre nouvel objet"):("Êtes-vous sûr de ces données ?")} +

+
+
+ + setNom(e.target.value)} + required + disabled={verif} + /> +
+
+ + setDescription(e.target.value)} + required + disabled={verif} + /> +
+ +
+ + setType(e.target.value)} + required + disabled={verif} + /> +
+ +
+ + setLocalisation(e.target.value)} + required + disabled={verif} + /> +
+ +
+ +
+ +
+ + +
+ +
+
+ +
+ + +
+
+
+
+ ); +} + +export default AddObject; diff --git a/Front-end/src/pages/Gestion/Gestion.jsx b/Front-end/src/pages/Gestion/Gestion.jsx index 01a9282..54d76ab 100644 --- a/Front-end/src/pages/Gestion/Gestion.jsx +++ b/Front-end/src/pages/Gestion/Gestion.jsx @@ -10,7 +10,7 @@ import { RadioTower, Binoculars, Settings, - ChartArea, + BadgePlus, } from "lucide-react"; function Gestion() { @@ -26,8 +26,7 @@ function Gestion() {

- {/* Features Grid */} -
+
@@ -47,7 +46,7 @@ function Gestion() {
- +

Ajouter un nouvel objet connecté @@ -56,29 +55,13 @@ function Gestion() { Intégrez facilement un nouvel objet connecté en renseignant ses informations et en configurant ses paramètres pour une gestion optimale.

Ajouter un objet

-
-
- -
-

- Optimisation et surveillance des ressources -

-

- Suivez les performances des dispositifs connectés et optimisez leur utilisation pour une gestion efficace des ressources. -

- - En savoir plus - -
+
diff --git a/Front-end/src/pages/Gestion/Objet.jsx b/Front-end/src/pages/Gestion/Objet.jsx index b357e6d..f2cc28d 100644 --- a/Front-end/src/pages/Gestion/Objet.jsx +++ b/Front-end/src/pages/Gestion/Objet.jsx @@ -3,6 +3,8 @@ import { Thermometer, CircleGauge, Droplet } from "lucide-react"; import { useEffect, useState } from "react"; import axios from "axios"; +import { API_BASE_URL } from "../../config"; + import InfoObjet from "../../components/InfoObject"; import ModifObject from "../../components/ModifObject"; import WindGraph from "../../components/WindGraph"; @@ -22,7 +24,7 @@ function Objet() { useEffect(() => { axios - .get(`http://localhost:8888/objet?id=${identifiant}`) + .get(`${API_BASE_URL}/objet?id=${identifiant}`) .then((response) => { setObject(response.data[0]); });