74 lines
1.9 KiB
C#
74 lines
1.9 KiB
C#
using API.Models.Ingoing.Altersgruppen;
|
|
using API.Repository.AgeGroup;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace API.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/ageGroups/")]
|
|
public class AgeGroupController : ControllerBase
|
|
{
|
|
private IAgeGroupService _ageGroupService;
|
|
|
|
public AgeGroupController(IAgeGroupService ageGroupService)
|
|
{
|
|
_ageGroupService = ageGroupService;
|
|
}
|
|
|
|
[HttpGet()]
|
|
public async Task<IActionResult> GetAll()
|
|
{
|
|
var allAgeGroups = await _ageGroupService.GetAllAsync();
|
|
|
|
return Ok(allAgeGroups);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<IActionResult> GetOne([FromRoute] int id)
|
|
{
|
|
var group = await _ageGroupService.GetAsync(id);
|
|
|
|
if (group == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return Ok(group);
|
|
}
|
|
|
|
[HttpPost()]
|
|
public async Task<IActionResult> Create([FromBody] AltersGruppeIngoing groupDto)
|
|
{
|
|
var group = await _ageGroupService.CreateAsync(groupDto.ToInternalFromIngoing());
|
|
|
|
return CreatedAtAction(nameof(GetOne), new { Id = group.Id }, group);
|
|
}
|
|
|
|
[HttpPut("{id}")]
|
|
public async Task<IActionResult> Update([FromRoute] int id, [FromBody] AltersGruppeIngoing groupDto)
|
|
{
|
|
var group = await _ageGroupService.UpdateAsync(id, groupDto.ToInternalFromIngoing());
|
|
|
|
if(group == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return Ok(group);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public async Task<IActionResult> Delete([FromRoute] int Id)
|
|
{
|
|
var group = await _ageGroupService.DeleteAsync(Id);
|
|
|
|
if (group == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return NoContent();
|
|
}
|
|
}
|
|
}
|