From be0fa19371c306490216dd3148e1934b2aa9fe89 Mon Sep 17 00:00:00 2001 From: beo3000 Date: Tue, 23 Dec 2025 11:13:48 +0100 Subject: [PATCH] add Mapping-Profiles --- docs/IMPLEMENTATION_PLAN.md | 4 +- .../Koogle.Application.csproj | 11 ++++ .../Mapping/ClubMappingProfile.cs | 37 ++++++++++++ .../Mapping/DayMappingProfile.cs | 56 +++++++++++++++++++ .../Mapping/ExpenseMappingProfile.cs | 44 +++++++++++++++ .../Mapping/PersonExpenseMappingProfile.cs | 41 ++++++++++++++ .../Mapping/PersonMappingProfile.cs | 49 ++++++++++++++++ 7 files changed, 240 insertions(+), 2 deletions(-) create mode 100644 src/Koogle.Application/Mapping/ClubMappingProfile.cs create mode 100644 src/Koogle.Application/Mapping/DayMappingProfile.cs create mode 100644 src/Koogle.Application/Mapping/ExpenseMappingProfile.cs create mode 100644 src/Koogle.Application/Mapping/PersonExpenseMappingProfile.cs create mode 100644 src/Koogle.Application/Mapping/PersonMappingProfile.cs diff --git a/docs/IMPLEMENTATION_PLAN.md b/docs/IMPLEMENTATION_PLAN.md index cbdbe24..8040ac4 100644 --- a/docs/IMPLEMENTATION_PLAN.md +++ b/docs/IMPLEMENTATION_PLAN.md @@ -328,7 +328,7 @@ NavMenu.razor: | ✓ | A3 | Foundation | DTOs | 5 DTO-Dateien | | ✓ | A4 | Foundation | Service Interfaces | 5 Service-Interface-Dateien | | ✓ | A5 | Foundation | Service Implementations | 5 Service-Dateien | -| ☐ | A6 | Foundation | AutoMapper Profiles | 5 Mapping-Dateien | +| ✓ | A6 | Foundation | AutoMapper Profiles | 5 Mapping-Dateien | | ☐ | A7 | Foundation | DI Registration | 2 DI-Dateien ändern | | ☐ | **B1** | **Clubs** | **ClubState Fluxor** | **4 State-Dateien** | | ☐ | **B2** | **Clubs** | **Club Pages - ERSTES TESTBARES MVP** | **1 Razor** | @@ -417,7 +417,7 @@ NavMenu.razor: 5. `src/Koogle.Application/Services/PersonExpenseService.cs` **Dependencies:** Repository, ICurrentClubContext, ICurrentUserService, IMapper -**Business Logic:** ClubId-Injection, Audit-Felder, Validierung +**Business Logic:** ClubId-Injection, Audit-Felder, Validierung (mittels FluentValidation) --- diff --git a/src/Koogle.Application/Koogle.Application.csproj b/src/Koogle.Application/Koogle.Application.csproj index 1ca911e..6dbec0b 100644 --- a/src/Koogle.Application/Koogle.Application.csproj +++ b/src/Koogle.Application/Koogle.Application.csproj @@ -6,8 +6,15 @@ enable + + + + + + + @@ -15,4 +22,8 @@ + + + + diff --git a/src/Koogle.Application/Mapping/ClubMappingProfile.cs b/src/Koogle.Application/Mapping/ClubMappingProfile.cs new file mode 100644 index 0000000..4188c16 --- /dev/null +++ b/src/Koogle.Application/Mapping/ClubMappingProfile.cs @@ -0,0 +1,37 @@ +using AutoMapper; +using Koogle.Application.DTOs; +using Koogle.Domain.Entities; + +namespace Koogle.Application.Mapping; + +/// +/// AutoMapper profile for Club entity mappings. +/// +public class ClubMappingProfile : Profile +{ + /// + /// Initializes Club entity to DTO mappings. + /// + public ClubMappingProfile() + { + // Club -> ClubDto + CreateMap(); + + // CreateClubDto -> Club (for creation) + CreateMap() + .ForMember(d => d.Id, o => o.Ignore()) + .ForMember(d => d.CreatedAt, o => o.Ignore()) + .ForMember(d => d.CreatedById, o => o.Ignore()) + .ForMember(d => d.ModifiedAt, o => o.Ignore()) + .ForMember(d => d.ModifiedById, o => o.Ignore()) + .ForMember(d => d.IsDeleted, o => o.Ignore()); + + // UpdateClubDto -> Club (for updates) + CreateMap() + .ForMember(d => d.CreatedAt, o => o.Ignore()) + .ForMember(d => d.CreatedById, o => o.Ignore()) + .ForMember(d => d.ModifiedAt, o => o.Ignore()) + .ForMember(d => d.ModifiedById, o => o.Ignore()) + .ForMember(d => d.IsDeleted, o => o.Ignore()); + } +} diff --git a/src/Koogle.Application/Mapping/DayMappingProfile.cs b/src/Koogle.Application/Mapping/DayMappingProfile.cs new file mode 100644 index 0000000..acdce31 --- /dev/null +++ b/src/Koogle.Application/Mapping/DayMappingProfile.cs @@ -0,0 +1,56 @@ +using AutoMapper; +using Koogle.Application.DTOs; +using Koogle.Domain.Entities; + +namespace Koogle.Application.Mapping; + +/// +/// AutoMapper profile for Day entity mappings. +/// +public class DayMappingProfile : Profile +{ + /// + /// Initializes Day entity to DTO mappings. + /// + public DayMappingProfile() + { + // Day -> DayDto + CreateMap() + .ForMember(d => d.ClubName, o => o.MapFrom(s => s.Club != null ? s.Club.Name : null)) + .ForMember(d => d.ParticipantCount, o => o.MapFrom(s => s.DayPersons.Count)) + .ForMember(d => d.Participants, o => o.MapFrom(s => s.DayPersons)); + + // Day -> DaySummaryDto + CreateMap() + .ForMember(d => d.ParticipantCount, o => o.MapFrom(s => s.DayPersons.Count)); + + // DayPerson -> DayParticipantDto + CreateMap() + .ForMember(d => d.PersonName, o => o.MapFrom(s => s.Person != null ? s.Person.Name : string.Empty)) + .ForMember(d => d.PersonStatus, o => o.MapFrom(s => s.Person != null ? s.Person.PersonStatus : default)); + + // CreateDayDto -> Day (for creation) + CreateMap() + .ForMember(d => d.Id, o => o.Ignore()) + .ForMember(d => d.Status, o => o.Ignore()) + .ForMember(d => d.ClubId, o => o.Ignore()) + .ForMember(d => d.Club, o => o.Ignore()) + .ForMember(d => d.DayPersons, o => o.Ignore()) + .ForMember(d => d.CreatedAt, o => o.Ignore()) + .ForMember(d => d.CreatedById, o => o.Ignore()) + .ForMember(d => d.ModifiedAt, o => o.Ignore()) + .ForMember(d => d.ModifiedById, o => o.Ignore()) + .ForMember(d => d.IsDeleted, o => o.Ignore()); + + // UpdateDayDto -> Day (for updates) + CreateMap() + .ForMember(d => d.ClubId, o => o.Ignore()) + .ForMember(d => d.Club, o => o.Ignore()) + .ForMember(d => d.DayPersons, o => o.Ignore()) + .ForMember(d => d.CreatedAt, o => o.Ignore()) + .ForMember(d => d.CreatedById, o => o.Ignore()) + .ForMember(d => d.ModifiedAt, o => o.Ignore()) + .ForMember(d => d.ModifiedById, o => o.Ignore()) + .ForMember(d => d.IsDeleted, o => o.Ignore()); + } +} diff --git a/src/Koogle.Application/Mapping/ExpenseMappingProfile.cs b/src/Koogle.Application/Mapping/ExpenseMappingProfile.cs new file mode 100644 index 0000000..7bb3229 --- /dev/null +++ b/src/Koogle.Application/Mapping/ExpenseMappingProfile.cs @@ -0,0 +1,44 @@ +using AutoMapper; +using Koogle.Application.DTOs; +using Koogle.Domain.Entities; + +namespace Koogle.Application.Mapping; + +/// +/// AutoMapper profile for Expense entity mappings. +/// +public class ExpenseMappingProfile : Profile +{ + /// + /// Initializes Expense entity to DTO mappings. + /// + public ExpenseMappingProfile() + { + // Expense -> ExpenseDto + CreateMap(); + + // Expense -> ExpenseSummaryDto + CreateMap(); + + // CreateExpenseDto -> Expense (for creation) + CreateMap() + .ForMember(d => d.Id, o => o.Ignore()) + .ForMember(d => d.ClubId, o => o.Ignore()) + .ForMember(d => d.Club, o => o.Ignore()) + .ForMember(d => d.CreatedAt, o => o.Ignore()) + .ForMember(d => d.CreatedById, o => o.Ignore()) + .ForMember(d => d.ModifiedAt, o => o.Ignore()) + .ForMember(d => d.ModifiedById, o => o.Ignore()) + .ForMember(d => d.IsDeleted, o => o.Ignore()); + + // UpdateExpenseDto -> Expense (for updates) + CreateMap() + .ForMember(d => d.ClubId, o => o.Ignore()) + .ForMember(d => d.Club, o => o.Ignore()) + .ForMember(d => d.CreatedAt, o => o.Ignore()) + .ForMember(d => d.CreatedById, o => o.Ignore()) + .ForMember(d => d.ModifiedAt, o => o.Ignore()) + .ForMember(d => d.ModifiedById, o => o.Ignore()) + .ForMember(d => d.IsDeleted, o => o.Ignore()); + } +} diff --git a/src/Koogle.Application/Mapping/PersonExpenseMappingProfile.cs b/src/Koogle.Application/Mapping/PersonExpenseMappingProfile.cs new file mode 100644 index 0000000..d3c40c2 --- /dev/null +++ b/src/Koogle.Application/Mapping/PersonExpenseMappingProfile.cs @@ -0,0 +1,41 @@ +using AutoMapper; +using Koogle.Application.DTOs; +using Koogle.Domain.Entities; + +namespace Koogle.Application.Mapping; + +/// +/// AutoMapper profile for PersonExpense entity mappings. +/// +public class PersonExpenseMappingProfile : Profile +{ + /// + /// Initializes PersonExpense entity to DTO mappings. + /// + public PersonExpenseMappingProfile() + { + // PersonExpense -> PersonExpenseDto + CreateMap() + .ForMember(d => d.PersonName, o => o.MapFrom(s => s.Person != null ? s.Person.Name : string.Empty)) + .ForMember(d => d.DayPostDate, o => o.MapFrom(s => s.Day != null ? s.Day.PostDate : default)); + + // CreatePersonExpenseDto -> PersonExpense (for creation) + CreateMap() + .ForMember(d => d.Id, o => o.Ignore()) + .ForMember(d => d.ClubId, o => o.Ignore()) + .ForMember(d => d.Name, o => o.Ignore()) + .ForMember(d => d.ExpenseType, o => o.Ignore()) + .ForMember(d => d.PersonExpenseStatus, o => o.Ignore()) + .ForMember(d => d.AssignedById, o => o.Ignore()) + .ForMember(d => d.Person, o => o.Ignore()) + .ForMember(d => d.Day, o => o.Ignore()) + .ForMember(d => d.Expense, o => o.Ignore()) + .ForMember(d => d.Game, o => o.Ignore()) + .ForMember(d => d.Club, o => o.Ignore()) + .ForMember(d => d.CreatedAt, o => o.Ignore()) + .ForMember(d => d.CreatedById, o => o.Ignore()) + .ForMember(d => d.ModifiedAt, o => o.Ignore()) + .ForMember(d => d.ModifiedById, o => o.Ignore()) + .ForMember(d => d.IsDeleted, o => o.Ignore()); + } +} diff --git a/src/Koogle.Application/Mapping/PersonMappingProfile.cs b/src/Koogle.Application/Mapping/PersonMappingProfile.cs new file mode 100644 index 0000000..66ea9d9 --- /dev/null +++ b/src/Koogle.Application/Mapping/PersonMappingProfile.cs @@ -0,0 +1,49 @@ +using AutoMapper; +using Koogle.Application.DTOs; +using Koogle.Domain.Entities; + +namespace Koogle.Application.Mapping; + +/// +/// AutoMapper profile for Person entity mappings. +/// +public class PersonMappingProfile : Profile +{ + /// + /// Initializes Person entity to DTO mappings. + /// + public PersonMappingProfile() + { + // Person -> PersonDto + CreateMap() + .ForMember(d => d.ClubName, o => o.MapFrom(s => s.Club != null ? s.Club.Name : null)); + + // Person -> PersonSummaryDto + CreateMap(); + + // CreatePersonDto -> Person (for creation) + CreateMap() + .ForMember(d => d.Id, o => o.Ignore()) + .ForMember(d => d.ClubId, o => o.Ignore()) + .ForMember(d => d.Club, o => o.Ignore()) + .ForMember(d => d.Expenses, o => o.Ignore()) + .ForMember(d => d.DayPersons, o => o.Ignore()) + .ForMember(d => d.CreatedAt, o => o.Ignore()) + .ForMember(d => d.CreatedById, o => o.Ignore()) + .ForMember(d => d.ModifiedAt, o => o.Ignore()) + .ForMember(d => d.ModifiedById, o => o.Ignore()) + .ForMember(d => d.IsDeleted, o => o.Ignore()); + + // UpdatePersonDto -> Person (for updates) + CreateMap() + .ForMember(d => d.ClubId, o => o.Ignore()) + .ForMember(d => d.Club, o => o.Ignore()) + .ForMember(d => d.Expenses, o => o.Ignore()) + .ForMember(d => d.DayPersons, o => o.Ignore()) + .ForMember(d => d.CreatedAt, o => o.Ignore()) + .ForMember(d => d.CreatedById, o => o.Ignore()) + .ForMember(d => d.ModifiedAt, o => o.Ignore()) + .ForMember(d => d.ModifiedById, o => o.Ignore()) + .ForMember(d => d.IsDeleted, o => o.Ignore()); + } +}