Skip to content

Commit d964bcd

Browse files
iammukeshmclaude
andcommitted
fix(identity): align Group entity with IAuditableEntity and encapsulate soft-delete
- Implement IAuditableEntity on Group (CreatedOnUtc, LastModifiedOnUtc, LastModifiedBy) - Map renamed properties to existing DB columns via HasColumnName (no migration needed) - Encapsulate ISoftDeletable with private setters and Delete() domain method - Upgrade GroupDto.CreatedAt from DateTime to DateTimeOffset (preserves JSON property name) - Use TimeProvider.System for testable timestamps Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9f97a45 commit d964bcd

7 files changed

Lines changed: 21 additions & 14 deletions

File tree

src/Modules/Identity/Modules.Identity.Contracts/DTOs/GroupDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ public class GroupDto
1010
public int MemberCount { get; set; }
1111
public IReadOnlyCollection<string>? RoleIds { get; set; }
1212
public IReadOnlyCollection<string>? RoleNames { get; set; }
13-
public DateTimeOffset CreatedOnUtc { get; set; }
13+
public DateTimeOffset CreatedAt { get; set; }
1414
}

src/Modules/Identity/Modules.Identity/Domain/Group.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static Group Create(string name, string? description = null, bool isDefau
3636
Description = description,
3737
IsDefault = isDefault,
3838
IsSystemGroup = isSystemGroup,
39-
CreatedAt = TimeProvider.System.GetUtcNow().UtcDateTime,
39+
CreatedOnUtc = TimeProvider.System.GetUtcNow(),
4040
CreatedBy = createdBy
4141
};
4242
}
@@ -45,14 +45,21 @@ public void Update(string name, string? description, string? modifiedBy = null)
4545
{
4646
Name = name;
4747
Description = description;
48-
ModifiedAt = TimeProvider.System.GetUtcNow().UtcDateTime;
49-
ModifiedBy = modifiedBy;
48+
LastModifiedOnUtc = TimeProvider.System.GetUtcNow();
49+
LastModifiedBy = modifiedBy;
5050
}
5151

5252
public void SetAsDefault(bool isDefault, string? modifiedBy = null)
5353
{
5454
IsDefault = isDefault;
55-
ModifiedAt = TimeProvider.System.GetUtcNow().UtcDateTime;
56-
ModifiedBy = modifiedBy;
55+
LastModifiedOnUtc = TimeProvider.System.GetUtcNow();
56+
LastModifiedBy = modifiedBy;
57+
}
58+
59+
public void Delete(string? deletedBy = null)
60+
{
61+
IsDeleted = true;
62+
DeletedOnUtc = TimeProvider.System.GetUtcNow();
63+
DeletedBy = deletedBy;
5764
}
5865
}

src/Modules/Identity/Modules.Identity/Features/v1/Groups/CreateGroup/CreateGroupCommandHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async ValueTask<GroupDto> Handle(CreateGroupCommand command, Cancellation
4343
.ToListAsync(cancellationToken);
4444
resolvedRoles = rawRoles.Select(r => (r.Id, r.Name!)).ToList();
4545

46-
var invalidRoleIds = command.RoleIds.Except(resolvedRoles.Select(r => r.Item1)).ToList();
46+
var invalidRoleIds = command.RoleIds.Except(resolvedRoles.Select(r => r.Id)).ToList();
4747
if (invalidRoleIds.Count > 0)
4848
{
4949
throw new NotFoundException($"Roles not found: {string.Join(", ", invalidRoleIds)}");
@@ -74,9 +74,9 @@ public async ValueTask<GroupDto> Handle(CreateGroupCommand command, Cancellation
7474
IsDefault = group.IsDefault,
7575
IsSystemGroup = group.IsSystemGroup,
7676
MemberCount = 0,
77-
RoleIds = resolvedRoles.Select(r => r.Item1).ToList().AsReadOnly(),
78-
RoleNames = resolvedRoles.Select(r => r.Item2).ToList().AsReadOnly(),
79-
CreatedOnUtc = group.CreatedOnUtc
77+
RoleIds = resolvedRoles.Select(r => r.Id).ToList().AsReadOnly(),
78+
RoleNames = resolvedRoles.Select(r => r.Name).ToList().AsReadOnly(),
79+
CreatedAt = group.CreatedOnUtc
8080
};
8181
}
8282
}

src/Modules/Identity/Modules.Identity/Features/v1/Groups/GetGroupById/GetGroupByIdQueryHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async ValueTask<GroupDto> Handle(GetGroupByIdQuery query, CancellationTok
4646
MemberCount = memberCount,
4747
RoleIds = roleIds.AsReadOnly(),
4848
RoleNames = roleNames.AsReadOnly(),
49-
CreatedAt = group.CreatedAt
49+
CreatedAt = group.CreatedOnUtc
5050
};
5151
}
5252
}

src/Modules/Identity/Modules.Identity/Features/v1/Groups/GetGroups/GetGroupsQueryHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public async ValueTask<IEnumerable<GroupDto>> Handle(GetGroupsQuery query, Cance
6767
.Select(gr => roleNames.GetValueOrDefault(gr.RoleId, gr.RoleId))
6868
.ToList()
6969
.AsReadOnly(),
70-
CreatedOnUtc = g.CreatedOnUtc
70+
CreatedAt = g.CreatedOnUtc
7171
});
7272
}
7373
}

src/Modules/Identity/Modules.Identity/Features/v1/Groups/UpdateGroup/UpdateGroupCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private async Task<GroupDto> BuildResponseAsync(Group group, HashSet<string> rol
117117
MemberCount = memberCount,
118118
RoleIds = roleIds.ToList().AsReadOnly(),
119119
RoleNames = roleNames.AsReadOnly(),
120-
CreatedOnUtc = group.CreatedOnUtc
120+
CreatedAt = group.CreatedOnUtc
121121
};
122122
}
123123
}

src/Modules/Identity/Modules.Identity/Features/v1/Users/GetUserGroups/GetUserGroupsQueryHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public async ValueTask<IEnumerable<GroupDto>> Handle(GetUserGroupsQuery query, C
7878
.Select(gr => roleNames.GetValueOrDefault(gr.RoleId, gr.RoleId))
7979
.ToList()
8080
.AsReadOnly(),
81-
CreatedOnUtc = g.CreatedOnUtc
81+
CreatedAt = g.CreatedOnUtc
8282
});
8383
}
8484
}

0 commit comments

Comments
 (0)