Permalink
Cannot retrieve contributors at this time
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?
ConductOfCode/SpecFlow/ConductOfCode/Controllers/StackController.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
74 lines (65 sloc)
1.71 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |