-
-
Save Quit/c236ad7b1646828b8469 to your computer and use it in GitHub Desktop.
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.Collections.Generic; | |
using System.Web.Http; | |
namespace SelfHost.WebApi.v1 | |
{ | |
[RoutePrefix("api/v1/population/")] | |
public class PopulationController : ApiController | |
{ | |
// For the sake of this test, IPopulationApi would be the api to | |
// control populations, like animals or plants. | |
private IPopulationApi _api; | |
// Dependency Injection, performed by web API | |
public PopulationController(IPopulationApi api) | |
{ | |
this._api = api; | |
} | |
/// <summary> | |
/// Returns all animals and plants. | |
/// </summary> | |
// GET api/v1/population/members | |
[Route("members")] | |
public IEnumerable<IMember> GetMembers() | |
{ | |
return _api.GetMembers(); | |
} | |
/// <summary> | |
/// Returns all animals or plants of species <paramref name="speciesName"/> | |
/// </summary> | |
// GET api/v1/population/members/animalDeer | |
[Route("members/{speciesName}")] | |
public IEnumerable<IMember> GetMembers(string speciesName) | |
{ | |
return _api.GetMembers(speciesName); | |
} | |
/// <summary> | |
/// Wipes out an entire species. | |
/// </summary> | |
// DELETE api/v1/population/erase/animalDeer | |
[Route("erase/{speciesName}")] | |
[HttpDelete] | |
[Authorize(Roles = "Administrator")] | |
public void EraseSpecies(string speciesName) | |
{ | |
_api.EraseSpecies(speciesName); | |
} | |
/// <summary> | |
/// Adds <paramref name="member"/> to the species <paramref name="speciesName"/> | |
/// </summary> | |
// POST api/v1/ | |
[Route("add/{speciesName}")] | |
[HttpPost] | |
[Authorize(Roles = "Administrator")] | |
public void AddMember(string speciesName, IMember member) | |
{ | |
_api.AddMember(speciesName, member); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment