From 9dc30fd47c0c3dcea25fffd6cd06a9c27793d70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Sun, 29 May 2022 14:38:02 +0200 Subject: [PATCH] f5 ! --- src/main/java/com/pixels/services/PixelService.java | 12 +----------- src/main/webapp/index.html | 5 +++++ src/main/webapp/js/loaded.js | 2 +- src/main/webapp/js/pixels.js | 2 +- src/main/webapp/js/user.js | 6 +----- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/pixels/services/PixelService.java b/src/main/java/com/pixels/services/PixelService.java index 439b32a..14c5a13 100644 --- a/src/main/java/com/pixels/services/PixelService.java +++ b/src/main/java/com/pixels/services/PixelService.java @@ -58,17 +58,6 @@ public class PixelService { } } - @PUT - @Path("{id}") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public String update(@PathParam("id") Long id, String json) { - Pixel pixel = gson.fromJson(json, Pixel.class); - pixel.setId(id); - em.merge(pixel); - return gson.toJson(pixel); - } - @POST @Path("{id}/buy/") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @@ -82,6 +71,7 @@ public class PixelService { if (user.getBalance() >= pixel.getPrice()) { // on update l'owner pixel.setOwner(user); + user.setBalance(user.getBalance() - pixel.getPrice()); // on ajoute la transaction Date now = new Date(System.currentTimeMillis()); diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index d7fec4b..bfab3e9 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -124,6 +124,11 @@ Modify pixel +
+ + +
+
diff --git a/src/main/webapp/js/loaded.js b/src/main/webapp/js/loaded.js index 758f95b..f788543 100644 --- a/src/main/webapp/js/loaded.js +++ b/src/main/webapp/js/loaded.js @@ -29,7 +29,7 @@ function pageLoaded() { fetch(event.target.action, { method: event.target.method, body: new URLSearchParams(new FormData(event.target)), - }).then((resp) => { + }).then(async (resp) => { if (resp.ok) { userLogin(); togglePopup("signup"); diff --git a/src/main/webapp/js/pixels.js b/src/main/webapp/js/pixels.js index a07abc1..91db4e4 100644 --- a/src/main/webapp/js/pixels.js +++ b/src/main/webapp/js/pixels.js @@ -103,7 +103,7 @@ function updateBuyForm(pixel) { description.innerHTML = pixel.description; price = document.getElementById("info-price"); - price.innerHTML = pixel.price; + price.innerHTML = pixel.price + " ₹"; form = document.getElementById("buy-form"); form.action = urlPixel + pixel.id + "/buy"; diff --git a/src/main/webapp/js/user.js b/src/main/webapp/js/user.js index a671519..0bc3d7c 100644 --- a/src/main/webapp/js/user.js +++ b/src/main/webapp/js/user.js @@ -73,15 +73,11 @@ function userLogout() { async function updateSolde() { fetch(urlUser).then(async (resp) => { if (resp.ok) { - console.log("ici"); user = await resp.json(); - console.log("là"); - let soldes = document.getElementsByClassName("solde"); for (element of soldes) { - element.innerHTML = user.balance + " €"; + element.innerHTML = user.balance + " ₹"; } - console.log("ok"); } }); }