|
|
@ -23,7 +23,7 @@ namespace ApiLeapHit.Controllers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
public async Task<ActionResult<DTOPlayer>> GetPlayer(int id)
|
|
|
|
public async Task<ActionResult<ApiResponse<DTOPlayer>>> GetPlayer(int id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -66,24 +66,25 @@ namespace ApiLeapHit.Controllers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var player = dtoPlayer.ToPlayer();
|
|
|
|
var player = dtoPlayer.ToPlayer();
|
|
|
|
|
|
|
|
|
|
|
|
await _dataManager.AddPlayer(player);
|
|
|
|
await _dataManager.AddPlayer(player);
|
|
|
|
|
|
|
|
|
|
|
|
// Ajout des liens HATEOAS
|
|
|
|
// Ajout des liens HATEOAS
|
|
|
|
var response = new ApiResponse<object>("Joueur ajouté avec succès.");
|
|
|
|
var response = new ApiResponse<DTOPlayer>("Joueur ajouté avec succès.");
|
|
|
|
response.Links.Add(new ApiLink(
|
|
|
|
response.Links.Add(new ApiLink(
|
|
|
|
Url.Action("GetPlayer", "Player", new { id = player.playerId }),
|
|
|
|
Url.Action("GetPlayer", "Player", new { id = player.playerId }),
|
|
|
|
"self",
|
|
|
|
"self",
|
|
|
|
"GET"
|
|
|
|
"GET"
|
|
|
|
));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var response2 = new ApiResponse<object>("Joueur ajouté avec succès.");
|
|
|
|
return Ok(response);
|
|
|
|
return Ok(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Une erreur est survenue lors de l'ajout du joueur.");
|
|
|
|
_logger.LogError(ex, "Une erreur est survenue lors de l'ajout du joueur.");
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse<object>("Une erreur est survenue lors de l'ajout du joueur."));
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse<object>($"Une erreur est survenue lors de l'ajout du joueur. {ex.Message}"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -103,35 +104,35 @@ namespace ApiLeapHit.Controllers
|
|
|
|
var response = new ApiResponse<IEnumerable<DTOPlayer>>($"La récupération des players a réussi. Nombre de players : {dtoPlayers.Count}", dtoPlayers);
|
|
|
|
var response = new ApiResponse<IEnumerable<DTOPlayer>>($"La récupération des players a réussi. Nombre de players : {dtoPlayers.Count}", dtoPlayers);
|
|
|
|
|
|
|
|
|
|
|
|
// Ajout des liens HATEOAS
|
|
|
|
// Ajout des liens HATEOAS
|
|
|
|
response.Links.Add(new ApiLink(
|
|
|
|
//response.Links.Add(new ApiLink(
|
|
|
|
Url.Action("GetPlayers", "Player"),
|
|
|
|
// Url.Action("GetPlayers", "Player"),
|
|
|
|
"self",
|
|
|
|
// "self",
|
|
|
|
"GET"
|
|
|
|
// "GET"
|
|
|
|
));
|
|
|
|
//));
|
|
|
|
response.Links.Add(new ApiLink(
|
|
|
|
//response.Links.Add(new ApiLink(
|
|
|
|
Url.Action("AddPlayer", "Player"),
|
|
|
|
// Url.Action("AddPlayer", "Player"),
|
|
|
|
"create",
|
|
|
|
// "create",
|
|
|
|
"POST"
|
|
|
|
// "POST"
|
|
|
|
));
|
|
|
|
//));
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var player in dtoPlayers)
|
|
|
|
//foreach (var player in dtoPlayers)
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
response.Links.Add(new ApiLink(
|
|
|
|
// response.Links.Add(new ApiLink(
|
|
|
|
Url.Action("GetPlayer", "Player", new { id = player.playerId }),
|
|
|
|
// Url.Action("GetPlayer", "Player", new { id = player.playerId }),
|
|
|
|
"get_player",
|
|
|
|
// "get_player",
|
|
|
|
"GET"
|
|
|
|
// "GET"
|
|
|
|
));
|
|
|
|
// ));
|
|
|
|
response.Links.Add(new ApiLink(
|
|
|
|
// response.Links.Add(new ApiLink(
|
|
|
|
Url.Action("RemovePlayer", "Player", new { id = player.playerId }),
|
|
|
|
// Url.Action("RemovePlayer", "Player", new { id = player.playerId }),
|
|
|
|
"delete_player",
|
|
|
|
// "delete_player",
|
|
|
|
"DELETE"
|
|
|
|
// "DELETE"
|
|
|
|
));
|
|
|
|
// ));
|
|
|
|
response.Links.Add(new ApiLink(
|
|
|
|
// response.Links.Add(new ApiLink(
|
|
|
|
Url.Action("Put", "Player", new { id = player.playerId }),
|
|
|
|
// Url.Action("Put", "Player", new { id = player.playerId }),
|
|
|
|
"update_player",
|
|
|
|
// "update_player",
|
|
|
|
"PUT"
|
|
|
|
// "PUT"
|
|
|
|
));
|
|
|
|
// ));
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(response);
|
|
|
|
return Ok(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|