Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
using System;
using System.Collections.Generic;
using ConductOfCode.Models;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
namespace ConductOfCode.Controllers
{
[Route("api/[controller]")]
public class StackController : Controller
{
private Stack<Item> Stack { get; set; }
public StackController(Stack<Item> stack)
{
Stack = stack;
}
[HttpPost("[action]")]
[SwaggerResponse(typeof(void))]
public IActionResult Clear()
{
Stack.Clear();
return NoContent();
}
[HttpGet("[action]")]
[SwaggerResponse("200", typeof(Item))]
[SwaggerResponse("400", typeof(Error))]
public IActionResult Peek()
{
try
{
return Ok(Stack.Peek());
}
catch (InvalidOperationException ex)
{
return BadRequest(new Error(ex));
}
}
[HttpGet("[action]")]
[SwaggerResponse("200", typeof(Item))]
[SwaggerResponse("400", typeof(Error))]
public IActionResult Pop()
{
try
{
return Ok(Stack.Pop());
}
catch (InvalidOperationException ex)
{
return BadRequest(new Error(ex));
}
}
[HttpPost("[action]")]
[SwaggerResponse(typeof(void))]
public IActionResult Push([FromBody] Item item)
{
Stack.Push(item);
return NoContent();
}
[HttpGet("[action]")]
[SwaggerResponse(typeof(Item[]))]
public Item[] ToArray()
{
return Stack.ToArray();
}
}
}