micro modif controleur
continuous-integration/drone/push Build is passing Details

Merge_API_EF
Kevin MONDEJAR 3 weeks ago
parent 46f60e9fae
commit d952cb6bf0

@ -36,14 +36,14 @@ namespace WfApi.Controllers
var character = await _character.GetCharById(id);
return Ok(character);
}
catch(KeyNotFoundException e)
catch(KeyNotFoundException)
{
return NotFound();
}
}
catch (Exception e)
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" });
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
}
}
@ -66,39 +66,39 @@ namespace WfApi.Controllers
return NoContent();
}
}
catch (Exception e)
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" });
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
}
}
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
public async Task<IActionResult> CreateCharacter([FromBody] CharacterDTO newCharacter)
{
try
{
if (newCharacter == null)
{
return BadRequest(new { message = "Source data is required." });
return BadRequest(new { message = "Character data is required." });
}
try
{
var existingSource = await _character.GetCharById(newCharacter.Id);
return Conflict(new { message = "A source with this ID already exists." });
return Conflict(new { message = "A character with this ID already exists." });
}
catch (KeyNotFoundException e)
catch (KeyNotFoundException)
{
await _character.AddCharacter(newCharacter);
return CreatedAtAction(nameof(GetAllSource), new { id = newCharacter.Id }, newCharacter);
return Ok(newCharacter);
}
}
catch (Exception e)
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" });
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
}
}
@ -106,22 +106,29 @@ namespace WfApi.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
public async Task<IActionResult> UpdateCharacter([FromQuery] int id, [FromBody] CharacterDTO updatedCharacter)
{
try
{
if (updatedCharacter == null)
{
return BadRequest(new { message = "new source data is required." });
return BadRequest(new { message = "new character data is required." });
}
try
{
var existChar = await _character.GetCharById(id);
var result = _character.UpdateCharacter(id, updatedCharacter);
return Ok(result);
}
catch (Exception e)
catch(KeyNotFoundException)
{
return Conflict(new { message = "A character with this ID already exists." });
}
}
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" });
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
}
}
}

@ -22,6 +22,10 @@ namespace WfApi.Controllers
[HttpGet("{id}")] // Indiquer que l'id est dans l'URL
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetCommentary(int id, int index = 0, int count = 5)
{
try

Loading…
Cancel
Save