debut Ajout Userinfos Object
This commit is contained in:
parent
c7f01c5028
commit
54b3e4d2a1
@ -61,7 +61,7 @@ public class MainVerticle extends AbstractVerticle {
|
||||
router.post("/deleteUser").handler(setUser::deleteUser);
|
||||
router.post("/updateProfil").handler(setUser::updateUserProfile);
|
||||
router.post("/changePassword").handler(setUser::changeUserPassword);
|
||||
|
||||
router.post("/publicUser").handler(queryUsers::getPublicUser);
|
||||
// Routes d'authentification
|
||||
router.post("/signup").handler(authHandler::handleSignup);
|
||||
router.post("/login").handler(authHandler::handleLogin);
|
||||
|
||||
@ -97,6 +97,54 @@ public class QueryUsers {
|
||||
user.put("role", "admin");
|
||||
}
|
||||
|
||||
context.response()
|
||||
.putHeader("content-type", "application/json; charset=UTF-8")
|
||||
.end(user.encode());
|
||||
});
|
||||
}
|
||||
public void getPublicUser(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 idUser = body.getInteger("idUser");
|
||||
Integer idUser = 4;
|
||||
databaseService.pool
|
||||
.preparedQuery("SELECT * FROM users WHERE id=?;")
|
||||
.execute(Tuple.of(idUser))
|
||||
.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.size() == 0) {
|
||||
context.response()
|
||||
.setStatusCode(404)
|
||||
.end(new JsonObject().put("error", "Utilisateur non trouvé").encode());
|
||||
return;
|
||||
}
|
||||
|
||||
Row row = rows.iterator().next();
|
||||
int points = row.getInteger("points");
|
||||
JsonObject user = new JsonObject()
|
||||
.put("id", row.getInteger("id"))
|
||||
.put("gender", row.getString("gender"))
|
||||
.put("pseudo",row.getString("pseudo"))
|
||||
.put("points", points);
|
||||
|
||||
if (points <= 60) {
|
||||
user.put("role", "user");
|
||||
} else if (points <= 100) {
|
||||
user.put("role", "complexe");
|
||||
} else if (points >= 200) {
|
||||
user.put("role", "admin");
|
||||
}
|
||||
|
||||
context.response()
|
||||
.putHeader("content-type", "application/json; charset=UTF-8")
|
||||
.end(user.encode());
|
||||
|
||||
61
Front-end/src/components/UserInfosObject.jsx
Normal file
61
Front-end/src/components/UserInfosObject.jsx
Normal file
@ -0,0 +1,61 @@
|
||||
import React from "react";
|
||||
import { Info } from "lucide-react";
|
||||
import axios from "axios";
|
||||
import { API_BASE_URL } from "../config";
|
||||
|
||||
|
||||
function InfoObject({ object,defafficherModif }) {
|
||||
axios
|
||||
.post(`${API_BASE_URL}/publicUser`, {
|
||||
id: object.user,
|
||||
})
|
||||
.then((response) => {
|
||||
console.log("Modification réussie :", response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Erreur lors de la modification :", error);
|
||||
});
|
||||
defafficherModif(false);
|
||||
window.location.reload();
|
||||
return (
|
||||
<div key={object.id} className="bg-white p-6 rounded-xl min-w-5xl">
|
||||
<div className="flex align-items gap-6 mb-6">
|
||||
<div className="w-12 h-12 bg-indigo-100 rounded-lg flex items-center justify-center mb-1">
|
||||
<Info className="text-indigo-600" size={24} />
|
||||
</div>
|
||||
<h1 className="text-black text-2xl font-bold mb-1 ">Informations</h1>
|
||||
</div>
|
||||
<div className="mb-5">
|
||||
<p className="text-black-900 font-bold">Description :</p>
|
||||
<p className="text-gray-600 capitalize">{object.description}</p>
|
||||
</div>
|
||||
|
||||
<div className="mb-5">
|
||||
<p className="text-black-900 font-bold">Type :</p>
|
||||
<p className="text-gray-600 capitalize">{object.type}</p>
|
||||
</div>
|
||||
|
||||
<div className="mb-5">
|
||||
<p className="text-black-900 font-bold">Localisation :</p>
|
||||
<p className="text-gray-600">{object.location}</p>
|
||||
</div>
|
||||
|
||||
<div className="mb-5">
|
||||
<p className="text-black-900 font-bold">Status :</p>
|
||||
<p className="text-gray-600 capitalize">{object.status}</p>
|
||||
</div>
|
||||
|
||||
<div className="mb-5">
|
||||
<p className="text-black-900 font-bold">
|
||||
Derniere mise à jour :
|
||||
</p>
|
||||
<p className="text-gray-600">{object.last_update}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-4 mb-1">
|
||||
<a className="text-blue-500 hover:cursor-pointer" onClick={(()=>defafficherModif(true))}>Modifier ces infos</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default InfoObject;
|
||||
Loading…
Reference in New Issue
Block a user