-
-
Save gavilanch/41927e8ece9088a2688919600d67ce85 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
[Route("api/[controller]")] | |
[ApiController] | |
public class ValuesController : ControllerBase | |
{ | |
private readonly ValuesRepository _repository; | |
public ValuesController(ValuesRepository repository) | |
{ | |
_repository = repository ?? throw new ArgumentNullException(nameof(repository)); | |
} | |
// GET api/values | |
[HttpGet] | |
public async Task<List<Value>> Get() | |
{ | |
return await _repository.GetAll(); | |
} | |
// GET api/values/5 | |
[HttpGet("{id}")] | |
public async Task<ActionResult<Value>> Get(int id) | |
{ | |
var response = await _repository.GetById(id); | |
if (response == null) { return NotFound(); } | |
return response; | |
} | |
// POST api/values | |
[HttpPost] | |
public async Task Post([FromBody] Value value) | |
{ | |
await _repository.Insert(value); | |
} | |
// DELETE api/values/5 | |
[HttpDelete("{id}")] | |
public async Task Delete(int id) | |
{ | |
await _repository.DeleteById(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment