This commit is contained in:
Laureηt 2022-05-29 14:38:02 +02:00
parent fbcdc11329
commit 9dc30fd47c
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
5 changed files with 9 additions and 18 deletions

View file

@ -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());

View file

@ -124,6 +124,11 @@
Modify pixel
<div>
<label>Solde</label>
<span class="solde"></span>
</div>
<form id="modify-form" method="post">
<div class="data">
<label>Price</label>

View file

@ -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");

View file

@ -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";

View file

@ -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");
}
});
}