Recupération Demande suppression partie Admin
This commit is contained in:
parent
ed647c8891
commit
ff7c27ba90
@ -46,6 +46,10 @@ public class MainVerticle extends AbstractVerticle {
|
|||||||
setWeatherData.setUserHandler(setUser);
|
setWeatherData.setUserHandler(setUser);
|
||||||
QueryDeleteObject RequestDeleteObject = new QueryDeleteObject(databaseService);
|
QueryDeleteObject RequestDeleteObject = new QueryDeleteObject(databaseService);
|
||||||
|
|
||||||
|
SetRequestDeleteObject DeleteObject = new SetRequestDeleteObject(databaseService);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Déclaration des routes
|
// Déclaration des routes
|
||||||
router.get("/objets").handler(queryObjects::getObjects);
|
router.get("/objets").handler(queryObjects::getObjects);
|
||||||
@ -68,14 +72,11 @@ public class MainVerticle extends AbstractVerticle {
|
|||||||
router.post("/addCategories").handler(setObjects::newCategorie);
|
router.post("/addCategories").handler(setObjects::newCategorie);
|
||||||
router.post("/deleteCategories").handler(setObjects::deleteCategories);
|
router.post("/deleteCategories").handler(setObjects::deleteCategories);
|
||||||
router.post("/requestDeleteObject").handler(RequestDeleteObject::deleteObject);
|
router.post("/requestDeleteObject").handler(RequestDeleteObject::deleteObject);
|
||||||
|
router.get("/getDemandeSuppression").handler(DeleteObject::getAllDeletionRequests);
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
|
|
||||||
// Création du serveur HTTP
|
// Création du serveur HTTP
|
||||||
vertx.createHttpServer()
|
vertx.createHttpServer()
|
||||||
.requestHandler(router)
|
.requestHandler(router)
|
||||||
|
|||||||
@ -37,7 +37,8 @@ public class QueryDeleteObject {
|
|||||||
databaseService.pool.preparedQuery(checkQuery).execute(Tuple.of(objectId), res -> {
|
databaseService.pool.preparedQuery(checkQuery).execute(Tuple.of(objectId), res -> {
|
||||||
if (res.failed()) {
|
if (res.failed()) {
|
||||||
res.cause().printStackTrace(); // Affiche l'erreur SQL s'il y en a une
|
res.cause().printStackTrace(); // Affiche l'erreur SQL s'il y en a une
|
||||||
context.response().setStatusCode(500).end(new JsonObject().put("error", "Erreur base de données").encode());
|
context.response().setStatusCode(500)
|
||||||
|
.end(new JsonObject().put("error", "Erreur base de données").encode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,13 +53,45 @@ public class QueryDeleteObject {
|
|||||||
|
|
||||||
databaseService.pool.preparedQuery(insertQuery).execute(Tuple.of(objectId, userId), insertRes -> {
|
databaseService.pool.preparedQuery(insertQuery).execute(Tuple.of(objectId, userId), insertRes -> {
|
||||||
if (insertRes.succeeded()) {
|
if (insertRes.succeeded()) {
|
||||||
context.response().setStatusCode(200).end(new JsonObject().put("message", "Demande envoyée").encode());
|
context.response().setStatusCode(200)
|
||||||
|
.end(new JsonObject().put("message", "Demande envoyée").encode());
|
||||||
} else {
|
} else {
|
||||||
insertRes.cause().printStackTrace(); // Pour voir l'erreur en console
|
insertRes.cause().printStackTrace(); // Pour voir l'erreur en console
|
||||||
context.response().setStatusCode(500).end(new JsonObject().put("error", "Erreur insertion").encode());
|
context.response().setStatusCode(500)
|
||||||
|
.end(new JsonObject().put("error", "Erreur insertion").encode());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getAllDeletionRequests(RoutingContext context) {
|
||||||
|
String query = "SELECT * FROM deletion_requests";
|
||||||
|
|
||||||
|
databaseService.pool.query(query).execute(res -> {
|
||||||
|
if (res.succeeded()) {
|
||||||
|
var results = res.result();
|
||||||
|
var jsonArray = new io.vertx.core.json.JsonArray();
|
||||||
|
|
||||||
|
results.forEach(row -> {
|
||||||
|
JsonObject json = new JsonObject()
|
||||||
|
.put("id", row.getInteger("id"))
|
||||||
|
.put("object_id", row.getInteger("object_id"))
|
||||||
|
.put("requested_by", row.getInteger("requested_by"))
|
||||||
|
.put("requested_at", row.getLocalDateTime("requested_at").toString()); // si tu as un champ
|
||||||
|
// de type timestamp
|
||||||
|
jsonArray.add(json);
|
||||||
|
});
|
||||||
|
|
||||||
|
context.response()
|
||||||
|
.putHeader("Content-Type", "application/json")
|
||||||
|
.end(jsonArray.encode());
|
||||||
|
} else {
|
||||||
|
res.cause().printStackTrace();
|
||||||
|
context.response().setStatusCode(500)
|
||||||
|
.end(new JsonObject().put("error", "Erreur lors de la récupération des demandes").encode());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,43 @@
|
|||||||
|
package com.example.starter;
|
||||||
|
|
||||||
|
import io.vertx.core.json.JsonArray;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import io.vertx.ext.web.RoutingContext;
|
||||||
|
import io.vertx.sqlclient.Row;
|
||||||
|
import io.vertx.sqlclient.RowSet;
|
||||||
|
|
||||||
|
public class SetRequestDeleteObject {
|
||||||
|
private final DatabaseService databaseService;
|
||||||
|
|
||||||
|
// Le nom du constructeur doit correspondre au nom de la classe
|
||||||
|
public SetRequestDeleteObject(DatabaseService dtbS) {
|
||||||
|
this.databaseService = dtbS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getAllDeletionRequests(RoutingContext context) {
|
||||||
|
String query = "SELECT * FROM deletion_requests";
|
||||||
|
|
||||||
|
databaseService.pool.query(query).execute(res -> {
|
||||||
|
if (res.succeeded()) {
|
||||||
|
RowSet<Row> results = res.result();
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
|
||||||
|
results.forEach(row -> {
|
||||||
|
JsonObject json = new JsonObject()
|
||||||
|
.put("id", row.getInteger("id"))
|
||||||
|
.put("object_id", row.getInteger("object_id"))
|
||||||
|
.put("requested_by", row.getInteger("requested_by"))
|
||||||
|
.put("request_date", row.getLocalDateTime("request_date").toString()); // Assurez-vous que le type correspond
|
||||||
|
jsonArray.add(json);
|
||||||
|
});
|
||||||
|
|
||||||
|
context.response()
|
||||||
|
.putHeader("Content-Type", "application/json")
|
||||||
|
.end(jsonArray.encode());
|
||||||
|
} else {
|
||||||
|
res.cause().printStackTrace();
|
||||||
|
context.response().setStatusCode(500).end(new JsonObject().put("error", "Erreur lors de la récupération des demandes").encode());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,36 +1,30 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
import { Check, X } from "lucide-react";
|
import { Check, X } from "lucide-react";
|
||||||
import { useAuth } from "../AuthContext";
|
import { useAuth } from "../AuthContext";
|
||||||
|
|
||||||
function Alert({ affAlert, setAffAlert, message }) {
|
function Alert({ affAlert, setAffAlert, message }) {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
|
|
||||||
// Gère la disparition de l'alerte après 3 secondes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (affAlert) {
|
if (affAlert) {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
setAffAlert(false); // Cache l'alerte après 3 secondes
|
setAffAlert(false);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
return () => clearTimeout(timer); // Nettoie le timer au besoin
|
return () => clearTimeout(timer);
|
||||||
}
|
}
|
||||||
}, [affAlert, setAffAlert]);
|
}, [affAlert, setAffAlert]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
affAlert && user?.role !== "user" && (
|
affAlert && user?.role !== "user" && (
|
||||||
<div className="flex flex-col md:flex-row bg-slate-600 w-full md:w-1/2 lg:w-1/3 fixed top-20 right-1 sm:right-4 rounded-lg p-4 md:p-5 items-center gap-4 md:gap-6 shadow-lg opacity-90">
|
<div className="fixed top-6 right-4 z-50 bg-slate-700 text-white px-6 py-4 rounded-xl shadow-lg flex items-center gap-4 w-[90%] sm:w-[350px]">
|
||||||
|
<Check className="text-green-400 w-6 h-6 flex-shrink-0" />
|
||||||
|
<p className="text-sm sm:text-base flex-grow">{message}</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => setAffAlert(false)}
|
onClick={() => setAffAlert(false)}
|
||||||
className="absolute top-2 right-2 text-white hover:text-gray-300"
|
className="text-white hover:text-gray-300"
|
||||||
>
|
>
|
||||||
<X />
|
<X />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<Check className="text-green-700 w-12 h-12 md:w-16 md:h-16" />
|
|
||||||
|
|
||||||
|
|
||||||
<p className="text-sm md:text-base text-white text-center md:text-left">
|
|
||||||
{message}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -9,6 +9,7 @@ function AdminObjet() {
|
|||||||
const [categories, setCategories] = useState();
|
const [categories, setCategories] = useState();
|
||||||
const [newCategory, setNewCategory] = useState("");
|
const [newCategory, setNewCategory] = useState("");
|
||||||
const [objects, setObjects] = useState([]);
|
const [objects, setObjects] = useState([]);
|
||||||
|
const [deleteRequests, setDeleteRequests] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get(`${API_BASE_URL}/objets`).then((response) => {
|
axios.get(`${API_BASE_URL}/objets`).then((response) => {
|
||||||
@ -16,6 +17,20 @@ function AdminObjet() {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
axios
|
||||||
|
.get(`${API_BASE_URL}/getDemandeSuppression`)
|
||||||
|
.then((response) => {
|
||||||
|
setDeleteRequests(response.data);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(
|
||||||
|
"Erreur lors de la récupération des requêtes de suppression :",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleAddCategory = () => {
|
const handleAddCategory = () => {
|
||||||
const trimmed = newCategory.trim();
|
const trimmed = newCategory.trim();
|
||||||
if (trimmed !== "" && !categories.includes(trimmed)) {
|
if (trimmed !== "" && !categories.includes(trimmed)) {
|
||||||
@ -315,6 +330,62 @@ function AdminObjet() {
|
|||||||
Enregistrer les règles globales
|
Enregistrer les règles globales
|
||||||
</button>
|
</button>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section className="bg-white p-6 rounded-xl shadow-md mt-12">
|
||||||
|
<h2 className="text-2xl font-semibold mb-4">
|
||||||
|
Demandes de Suppression d'Objets
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full min-w-[640px] divide-y divide-gray-200">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Objet ID</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Utilisateur ID</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date de Requête</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="bg-white divide-y divide-gray-200">
|
||||||
|
{deleteRequests.map((request) => (
|
||||||
|
<tr key={request.id}>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{request.id}</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{request.object_id}</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{request.requested_by}</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{request.request_date}</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900 flex gap-2">
|
||||||
|
<button
|
||||||
|
className="bg-green-500 hover:bg-green-600 text-white px-3 py-1 rounded-md text-sm"
|
||||||
|
onClick={() => handleAccept(request.id)}
|
||||||
|
>
|
||||||
|
Accepter
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="bg-red-500 hover:bg-red-600 text-white px-3 py-1 rounded-md text-sm"
|
||||||
|
onClick={() => handleReject(request.id)}
|
||||||
|
>
|
||||||
|
Refuser
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{deleteRequests.length === 0 && (
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
colSpan="5"
|
||||||
|
className="px-6 py-4 text-center text-sm text-gray-500"
|
||||||
|
>
|
||||||
|
Aucune demande de suppression trouvée.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -43,6 +43,7 @@ const initialWidgets = [
|
|||||||
{ id: 3, type: "reporting" },
|
{ id: 3, type: "reporting" },
|
||||||
{ id: 4, type: "adminobjet" },
|
{ id: 4, type: "adminobjet" },
|
||||||
{ id: 5, type: "objects" },
|
{ id: 5, type: "objects" },
|
||||||
|
{ id: 6, type: "requestObject" }
|
||||||
];
|
];
|
||||||
|
|
||||||
function Dashboard() {
|
function Dashboard() {
|
||||||
@ -70,6 +71,10 @@ function Dashboard() {
|
|||||||
axios.get(`${API_BASE_URL}/objets`).then((response) => {
|
axios.get(`${API_BASE_URL}/objets`).then((response) => {
|
||||||
setAdminObjects(response.data);
|
setAdminObjects(response.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
axios.get(`${API_BASE_URL}/demandeSuppression`).then((response) => {
|
||||||
|
setRequestDeleteObject(response.data);
|
||||||
|
})
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const [adminObjects, setAdminObjects] = useState([
|
const [adminObjects, setAdminObjects] = useState([
|
||||||
@ -284,6 +289,25 @@ function Dashboard() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{widget.type ==="requestObject" && (
|
||||||
|
<div>
|
||||||
|
<h2 className="text-xl font-semibold mb-4">Requête suppression objets</h2>
|
||||||
|
|
||||||
|
<div className="mb-4">
|
||||||
|
<p className="text-gray-700 mb-2">Générer des rapports d'utilisation :</p>
|
||||||
|
<div className="flex gap-4">
|
||||||
|
<button
|
||||||
|
className="bg-indigo-600 text-white px-4 py-2 rounded-md hover:bg-indigo-700"
|
||||||
|
onClick={() => exportCSV()}
|
||||||
|
>
|
||||||
|
Requête objets
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
)}
|
||||||
{widget.type === "reporting" && (
|
{widget.type === "reporting" && (
|
||||||
<div>
|
<div>
|
||||||
<h2 className="text-xl font-semibold mb-4">Rapports et Statistiques</h2>
|
<h2 className="text-xl font-semibold mb-4">Rapports et Statistiques</h2>
|
||||||
@ -372,6 +396,12 @@ function Dashboard() {
|
|||||||
>
|
>
|
||||||
Rapports et Statistiques
|
Rapports et Statistiques
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => handleWidgetSelection("requestObject")}
|
||||||
|
className="px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-md text-left"
|
||||||
|
>
|
||||||
|
Demande de suppression d'objets
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowAddWidgetModal(false)}
|
onClick={() => setShowAddWidgetModal(false)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user