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 GetAll() { var allAgeGroups = await _ageGroupService.GetAllAsync(); return Ok(allAgeGroups); } [HttpGet("{id}")] public async Task GetOne([FromRoute] int id) { var group = await _ageGroupService.GetAsync(id); if (group == null) { return NotFound(); } return Ok(group); } [HttpPost()] public async Task 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 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 Delete([FromRoute] int Id) { var group = await _ageGroupService.DeleteAsync(Id); if (group == null) { return NotFound(); } return NoContent(); } } }