poprawa komunikatów po testach
This commit is contained in:
parent
cd6b90696b
commit
eec83a95fc
@ -35,16 +35,22 @@ namespace FirmTracker_Server.Controllers
|
||||
[ProducesResponseType(201)] // Created
|
||||
[ProducesResponseType(400)] // Bad Request
|
||||
public IActionResult CreateExpense([FromBody] Expense expense) {
|
||||
if (expense.Value<=0)
|
||||
try
|
||||
{
|
||||
if (expense.Value <= 0)
|
||||
{
|
||||
throw new InvalidOperationException("Wydatek nie może posiadać kwoty mniejszej lub równej 0.");
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
_expenseCrud.AddExpense(expense);
|
||||
return CreatedAtAction("GetExpense", new { id = expense.Id }, expense);
|
||||
}
|
||||
catch (System.Exception ex) {
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest(ioe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
@ -68,6 +74,8 @@ namespace FirmTracker_Server.Controllers
|
||||
[ProducesResponseType(204)]
|
||||
[ProducesResponseType(400)]
|
||||
public IActionResult UpdateExpense(int id, [FromBody] Expense expense)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (id != expense.Id)
|
||||
{
|
||||
@ -77,12 +85,16 @@ namespace FirmTracker_Server.Controllers
|
||||
{
|
||||
throw new InvalidOperationException("Wydatek nie może posiadać kwoty mniejszej lub równej 0.");
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
_expenseCrud.UpdateExpense(expense);
|
||||
return NoContent();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest(ioe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ namespace FirmTracker_Server.Controllers
|
||||
[ProducesResponseType(200)] // Created
|
||||
[ProducesResponseType(400)] // Bad Request
|
||||
public IActionResult CreateProduct([FromBody] Product product)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (product.Type != 0 && product.Type != 1)
|
||||
{
|
||||
@ -49,19 +51,23 @@ namespace FirmTracker_Server.Controllers
|
||||
{
|
||||
throw new InvalidOperationException("Dostępność usługi musi być ustawiona na 0.");
|
||||
}
|
||||
if(product.Type ==1 && product.Availability < 0) {
|
||||
if (product.Type == 1 && product.Availability < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Dostępność towaru nie może być ujemna.");
|
||||
}
|
||||
if (product.Price < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Produkt nie może posiadać ujemnej ceny.");
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
_productCrud.AddProduct(product);
|
||||
return CreatedAtAction("GetProduct", new { id = product.Id }, product);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest(ioe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
@ -95,6 +101,8 @@ namespace FirmTracker_Server.Controllers
|
||||
[ProducesResponseType(200)] // Created
|
||||
[ProducesResponseType(400)] // Bad Request
|
||||
public IActionResult UpdateProduct(int id, [FromBody] Product product)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (id != product.Id)
|
||||
throw new InvalidOperationException("ID produktu nie zgadza się.");
|
||||
@ -114,12 +122,16 @@ namespace FirmTracker_Server.Controllers
|
||||
{
|
||||
throw new InvalidOperationException("Produkt nie może posiadać ujemnej ceny.");
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
_productCrud.UpdateProduct(product);
|
||||
return NoContent();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
return BadRequest(ioe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user