Change AgeGroup ID type from int to string and add migration

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.
This commit is contained in:
2025-12-07 20:32:49 +01:00
parent 9128b199e9
commit aacd8b7d96
9 changed files with 133 additions and 9 deletions

View File

@@ -24,7 +24,7 @@ namespace API.Controllers
}
[HttpGet("{id}")]
public async Task<IActionResult> GetOne([FromRoute] int id)
public async Task<IActionResult> GetOne([FromRoute] string id)
{
var group = await _ageGroupService.GetAsync(id);
@@ -45,7 +45,7 @@ namespace API.Controllers
}
[HttpPut("{id}")]
public async Task<IActionResult> Update([FromRoute] int id, [FromBody] AltersGruppeIngoing groupDto)
public async Task<IActionResult> Update([FromRoute] string id, [FromBody] AltersGruppeIngoing groupDto)
{
var group = await _ageGroupService.UpdateAsync(id, groupDto.ToInternalFromIngoing());
@@ -58,7 +58,7 @@ namespace API.Controllers
}
[HttpDelete("{id}")]
public async Task<IActionResult> Delete([FromRoute] int Id)
public async Task<IActionResult> Delete([FromRoute] string Id)
{
var group = await _ageGroupService.DeleteAsync(Id);

View File

@@ -0,0 +1,46 @@
// <auto-generated />
using API.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace API.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20251207192702_Init")]
partial class Init
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.11");
modelBuilder.Entity("API.Models.Internal.Altersgruppen.AltersGruppe", b =>
{
b.Property<string>("Id")
.HasMaxLength(26)
.HasColumnType("TEXT");
b.Property<int>("EndingAge")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<int>("StartingAge")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Altersgruppen");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace API.Migrations
{
/// <inheritdoc />
public partial class Init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Altersgruppen",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", maxLength: 26, nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
StartingAge = table.Column<int>(type: "INTEGER", nullable: false),
EndingAge = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Altersgruppen", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Altersgruppen");
}
}
}

View File

@@ -0,0 +1,43 @@
// <auto-generated />
using API.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace API.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.11");
modelBuilder.Entity("API.Models.Internal.Altersgruppen.AltersGruppe", b =>
{
b.Property<string>("Id")
.HasMaxLength(26)
.HasColumnType("TEXT");
b.Property<int>("EndingAge")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<int>("StartingAge")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Altersgruppen");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -20,7 +20,7 @@ namespace API.Repository.AgeGroup
return altersGruppe;
}
public async Task<AltersGruppe?> DeleteAsync(int id)
public async Task<AltersGruppe?> DeleteAsync(string id)
{
var group = await _context.Altersgruppen.FirstOrDefaultAsync(x => x.Id == id);
@@ -42,12 +42,12 @@ namespace API.Repository.AgeGroup
return allGroups;
}
public async Task<AltersGruppe?> GetAsync(int id)
public async Task<AltersGruppe?> GetAsync(string id)
{
return await _context.Altersgruppen.FindAsync(id);
}
public async Task<AltersGruppe?> UpdateAsync(int id, AltersGruppe altersGruppe)
public async Task<AltersGruppe?> UpdateAsync(string id, AltersGruppe altersGruppe)
{
var existingGroup = await _context.Altersgruppen.FirstOrDefaultAsync(x => x.Id == id);

View File

@@ -6,9 +6,9 @@ namespace API.Repository.AgeGroup
{
public Task<List<AltersGruppe>> GetAllAsync();
public Task<AltersGruppe?> GetAsync(int id);
public Task<AltersGruppe?> GetAsync(string id);
public Task<AltersGruppe> CreateAsync(AltersGruppe altersGruppe);
public Task<AltersGruppe?> DeleteAsync(int id);
public Task<AltersGruppe?> UpdateAsync(int id, AltersGruppe altersGruppe);
public Task<AltersGruppe?> DeleteAsync(string id);
public Task<AltersGruppe?> UpdateAsync(string id, AltersGruppe altersGruppe);
}
}

BIN
API/app.db Normal file

Binary file not shown.

BIN
API/app.db-shm Normal file

Binary file not shown.

BIN
API/app.db-wal Normal file

Binary file not shown.