fix: recrediter l'ancien proprio

Co-authored-by: pejour <pejour@users.noreply.github.com>
Co-authored-by: Tom Heurtebise <theurt@users.noreply.github.com>
This commit is contained in:
gdamms 2022-06-01 14:17:02 +02:00
parent 1dd63ac090
commit 8850924f19

View file

@ -68,6 +68,11 @@ public class PixelService {
User user = User.fromSessionID(cookie.getValue(), em);
if (user.getBalance() >= pixel.getPrice()) {
// crediter l'argent a l'ancien owner
User previousOwner = pixel.getOwner();
if (previousOwner != null)
previousOwner.setBalance(previousOwner.getBalance() + pixel.getPrice());
// on update l'owner
pixel.setOwner(user);
user.setBalance(user.getBalance() - pixel.getPrice());