|
|
@ -13,6 +13,8 @@ public class PizzaController : Controller |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET Action |
|
|
|
|
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
[HttpGet] |
|
|
|
public ActionResult<List<Pizza>> GetAll() => PizzaService.GetAll(); |
|
|
|
public ActionResult<List<Pizza>> GetAll() => PizzaService.GetAll(); |
|
|
|
|
|
|
|
|
|
|
@ -25,4 +27,43 @@ public class PizzaController : Controller |
|
|
|
|
|
|
|
|
|
|
|
return pizza; |
|
|
|
return pizza; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// POST Action |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
|
|
public IActionResult Create(Pizza pizza) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
PizzaService.Add(pizza); |
|
|
|
|
|
|
|
return CreatedAtAction(nameof(Get), new { id = pizza.Id}, pizza); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PUT Action |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id}")] |
|
|
|
|
|
|
|
public IActionResult Update(int id, Pizza pizza) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (id != pizza.Id) |
|
|
|
|
|
|
|
return BadRequest(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var existingPizza = PizzaService.Get(id); |
|
|
|
|
|
|
|
if (existingPizza is null) |
|
|
|
|
|
|
|
return NotFound(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PizzaService.Update(pizza); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return NoContent(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DELETE Action |
|
|
|
|
|
|
|
[HttpDelete("{id}")] |
|
|
|
|
|
|
|
public IActionResult Delete(int id) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var pizza = PizzaService.Get(id); |
|
|
|
|
|
|
|
if (pizza is null) |
|
|
|
|
|
|
|
return NotFound(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PizzaService.Delete(id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return NoContent(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |