From aacd8b7d96b298c21917191ba72e6cf023c31cbc Mon Sep 17 00:00:00 2001 From: Jonas Date: Sun, 7 Dec 2025 20:32:49 +0100 Subject: [PATCH] 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. --- API/Controllers/AgeGroupController.cs | 6 +-- .../20251207192702_Init.Designer.cs | 46 ++++++++++++++++++ API/Migrations/20251207192702_Init.cs | 35 +++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 43 ++++++++++++++++ API/Repository/AgeGroup/AgeGroupService.cs | 6 +-- API/Repository/AgeGroup/IAgeGroupService.cs | 6 +-- API/app.db | Bin 0 -> 4096 bytes API/app.db-shm | Bin 0 -> 32768 bytes API/app.db-wal | Bin 0 -> 78312 bytes 9 files changed, 133 insertions(+), 9 deletions(-) create mode 100644 API/Migrations/20251207192702_Init.Designer.cs create mode 100644 API/Migrations/20251207192702_Init.cs create mode 100644 API/Migrations/ApplicationDbContextModelSnapshot.cs create mode 100644 API/app.db create mode 100644 API/app.db-shm create mode 100644 API/app.db-wal diff --git a/API/Controllers/AgeGroupController.cs b/API/Controllers/AgeGroupController.cs index 89267d1..8280bf1 100644 --- a/API/Controllers/AgeGroupController.cs +++ b/API/Controllers/AgeGroupController.cs @@ -24,7 +24,7 @@ namespace API.Controllers } [HttpGet("{id}")] - public async Task GetOne([FromRoute] int id) + public async Task GetOne([FromRoute] string id) { var group = await _ageGroupService.GetAsync(id); @@ -45,7 +45,7 @@ namespace API.Controllers } [HttpPut("{id}")] - public async Task Update([FromRoute] int id, [FromBody] AltersGruppeIngoing groupDto) + public async Task 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 Delete([FromRoute] int Id) + public async Task Delete([FromRoute] string Id) { var group = await _ageGroupService.DeleteAsync(Id); diff --git a/API/Migrations/20251207192702_Init.Designer.cs b/API/Migrations/20251207192702_Init.Designer.cs new file mode 100644 index 0000000..9426d12 --- /dev/null +++ b/API/Migrations/20251207192702_Init.Designer.cs @@ -0,0 +1,46 @@ +// +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 + { + /// + 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("Id") + .HasMaxLength(26) + .HasColumnType("TEXT"); + + b.Property("EndingAge") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("StartingAge") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Altersgruppen"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/API/Migrations/20251207192702_Init.cs b/API/Migrations/20251207192702_Init.cs new file mode 100644 index 0000000..fb71bf2 --- /dev/null +++ b/API/Migrations/20251207192702_Init.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace API.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Altersgruppen", + columns: table => new + { + Id = table.Column(type: "TEXT", maxLength: 26, nullable: false), + Name = table.Column(type: "TEXT", maxLength: 100, nullable: false), + StartingAge = table.Column(type: "INTEGER", nullable: false), + EndingAge = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Altersgruppen", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Altersgruppen"); + } + } +} diff --git a/API/Migrations/ApplicationDbContextModelSnapshot.cs b/API/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..cf69943 --- /dev/null +++ b/API/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,43 @@ +// +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("Id") + .HasMaxLength(26) + .HasColumnType("TEXT"); + + b.Property("EndingAge") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("StartingAge") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Altersgruppen"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/API/Repository/AgeGroup/AgeGroupService.cs b/API/Repository/AgeGroup/AgeGroupService.cs index 5bdee6d..3b41cd6 100644 --- a/API/Repository/AgeGroup/AgeGroupService.cs +++ b/API/Repository/AgeGroup/AgeGroupService.cs @@ -20,7 +20,7 @@ namespace API.Repository.AgeGroup return altersGruppe; } - public async Task DeleteAsync(int id) + public async Task 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 GetAsync(int id) + public async Task GetAsync(string id) { return await _context.Altersgruppen.FindAsync(id); } - public async Task UpdateAsync(int id, AltersGruppe altersGruppe) + public async Task UpdateAsync(string id, AltersGruppe altersGruppe) { var existingGroup = await _context.Altersgruppen.FirstOrDefaultAsync(x => x.Id == id); diff --git a/API/Repository/AgeGroup/IAgeGroupService.cs b/API/Repository/AgeGroup/IAgeGroupService.cs index a350be0..9da50d3 100644 --- a/API/Repository/AgeGroup/IAgeGroupService.cs +++ b/API/Repository/AgeGroup/IAgeGroupService.cs @@ -6,9 +6,9 @@ namespace API.Repository.AgeGroup { public Task> GetAllAsync(); - public Task GetAsync(int id); + public Task GetAsync(string id); public Task CreateAsync(AltersGruppe altersGruppe); - public Task DeleteAsync(int id); - public Task UpdateAsync(int id, AltersGruppe altersGruppe); + public Task DeleteAsync(string id); + public Task UpdateAsync(string id, AltersGruppe altersGruppe); } } diff --git a/API/app.db b/API/app.db new file mode 100644 index 0000000000000000000000000000000000000000..0de02ecf623141161c863ee065d9f7dd83cbe849 GIT binary patch literal 4096 zcmWFz^vNtqRY=P(%1ta$FlG>7U}9o$P*7lCU|@t|AVoG{WYDWB{V{hUG^d1%@9K_x;$SgrZVPo140y;L&=?iD8igcr}w{~4AZe27@p>4 zh(uwDF-8(2aG@dbhJN#v*&!;UG&-S|I~QbdPr)XSt&_RNoG5-;g6~1=eO+X{<-Pvw{H9}E_TWJ`=i^t z+d?0@ukYyZO{C-Mn`5cbXj*lMvn>{Bi>iuaE!l7LG_#rKS7h$Z-emgA+b(w3BDL(F zs1c9IwwERGMMD4q1Q0*~0R#|0009ILK%ndd4tnIOdR>U?yWJa9{e27C8{U}hDwG(FPo|@zq_#>{LS8JueIx0R#|0009ILKmY**5I_I{1WFbtm=`#n`bOSd zd-j#t|K(qjY?n&zhXWBn009ILKmY**5I_I{1Q0-A;Rvje70GAU?5<|r-mDp_-sZL& zZe4G27%qpy*`#T1O%uZ{s3W*>`Es8zapb-G)Dh&@4Vd!^`P-$}5!jrPQd=wP2x@C< zuP+=pMuGqW2q1s}0tg_000IasUV(#yma2NgkPr10Nyc|3Cevf7eTCWe>`vug`S|QH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