trop tard

This commit is contained in:
Gu://em_ 2026-04-04 00:01:13 +02:00
parent 0b841e70a4
commit e1301f007b
4 changed files with 37 additions and 13 deletions

View file

@ -9,10 +9,34 @@ public class ItemModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;
private Integer id;
@Enumerated
public ItemType type;
private ItemType type;
public Integer quantity;
private Integer quantity;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public ItemType getType() {
return type;
}
public void setType(ItemType type) {
this.type = type;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
}

View file

@ -59,8 +59,8 @@ public class GameService {
// Initialize player inventory
ItemModel yakaballs = new ItemModel();
yakaballs.type = ItemType.YAKABALL;
yakaballs.quantity = 5;
yakaballs.setType(ItemType.YAKABALL);
yakaballs.setQuantity(5);
// Store
playerRepository.persist(player);

View file

@ -145,7 +145,7 @@ public class PlayerService {
ItemModel yakaballItem = itemRepository
.find("type", ItemType.YAKABALL)
.firstResult();
if (yakaballItem == null || yakaballItem.quantity < 1) {
if (yakaballItem == null || yakaballItem.getQuantity() < 1) {
throw new WebApplicationException(
Response.status(400).entity("Not enough Yakaballs").build()
);
@ -170,7 +170,7 @@ public class PlayerService {
ErrorCode.BAD_REQUEST.throwException("Yakamon species not found");
}
yakaballItem.quantity -= 1;
yakaballItem.setQuantity(yakaballItem.getQuantity() - 1);
itemRepository.persist(yakaballItem);
YakamonModel newYakamon = new YakamonModel();
@ -342,11 +342,11 @@ public class PlayerService {
.firstResult();
if (item == null) {
item = new ItemModel();
item.type = itemType;
item.quantity = 1;
item.setType(itemType);
item.setQuantity(1);
itemRepository.persist(item);
} else {
item.quantity += 1;
item.setQuantity(item.getQuantity() + 1);
itemRepository.persist(item);
}
}

View file

@ -41,10 +41,10 @@ public class InventoryResource {
for (ItemModel item : items) {
GetInventoryResponse.Items responseItem = temp.new Items();
GetInventoryResponse.ItemType itemType = temp.new ItemType();
itemType.type = item.type.name();
itemType.value = item.type.name();
itemType.type = item.getType().name();
itemType.value = item.getType().name();
responseItem.itemType = itemType;
responseItem.quantity = item.quantity;
responseItem.quantity = item.getQuantity();
responseItems.add(responseItem);
}