diff --git a/back/Contracts/DTOs/SpendingGroupDto.cs b/back/Contracts/DTOs/SpendingGroupDto.cs index cf03704..2adf558 100644 --- a/back/Contracts/DTOs/SpendingGroupDto.cs +++ b/back/Contracts/DTOs/SpendingGroupDto.cs @@ -5,4 +5,5 @@ public class SpendingGroupDto public Guid Id { get; set; } public string Name { get; set; } = string.Empty; public Guid UserId { get; set; } + public List ChangeRecords { get; set; } = new(); } \ No newline at end of file diff --git a/back/Infrastructure/Models/Changerecord.cs b/back/Infrastructure/Models/Changerecord.cs index 4f9a5e9..64b06c4 100644 --- a/back/Infrastructure/Models/Changerecord.cs +++ b/back/Infrastructure/Models/Changerecord.cs @@ -12,7 +12,7 @@ public class ChangeRecord public User User { get; set; } = null!; public Guid SpendingGroupId { get; set; } - public SpendingGroup SpendingGroup { get; set; } = null!; + public SpendingGroup? SpendingGroup { get; set; } public void Update(ChangeRecordDto changeRecordDto) { diff --git a/back/Infrastructure/Models/SpendingGroup.cs b/back/Infrastructure/Models/SpendingGroup.cs index b3d5d20..ec9d48e 100644 --- a/back/Infrastructure/Models/SpendingGroup.cs +++ b/back/Infrastructure/Models/SpendingGroup.cs @@ -7,4 +7,5 @@ public class SpendingGroup public Guid UserId { get; set; } public User User { get; set; } = null!; + public List ChangeRecords { get; set; } = new(); } \ No newline at end of file diff --git a/back/Infrastructure/Models/User.cs b/back/Infrastructure/Models/User.cs index add673c..469e15e 100644 --- a/back/Infrastructure/Models/User.cs +++ b/back/Infrastructure/Models/User.cs @@ -10,6 +10,7 @@ public class User public string Password { get; set; } = null!; public decimal Balance { get; set; } public List? SpendingGroups { get; set; } + public List? ChangeRecords { get; set; } public void Update(UserDto userDto) { diff --git a/back/Infrastructure/Repositories/SpendingGroupRepo.cs b/back/Infrastructure/Repositories/SpendingGroupRepo.cs index 38a69d0..d7e879e 100644 --- a/back/Infrastructure/Repositories/SpendingGroupRepo.cs +++ b/back/Infrastructure/Repositories/SpendingGroupRepo.cs @@ -46,6 +46,7 @@ public class SpendingGroupRepo : ISpendingGroupRepo using var context = _factory.CreateDbContext(); var group = await context.SpendingGroups + .Include(x => x.ChangeRecords) .FirstOrDefaultAsync(x => x.Id == search.Id || x.Name == search.Name); @@ -71,7 +72,7 @@ public class SpendingGroupRepo : ISpendingGroupRepo } } - return await query.Select(x => x.ToDto()).ToListAsync(); + return await query.Include(x => x.ChangeRecords).Select(x => x.ToDto()).ToListAsync(); } public async Task Update(SpendingGroupDto spendingGroup) diff --git a/back/Infrastructure/Support/Mappers/SpendingGroupMapper.cs b/back/Infrastructure/Support/Mappers/SpendingGroupMapper.cs index 94a39b6..1cb0585 100644 --- a/back/Infrastructure/Support/Mappers/SpendingGroupMapper.cs +++ b/back/Infrastructure/Support/Mappers/SpendingGroupMapper.cs @@ -10,7 +10,8 @@ public static class SpendingGroupMapper { Id = group.Id, Name = group.Name, - UserId = group.UserId + UserId = group.UserId, + ChangeRecords = group.ChangeRecords.Select(x => x.ToDto()).ToList() }; public static SpendingGroup ToModel(this SpendingGroupDto group) => new()