ah
This commit is contained in:
parent
c552442029
commit
0b841e70a4
13 changed files with 620 additions and 103 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
package fr.epita.assistants.yakamon.data.model;
|
package fr.epita.assistants.yakamon.data.model;
|
||||||
|
|
||||||
import fr.epita.assistants.yakamon.utils.ElementType;
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package fr.epita.assistants.yakamon.domain.entity;
|
package fr.epita.assistants.yakamon.domain.entity;
|
||||||
|
|
||||||
import fr.epita.assistants.yakamon.utils.tile.ItemType;
|
import fr.epita.assistants.yakamon.utils.tile.ItemType;
|
||||||
import java.util.Objects;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
package fr.epita.assistants.yakamon.domain.entity;
|
package fr.epita.assistants.yakamon.domain.entity;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class PlayerEntity {
|
public class PlayerEntity {
|
||||||
|
|
||||||
|
public UUID uuid;
|
||||||
public String name;
|
public String name;
|
||||||
public Integer posX;
|
public Integer posX;
|
||||||
public Integer posY;
|
public Integer posY;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package fr.epita.assistants.yakamon.domain.service;
|
||||||
|
|
||||||
|
import fr.epita.assistants.yakamon.data.model.ItemModel;
|
||||||
|
import fr.epita.assistants.yakamon.data.repository.ItemRepository;
|
||||||
|
import fr.epita.assistants.yakamon.domain.entity.GameEntity;
|
||||||
|
import fr.epita.assistants.yakamon.utils.ErrorCode;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class InventoryService {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ItemRepository itemRepository;
|
||||||
|
|
||||||
|
public List<ItemModel> getInventory() {
|
||||||
|
if (GameEntity.INSTANCE == null || !GameEntity.INSTANCE.started) {
|
||||||
|
ErrorCode.GAME_NOT_STARTED.throwException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemRepository.listAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,13 +9,16 @@ import fr.epita.assistants.yakamon.data.repository.PlayerRepository;
|
||||||
import fr.epita.assistants.yakamon.data.repository.YakadexRepository;
|
import fr.epita.assistants.yakamon.data.repository.YakadexRepository;
|
||||||
import fr.epita.assistants.yakamon.data.repository.YakamonRepository;
|
import fr.epita.assistants.yakamon.data.repository.YakamonRepository;
|
||||||
import fr.epita.assistants.yakamon.domain.entity.GameEntity;
|
import fr.epita.assistants.yakamon.domain.entity.GameEntity;
|
||||||
|
import fr.epita.assistants.yakamon.domain.entity.PlayerEntity;
|
||||||
import fr.epita.assistants.yakamon.domain.entity.TileEntity;
|
import fr.epita.assistants.yakamon.domain.entity.TileEntity;
|
||||||
|
import fr.epita.assistants.yakamon.domain.entity.YakamonEntity;
|
||||||
import fr.epita.assistants.yakamon.utils.Direction;
|
import fr.epita.assistants.yakamon.utils.Direction;
|
||||||
import fr.epita.assistants.yakamon.utils.ErrorCode;
|
import fr.epita.assistants.yakamon.utils.ErrorCode;
|
||||||
import fr.epita.assistants.yakamon.utils.Point;
|
import fr.epita.assistants.yakamon.utils.Point;
|
||||||
import fr.epita.assistants.yakamon.utils.tile.Collectible;
|
import fr.epita.assistants.yakamon.utils.tile.Collectible;
|
||||||
import fr.epita.assistants.yakamon.utils.tile.CollectibleUtils;
|
import fr.epita.assistants.yakamon.utils.tile.CollectibleUtils;
|
||||||
import fr.epita.assistants.yakamon.utils.tile.ItemType;
|
import fr.epita.assistants.yakamon.utils.tile.ItemType;
|
||||||
|
import fr.epita.assistants.yakamon.utils.tile.TerrainType;
|
||||||
import fr.epita.assistants.yakamon.utils.tile.YakamonInfo;
|
import fr.epita.assistants.yakamon.utils.tile.YakamonInfo;
|
||||||
import fr.epita.assistants.yakamon.utils.tile.YakamonType;
|
import fr.epita.assistants.yakamon.utils.tile.YakamonType;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
|
@ -25,7 +28,8 @@ import jakarta.ws.rs.WebApplicationException;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.UUID;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class PlayerService {
|
public class PlayerService {
|
||||||
|
|
@ -92,7 +96,7 @@ public class PlayerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public YakamonModel catchYakamon() {
|
public YakamonEntity catchYakamon() {
|
||||||
if (GameEntity.INSTANCE == null || !GameEntity.INSTANCE.started) {
|
if (GameEntity.INSTANCE == null || !GameEntity.INSTANCE.started) {
|
||||||
ErrorCode.GAME_NOT_STARTED.throwException();
|
ErrorCode.GAME_NOT_STARTED.throwException();
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +187,12 @@ public class PlayerService {
|
||||||
player.lastCatch = LocalDateTime.now();
|
player.lastCatch = LocalDateTime.now();
|
||||||
playerRepository.persist(player);
|
playerRepository.persist(player);
|
||||||
|
|
||||||
return newYakamon;
|
return new YakamonEntity(
|
||||||
|
newYakamon.id,
|
||||||
|
newYakamon.nickname,
|
||||||
|
newYakamon.yakadex_entry_id.id,
|
||||||
|
newYakamon.energy_points
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkMovementDelay(PlayerModel player) {
|
private void checkMovementDelay(PlayerModel player) {
|
||||||
|
|
@ -237,4 +246,120 @@ public class PlayerService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkCollectDelay(PlayerModel player) {
|
||||||
|
String tickDurationStr = System.getenv("JWS_TICK_DURATION");
|
||||||
|
String collectDelayStr = System.getenv("JWS_COLLECT_DELAY");
|
||||||
|
|
||||||
|
if (tickDurationStr == null || collectDelayStr == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
long tickDuration = Long.parseLong(tickDurationStr);
|
||||||
|
long collectDelay = Long.parseLong(collectDelayStr);
|
||||||
|
long requiredDelay = tickDuration * collectDelay;
|
||||||
|
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
long elapsed = ChronoUnit.MILLIS.between(player.lastCollect, now);
|
||||||
|
|
||||||
|
if (elapsed < requiredDelay) {
|
||||||
|
throw new WebApplicationException(Response.status(429).build());
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException(
|
||||||
|
"Invalid environment variables"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public PlayerEntity getPlayerInfo() {
|
||||||
|
if (GameEntity.INSTANCE == null || !GameEntity.INSTANCE.started) {
|
||||||
|
ErrorCode.GAME_NOT_STARTED.throwException();
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerModel player = playerRepository.findAll().firstResult();
|
||||||
|
if (player == null) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException("Player not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PlayerEntity(
|
||||||
|
player.id,
|
||||||
|
player.name,
|
||||||
|
player.posX,
|
||||||
|
player.posY,
|
||||||
|
player.lastMove,
|
||||||
|
player.lastCatch,
|
||||||
|
player.lastCollect,
|
||||||
|
player.lastFeed
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Map<String, Object> collect() {
|
||||||
|
if (GameEntity.INSTANCE == null || !GameEntity.INSTANCE.started) {
|
||||||
|
ErrorCode.GAME_NOT_STARTED.throwException();
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerModel player = playerRepository.findAll().firstResult();
|
||||||
|
if (player == null) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException("Player not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
checkCollectDelay(player);
|
||||||
|
|
||||||
|
TileEntity[][] map = GameEntity.INSTANCE.map;
|
||||||
|
if (map == null) {
|
||||||
|
ErrorCode.INVALID_MAP.throwException("Map not loaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
int x = player.posX;
|
||||||
|
int y = player.posY;
|
||||||
|
|
||||||
|
if (y < 0 || y >= map.length || x < 0 || x >= map[y].length) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException("Invalid position");
|
||||||
|
}
|
||||||
|
|
||||||
|
TileEntity tile = map[y][x];
|
||||||
|
if (
|
||||||
|
tile == null || tile.collectible == null || tile.collectible == 'N'
|
||||||
|
) {
|
||||||
|
throw new WebApplicationException(
|
||||||
|
Response.status(400)
|
||||||
|
.entity("No collectible at this position")
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collectible collectible = CollectibleUtils.getCollectible(
|
||||||
|
tile.collectible
|
||||||
|
);
|
||||||
|
if (collectible instanceof ItemType) {
|
||||||
|
ItemType itemType = (ItemType) collectible;
|
||||||
|
ItemModel item = itemRepository
|
||||||
|
.find("type", itemType)
|
||||||
|
.firstResult();
|
||||||
|
if (item == null) {
|
||||||
|
item = new ItemModel();
|
||||||
|
item.type = itemType;
|
||||||
|
item.quantity = 1;
|
||||||
|
itemRepository.persist(item);
|
||||||
|
} else {
|
||||||
|
item.quantity += 1;
|
||||||
|
itemRepository.persist(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tile.collectible = 'N';
|
||||||
|
player.lastCollect = LocalDateTime.now();
|
||||||
|
playerRepository.persist(player);
|
||||||
|
|
||||||
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
Map<String, Object> tileData = new HashMap<>();
|
||||||
|
tileData.put("terrainType", TerrainType.getTerrain(tile.terrain));
|
||||||
|
tileData.put("collectible", collectible);
|
||||||
|
response.put("tileType", tileData);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,149 @@
|
||||||
package fr.epita.assistants.yakamon.domain.service;
|
package fr.epita.assistants.yakamon.domain.service;
|
||||||
|
|
||||||
public class TeamService {}
|
import fr.epita.assistants.yakamon.data.model.YakadexEntryModel;
|
||||||
|
import fr.epita.assistants.yakamon.data.model.YakamonModel;
|
||||||
|
import fr.epita.assistants.yakamon.data.repository.YakadexRepository;
|
||||||
|
import fr.epita.assistants.yakamon.data.repository.YakamonRepository;
|
||||||
|
import fr.epita.assistants.yakamon.domain.entity.GameEntity;
|
||||||
|
import fr.epita.assistants.yakamon.domain.entity.YakamonEntity;
|
||||||
|
import fr.epita.assistants.yakamon.utils.ErrorCode;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class TeamService {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
YakamonRepository yakamonRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
YakadexRepository yakadexRepository;
|
||||||
|
|
||||||
|
public List<YakamonEntity> getTeam() {
|
||||||
|
if (GameEntity.INSTANCE == null || !GameEntity.INSTANCE.started) {
|
||||||
|
ErrorCode.GAME_NOT_STARTED.throwException();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<YakamonModel> models = yakamonRepository.listAll();
|
||||||
|
List<YakamonEntity> entities = new ArrayList<>();
|
||||||
|
|
||||||
|
for (YakamonModel model : models) {
|
||||||
|
entities.add(
|
||||||
|
new YakamonEntity(
|
||||||
|
model.id,
|
||||||
|
model.nickname,
|
||||||
|
model.yakadex_entry_id.id,
|
||||||
|
model.energy_points
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public YakamonEntity evolve(UUID uuid) {
|
||||||
|
if (GameEntity.INSTANCE == null || !GameEntity.INSTANCE.started) {
|
||||||
|
ErrorCode.GAME_NOT_STARTED.throwException();
|
||||||
|
}
|
||||||
|
|
||||||
|
YakamonModel yakamon = yakamonRepository.find("id", uuid).firstResult();
|
||||||
|
if (yakamon == null) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException("Yakamon not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
YakadexEntryModel entry = yakamon.yakadex_entry_id;
|
||||||
|
if (entry.evolution_id == null) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException("This yakamon cannot evolve");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (yakamon.energy_points < entry.evolve_threshold) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException(
|
||||||
|
"Not enough energy points to evolve"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
YakadexEntryModel evolution = yakadexRepository
|
||||||
|
.find("id", entry.evolution_id.id)
|
||||||
|
.firstResult();
|
||||||
|
yakamon.yakadex_entry_id = evolution;
|
||||||
|
yakamonRepository.persist(yakamon);
|
||||||
|
|
||||||
|
return new YakamonEntity(
|
||||||
|
yakamon.id,
|
||||||
|
yakamon.nickname,
|
||||||
|
yakamon.yakadex_entry_id.id,
|
||||||
|
yakamon.energy_points
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public YakamonEntity feed(UUID uuid, Integer quantity) {
|
||||||
|
if (GameEntity.INSTANCE == null || !GameEntity.INSTANCE.started) {
|
||||||
|
ErrorCode.GAME_NOT_STARTED.throwException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quantity == null || quantity <= 0) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException("Invalid quantity");
|
||||||
|
}
|
||||||
|
|
||||||
|
YakamonModel yakamon = yakamonRepository.find("id", uuid).firstResult();
|
||||||
|
if (yakamon == null) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException("Yakamon not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
yakamon.energy_points += quantity;
|
||||||
|
yakamonRepository.persist(yakamon);
|
||||||
|
|
||||||
|
return new YakamonEntity(
|
||||||
|
yakamon.id,
|
||||||
|
yakamon.nickname,
|
||||||
|
yakamon.yakadex_entry_id.id,
|
||||||
|
yakamon.energy_points
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void release(UUID uuid) {
|
||||||
|
if (GameEntity.INSTANCE == null || !GameEntity.INSTANCE.started) {
|
||||||
|
ErrorCode.GAME_NOT_STARTED.throwException();
|
||||||
|
}
|
||||||
|
|
||||||
|
YakamonModel yakamon = yakamonRepository.find("id", uuid).firstResult();
|
||||||
|
if (yakamon == null) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException("Yakamon not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
yakamonRepository.delete(yakamon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public YakamonEntity rename(UUID uuid, String newName) {
|
||||||
|
if (GameEntity.INSTANCE == null || !GameEntity.INSTANCE.started) {
|
||||||
|
ErrorCode.GAME_NOT_STARTED.throwException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newName == null || newName.isBlank()) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException("Invalid name");
|
||||||
|
}
|
||||||
|
|
||||||
|
YakamonModel yakamon = yakamonRepository.find("id", uuid).firstResult();
|
||||||
|
if (yakamon == null) {
|
||||||
|
ErrorCode.BAD_REQUEST.throwException("Yakamon not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
yakamon.nickname = newName;
|
||||||
|
yakamonRepository.persist(yakamon);
|
||||||
|
|
||||||
|
return new YakamonEntity(
|
||||||
|
yakamon.id,
|
||||||
|
yakamon.nickname,
|
||||||
|
yakamon.yakadex_entry_id.id,
|
||||||
|
yakamon.energy_points
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,8 @@ package fr.epita.assistants.yakamon.domain.service;
|
||||||
|
|
||||||
import fr.epita.assistants.yakamon.data.model.YakadexEntryModel;
|
import fr.epita.assistants.yakamon.data.model.YakadexEntryModel;
|
||||||
import fr.epita.assistants.yakamon.data.repository.YakadexRepository;
|
import fr.epita.assistants.yakamon.data.repository.YakadexRepository;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.YakadexEntry;
|
import fr.epita.assistants.yakamon.domain.entity.YakadexEntryEntity;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.YakadexAllInfosResponse;
|
import fr.epita.assistants.yakamon.utils.ElementType;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.YakadexInfosResponse;
|
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -16,7 +15,7 @@ public class YakadexService {
|
||||||
@Inject
|
@Inject
|
||||||
YakadexRepository yakadexRepository;
|
YakadexRepository yakadexRepository;
|
||||||
|
|
||||||
public YakadexAllInfosResponse getAllEntries(Boolean onlyMissing) {
|
public List<YakadexEntryEntity> getAllEntries(Boolean onlyMissing) {
|
||||||
List<YakadexEntryModel> entries;
|
List<YakadexEntryModel> entries;
|
||||||
|
|
||||||
if (onlyMissing != null && onlyMissing) {
|
if (onlyMissing != null && onlyMissing) {
|
||||||
|
|
@ -25,25 +24,29 @@ public class YakadexService {
|
||||||
entries = yakadexRepository.listAll();
|
entries = yakadexRepository.listAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<YakadexEntry> dtos = new ArrayList<>();
|
List<YakadexEntryEntity> entities = new ArrayList<>();
|
||||||
for (YakadexEntryModel entry : entries) {
|
for (YakadexEntryModel entry : entries) {
|
||||||
YakadexEntry dto = new YakadexInfosResponse(
|
YakadexEntryEntity entity = new YakadexEntryEntity(
|
||||||
entry.id,
|
entry.id,
|
||||||
entry.name,
|
entry.name,
|
||||||
entry.first_type,
|
entry.first_type != null
|
||||||
entry.second_type,
|
? ElementType.valueOf(entry.first_type)
|
||||||
|
: null,
|
||||||
|
entry.second_type != null
|
||||||
|
? ElementType.valueOf(entry.second_type)
|
||||||
|
: null,
|
||||||
entry.evolve_threshold,
|
entry.evolve_threshold,
|
||||||
null,
|
null,
|
||||||
entry.caught,
|
entry.caught,
|
||||||
entry.description
|
entry.description
|
||||||
);
|
);
|
||||||
dtos.add(dto);
|
entities.add(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new YakadexAllInfosResponse(dtos.toArray(new YakadexEntry[0]));
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public YakadexInfosResponse getEntryById(Integer id) {
|
public YakadexEntryEntity getEntryById(Integer id) {
|
||||||
YakadexEntryModel entry = yakadexRepository
|
YakadexEntryModel entry = yakadexRepository
|
||||||
.find("id = ?1", id)
|
.find("id = ?1", id)
|
||||||
.firstResult();
|
.firstResult();
|
||||||
|
|
@ -52,11 +55,15 @@ public class YakadexService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new YakadexInfosResponse(
|
return new YakadexEntryEntity(
|
||||||
entry.id,
|
entry.id,
|
||||||
entry.name,
|
entry.name,
|
||||||
entry.first_type,
|
entry.first_type != null
|
||||||
entry.second_type,
|
? ElementType.valueOf(entry.first_type)
|
||||||
|
: null,
|
||||||
|
entry.second_type != null
|
||||||
|
? ElementType.valueOf(entry.second_type)
|
||||||
|
: null,
|
||||||
entry.evolve_threshold,
|
entry.evolve_threshold,
|
||||||
null,
|
null,
|
||||||
entry.caught,
|
entry.caught,
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,22 @@
|
||||||
package fr.epita.assistants.yakamon.presentation.rest;
|
package fr.epita.assistants.yakamon.presentation.rest;
|
||||||
|
|
||||||
import fr.epita.assistants.yakamon.domain.entity.GameEntity;
|
import fr.epita.assistants.yakamon.domain.entity.GameEntity;
|
||||||
|
import fr.epita.assistants.yakamon.domain.entity.TileEntity;
|
||||||
import fr.epita.assistants.yakamon.domain.service.GameService;
|
import fr.epita.assistants.yakamon.domain.service.GameService;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.request.StartGameRequest;
|
import fr.epita.assistants.yakamon.presentation.api.request.StartGameRequest;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.StartGameResponse;
|
import fr.epita.assistants.yakamon.utils.tile.Collectible;
|
||||||
|
import fr.epita.assistants.yakamon.utils.tile.CollectibleUtils;
|
||||||
|
import fr.epita.assistants.yakamon.utils.tile.ItemType;
|
||||||
|
import fr.epita.assistants.yakamon.utils.tile.YakamonType;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
import jakarta.ws.rs.POST;
|
import jakarta.ws.rs.POST;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@Path("/start")
|
@Path("/start")
|
||||||
|
|
@ -21,6 +28,9 @@ public class GameResource {
|
||||||
GameResource.class.getName()
|
GameResource.class.getName()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GameService gameService;
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
public Response start(StartGameRequest request) {
|
public Response start(StartGameRequest request) {
|
||||||
|
|
@ -48,24 +58,87 @@ public class GameResource {
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GameService gameService = new GameService();
|
gameService.startGame(request.mapPath, request.playerName);
|
||||||
GameEntity startedGame = gameService.startGame(
|
LOGGER.info("Game started successfully");
|
||||||
request.mapPath,
|
|
||||||
request.playerName
|
|
||||||
);
|
|
||||||
LOGGER.info(
|
|
||||||
"Game started at: " +
|
|
||||||
(startedGame != null ? startedGame.startTime : "unknown")
|
|
||||||
);
|
|
||||||
|
|
||||||
// StartGameResponse response = new StartGameResponse();
|
TileEntity[][] map = GameEntity.INSTANCE.map;
|
||||||
// return Response.ok(response).build();
|
Map<String, Object>[][] tiles = new Map[map.length][];
|
||||||
return Response.ok().build();
|
|
||||||
|
for (int y = 0; y < map.length; y++) {
|
||||||
|
tiles[y] = new Map[map[y].length];
|
||||||
|
for (int x = 0; x < map[y].length; x++) {
|
||||||
|
TileEntity tile = map[y][x];
|
||||||
|
Map<String, Object> tileData = new HashMap<>();
|
||||||
|
tileData.put("terrainType", getTerrainType(tile.terrain));
|
||||||
|
|
||||||
|
Map<String, Object> collectibleData = new HashMap<>();
|
||||||
|
String collectibleType = getCollectibleType(
|
||||||
|
tile.collectible
|
||||||
|
);
|
||||||
|
String collectibleValue = getCollectibleValue(
|
||||||
|
tile.collectible
|
||||||
|
);
|
||||||
|
|
||||||
|
if (collectibleType != null) {
|
||||||
|
collectibleData.put("type", collectibleType);
|
||||||
|
collectibleData.put("value", collectibleValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
tileData.put("collectible", collectibleData);
|
||||||
|
tiles[y][x] = tileData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
response.put("tiles", tiles);
|
||||||
|
return Response.ok(response).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Response.status(
|
LOGGER.severe("Failed to start game: " + e.getMessage());
|
||||||
400,
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
"Invalid path or invalid name provided."
|
.entity("Invalid path or invalid name provided.")
|
||||||
).build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getTerrainType(Character terrain) {
|
||||||
|
return switch (terrain) {
|
||||||
|
case 'G' -> "GRASS";
|
||||||
|
case 'M' -> "MOUNTAIN";
|
||||||
|
case 'R' -> "ROCK";
|
||||||
|
case 'S' -> "SAND";
|
||||||
|
case 'W' -> "WATER";
|
||||||
|
case 'L' -> "LAVA";
|
||||||
|
default -> "GRASS";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCollectibleType(Character collectible) {
|
||||||
|
if (collectible == 'N') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collectible c = CollectibleUtils.getCollectible(collectible);
|
||||||
|
if (c instanceof ItemType) {
|
||||||
|
return "ITEM";
|
||||||
|
} else if (c instanceof YakamonType) {
|
||||||
|
return "YAKAMON";
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCollectibleValue(Character collectible) {
|
||||||
|
if (collectible == 'N') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collectible c = CollectibleUtils.getCollectible(collectible);
|
||||||
|
if (c instanceof ItemType) {
|
||||||
|
return ((ItemType) c).name();
|
||||||
|
} else if (c instanceof YakamonType) {
|
||||||
|
return ((YakamonType) c).name();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
package fr.epita.assistants.yakamon.presentation.rest;
|
|
||||||
|
|
||||||
import jakarta.ws.rs.*;
|
|
||||||
import jakarta.ws.rs.core.MediaType;
|
|
||||||
|
|
||||||
@Path("/hello")
|
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
|
||||||
@Consumes(MediaType.TEXT_PLAIN)
|
|
||||||
public class HelloWorldResource {
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/")
|
|
||||||
public String helloWorld() {
|
|
||||||
return "Hello, world!";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{name}")
|
|
||||||
public String helloWorld(@PathParam("name") String name) {
|
|
||||||
return "Hello " + name + "!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +1,29 @@
|
||||||
package fr.epita.assistants.yakamon.presentation.rest;
|
package fr.epita.assistants.yakamon.presentation.rest;
|
||||||
|
|
||||||
|
import fr.epita.assistants.yakamon.data.model.ItemModel;
|
||||||
import fr.epita.assistants.yakamon.domain.service.GameService;
|
import fr.epita.assistants.yakamon.domain.service.GameService;
|
||||||
|
import fr.epita.assistants.yakamon.domain.service.InventoryService;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.GetInventoryResponse;
|
import fr.epita.assistants.yakamon.presentation.api.response.GetInventoryResponse;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Path("/inventory")
|
@Path("/inventory")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public class InventoryResource {
|
public class InventoryResource {
|
||||||
|
|
||||||
private final GameService gameService = new GameService();
|
@Inject
|
||||||
|
private GameService gameService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private InventoryService inventoryService;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public Response getInventory() {
|
public Response getInventory() {
|
||||||
|
|
@ -23,9 +32,30 @@ public class InventoryResource {
|
||||||
.entity("Game not started")
|
.entity("Game not started")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
// TODO service
|
|
||||||
// GetInventoryResponse response = inventoryService.getInventory();
|
try {
|
||||||
// return Response.ok(response).build();
|
List<ItemModel> items = inventoryService.getInventory();
|
||||||
return Response.status(Response.Status.NOT_IMPLEMENTED).build();
|
List<GetInventoryResponse.Items> responseItems = new ArrayList<>();
|
||||||
|
GetInventoryResponse temp = new GetInventoryResponse(responseItems);
|
||||||
|
|
||||||
|
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();
|
||||||
|
responseItem.itemType = itemType;
|
||||||
|
responseItem.quantity = item.quantity;
|
||||||
|
responseItems.add(responseItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
GetInventoryResponse response = new GetInventoryResponse(
|
||||||
|
responseItems
|
||||||
|
);
|
||||||
|
return Response.ok(response).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(e.getMessage())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
package fr.epita.assistants.yakamon.presentation.rest;
|
package fr.epita.assistants.yakamon.presentation.rest;
|
||||||
|
|
||||||
|
import fr.epita.assistants.yakamon.domain.entity.YakamonEntity;
|
||||||
import fr.epita.assistants.yakamon.domain.service.GameService;
|
import fr.epita.assistants.yakamon.domain.service.GameService;
|
||||||
import fr.epita.assistants.yakamon.domain.service.PlayerService;
|
import fr.epita.assistants.yakamon.domain.service.PlayerService;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.request.PlayerMoveRequest;
|
import fr.epita.assistants.yakamon.presentation.api.request.PlayerMoveRequest;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.GetInventoryResponse;
|
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.PlayerCatchResponse;
|
import fr.epita.assistants.yakamon.presentation.api.response.PlayerCatchResponse;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.PlayerCollectResponse;
|
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.PlayerInfosResponse;
|
import fr.epita.assistants.yakamon.presentation.api.response.PlayerInfosResponse;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.PlayerMoveResponse;
|
import fr.epita.assistants.yakamon.presentation.api.response.PlayerMoveResponse;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
|
@ -34,12 +34,12 @@ public class PlayerResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var yakamon = playerService.catchYakamon();
|
YakamonEntity yakamon = playerService.catchYakamon();
|
||||||
var response = new PlayerCatchResponse(
|
var response = new PlayerCatchResponse(
|
||||||
yakamon.id.toString(),
|
yakamon.uuid.toString(),
|
||||||
yakamon.nickname,
|
yakamon.nickname,
|
||||||
yakamon.yakadex_entry_id.id,
|
yakamon.yakadexId,
|
||||||
yakamon.energy_points
|
yakamon.energyPoints
|
||||||
);
|
);
|
||||||
return Response.ok(response).build();
|
return Response.ok(response).build();
|
||||||
} catch (jakarta.ws.rs.WebApplicationException e) {
|
} catch (jakarta.ws.rs.WebApplicationException e) {
|
||||||
|
|
@ -59,8 +59,17 @@ public class PlayerResource {
|
||||||
.entity("Game not started")
|
.entity("Game not started")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
// TODO service
|
|
||||||
return Response.status(Response.Status.NOT_IMPLEMENTED).build();
|
try {
|
||||||
|
var tileData = playerService.collect();
|
||||||
|
return Response.ok(tileData).build();
|
||||||
|
} catch (jakarta.ws.rs.WebApplicationException e) {
|
||||||
|
return e.getResponse();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(e.getMessage())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
|
@ -103,9 +112,34 @@ public class PlayerResource {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO service
|
try {
|
||||||
// PlayerInfosResponse response = playerService.getInfos(...);
|
var player = playerService.getPlayerInfo();
|
||||||
// return Response.ok(response).build();
|
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
||||||
return Response.status(Response.Status.NOT_IMPLEMENTED).build();
|
var response = new PlayerInfosResponse(
|
||||||
|
player.uuid.toString(),
|
||||||
|
player.name,
|
||||||
|
player.posX,
|
||||||
|
player.posY,
|
||||||
|
player.lastMove != null
|
||||||
|
? player.lastMove.format(formatter)
|
||||||
|
: null,
|
||||||
|
player.lastCatch != null
|
||||||
|
? player.lastCatch.format(formatter)
|
||||||
|
: null,
|
||||||
|
player.lastCollect != null
|
||||||
|
? player.lastCollect.format(formatter)
|
||||||
|
: null,
|
||||||
|
player.lastFeed != null
|
||||||
|
? player.lastFeed.format(formatter)
|
||||||
|
: null
|
||||||
|
);
|
||||||
|
return Response.ok(response).build();
|
||||||
|
} catch (jakarta.ws.rs.WebApplicationException e) {
|
||||||
|
return e.getResponse();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(e.getMessage())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,32 @@
|
||||||
package fr.epita.assistants.yakamon.presentation.rest;
|
package fr.epita.assistants.yakamon.presentation.rest;
|
||||||
|
|
||||||
|
import fr.epita.assistants.yakamon.converter.EntityToDtoConverter;
|
||||||
|
import fr.epita.assistants.yakamon.domain.entity.YakamonEntity;
|
||||||
import fr.epita.assistants.yakamon.domain.service.GameService;
|
import fr.epita.assistants.yakamon.domain.service.GameService;
|
||||||
|
import fr.epita.assistants.yakamon.domain.service.TeamService;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.request.TeamFeedRequest;
|
import fr.epita.assistants.yakamon.presentation.api.request.TeamFeedRequest;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.request.TeamRenameRequest;
|
import fr.epita.assistants.yakamon.presentation.api.request.TeamRenameRequest;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.TeamEvolveResponse;
|
import fr.epita.assistants.yakamon.presentation.api.response.TeamEvolveResponse;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.TeamFeedResponse;
|
import fr.epita.assistants.yakamon.presentation.api.response.TeamFeedResponse;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.TeamInfosResponse;
|
import fr.epita.assistants.yakamon.presentation.api.response.TeamInfosResponse;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.TeamRenameResponse;
|
import fr.epita.assistants.yakamon.presentation.api.response.TeamRenameResponse;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Path("/team")
|
@Path("/team")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public class TeamResource {
|
public class TeamResource {
|
||||||
|
|
||||||
private final GameService gameService = new GameService();
|
@Inject
|
||||||
|
private GameService gameService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private TeamService teamService;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public Response getTeam() {
|
public Response getTeam() {
|
||||||
|
|
@ -25,10 +35,21 @@ public class TeamResource {
|
||||||
.entity("Game not started")
|
.entity("Game not started")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
// TODO service
|
|
||||||
// TeamInfosResponse response = new TeamInfosResponse();
|
try {
|
||||||
// return Response.ok(response).build();
|
List<YakamonEntity> team = teamService.getTeam();
|
||||||
return Response.ok().build();
|
var actions = EntityToDtoConverter.toYakamonActions(team);
|
||||||
|
TeamInfosResponse response = new TeamInfosResponse(
|
||||||
|
actions.toArray(
|
||||||
|
new fr.epita.assistants.yakamon.presentation.api.YakamonAction[0]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return Response.ok(response).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(e.getMessage())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
|
@ -45,10 +66,26 @@ public class TeamResource {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO service
|
try {
|
||||||
// TeamEvolveResponse response = new TeamEvolveResponse();
|
UUID yakemonId = UUID.fromString(uuid);
|
||||||
// return Response.ok(response).build();
|
YakamonEntity evolved = teamService.evolve(yakemonId);
|
||||||
return Response.ok().build();
|
var action = EntityToDtoConverter.toYakamonAction(evolved);
|
||||||
|
TeamEvolveResponse response = new TeamEvolveResponse(
|
||||||
|
action.uuid,
|
||||||
|
action.nickname,
|
||||||
|
action.yakadexId,
|
||||||
|
action.energyPoints
|
||||||
|
);
|
||||||
|
return Response.ok(response).build();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity("Invalid uuid format")
|
||||||
|
.build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(e.getMessage())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
|
@ -75,10 +112,26 @@ public class TeamResource {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO service
|
try {
|
||||||
// TeamFeedResponse response = new TeamFeedResponse();
|
UUID yakemonId = UUID.fromString(uuid);
|
||||||
// return Response.ok(response).build();
|
YakamonEntity fed = teamService.feed(yakemonId, request.quantity);
|
||||||
return Response.ok().build();
|
var action = EntityToDtoConverter.toYakamonAction(fed);
|
||||||
|
TeamFeedResponse response = new TeamFeedResponse(
|
||||||
|
action.uuid,
|
||||||
|
action.nickname,
|
||||||
|
action.yakadexId,
|
||||||
|
action.energyPoints
|
||||||
|
);
|
||||||
|
return Response.ok(response).build();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity("Invalid uuid format")
|
||||||
|
.build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(e.getMessage())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
|
|
@ -95,9 +148,19 @@ public class TeamResource {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO service
|
try {
|
||||||
// return 204 (No Content) to match the subject
|
UUID yakemonId = UUID.fromString(uuid);
|
||||||
return Response.noContent().build();
|
teamService.release(yakemonId);
|
||||||
|
return Response.noContent().build();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity("Invalid uuid format")
|
||||||
|
.build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(e.getMessage())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PATCH
|
@PATCH
|
||||||
|
|
@ -116,15 +179,38 @@ public class TeamResource {
|
||||||
.entity("Missing or invalid uuid")
|
.entity("Missing or invalid uuid")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
if (request == null) {
|
if (
|
||||||
|
request == null ||
|
||||||
|
request.newNickname == null ||
|
||||||
|
request.newNickname.isBlank()
|
||||||
|
) {
|
||||||
return Response.status(Response.Status.BAD_REQUEST)
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
.entity("Missing request body")
|
.entity("Missing or invalid name")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO service
|
try {
|
||||||
// TeamRenameResponse response = new TeamRenameResponse();
|
UUID yakemonId = UUID.fromString(uuid);
|
||||||
// return Response.ok(response).build();
|
YakamonEntity renamed = teamService.rename(
|
||||||
return Response.ok().build();
|
yakemonId,
|
||||||
|
request.newNickname
|
||||||
|
);
|
||||||
|
var action = EntityToDtoConverter.toYakamonAction(renamed);
|
||||||
|
TeamRenameResponse response = new TeamRenameResponse(
|
||||||
|
action.uuid,
|
||||||
|
action.nickname,
|
||||||
|
action.yakadexId,
|
||||||
|
action.energyPoints
|
||||||
|
);
|
||||||
|
return Response.ok(response).build();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity("Invalid uuid format")
|
||||||
|
.build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(e.getMessage())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
package fr.epita.assistants.yakamon.presentation.rest;
|
package fr.epita.assistants.yakamon.presentation.rest;
|
||||||
|
|
||||||
|
import fr.epita.assistants.yakamon.converter.EntityToDtoConverter;
|
||||||
|
import fr.epita.assistants.yakamon.domain.entity.YakadexEntryEntity;
|
||||||
import fr.epita.assistants.yakamon.domain.service.GameService;
|
import fr.epita.assistants.yakamon.domain.service.GameService;
|
||||||
import fr.epita.assistants.yakamon.domain.service.YakadexService;
|
import fr.epita.assistants.yakamon.domain.service.YakadexService;
|
||||||
|
import fr.epita.assistants.yakamon.presentation.api.YakadexEntry;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.YakadexAllInfosResponse;
|
import fr.epita.assistants.yakamon.presentation.api.response.YakadexAllInfosResponse;
|
||||||
import fr.epita.assistants.yakamon.presentation.api.response.YakadexInfosResponse;
|
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Path("/yakadex")
|
@Path("/yakadex")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
|
@ -30,9 +33,15 @@ public class YakadexResource {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
YakadexAllInfosResponse response = yakadexService.getAllEntries(
|
List<YakadexEntryEntity> entries = yakadexService.getAllEntries(
|
||||||
onlyMissing
|
onlyMissing
|
||||||
);
|
);
|
||||||
|
List<YakadexEntry> dtos = EntityToDtoConverter.toYakadexEntries(
|
||||||
|
entries
|
||||||
|
);
|
||||||
|
YakadexAllInfosResponse response = new YakadexAllInfosResponse(
|
||||||
|
dtos.toArray(new YakadexEntry[0])
|
||||||
|
);
|
||||||
return Response.ok(response).build();
|
return Response.ok(response).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,12 +54,13 @@ public class YakadexResource {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
YakadexInfosResponse response = yakadexService.getEntryById(id);
|
YakadexEntryEntity entry = yakadexService.getEntryById(id);
|
||||||
|
|
||||||
if (response == null) {
|
if (entry == null) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response.ok(response).build();
|
YakadexEntry dto = EntityToDtoConverter.toYakadexEntry(entry);
|
||||||
|
return Response.ok(dto).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue