Refactored AgeGroupController, AgeGroupService, and IAgeGroupService to use string IDs instead of int. Added initial Entity Framework migration and database files to support AltersGruppe with string primary key.
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] string 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] string 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] string Id)
|
|
{
|
|
var group = await _ageGroupService.DeleteAsync(Id);
|
|
|
|
if (group == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return NoContent();
|
|
}
|
|
}
|
|
}
|