feat: add person name and insert time to announcement DTO
- Added PersonName property to AnnouncementDto to display person's full name - Added lookup logic to fetch person names from Persons table based on phone numbers - Added InsertTime shadow property retrieval from EF Core to display creation date - Updated model snapshot with new shadow properties (InsertTime, IsRemoved, RemoveTime, UpdateTime) for Chat entity
This commit is contained in:
@@ -33,14 +33,37 @@ namespace Complex.Application.Services.Announcement
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
|
||||
var result = chats.Select(c => new AnnouncementDto
|
||||
// Get unique phone numbers to look up person names
|
||||
var phoneNumbers = chats
|
||||
.Select(c => c.PersonMobileNumber)
|
||||
.Where(p => p != null)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var personNames = _complexDBContext.Persons
|
||||
.Where(p => phoneNumbers.Contains(p.Id))
|
||||
.ToDictionary(p => p.Id, p => $"{p.FirstName} {p.LastName}".Trim());
|
||||
|
||||
var result = chats.Select(c =>
|
||||
{
|
||||
Id = c.Id,
|
||||
ComplexId = c.ComplexId,
|
||||
PersonMobileNumber = c.PersonMobileNumber,
|
||||
Body = c.Body,
|
||||
ChatTypeId = c.ChatTypeId,
|
||||
InsertTime = null // InsertTime is set by Auditable attribute in SaveChanges, not a property on Chat entity
|
||||
personNames.TryGetValue(c.PersonMobileNumber, out var personName);
|
||||
|
||||
// Read InsertTime from EF Core shadow property
|
||||
var insertTimeEntry = _complexDBContext.Entry(c).Property("InsertTime");
|
||||
var insertTime = insertTimeEntry?.CurrentValue as DateTime?;
|
||||
|
||||
return new AnnouncementDto
|
||||
{
|
||||
Id = c.Id,
|
||||
ComplexId = c.ComplexId,
|
||||
PersonMobileNumber = c.PersonMobileNumber,
|
||||
PersonName = personName,
|
||||
Body = c.Body,
|
||||
ChatTypeId = c.ChatTypeId,
|
||||
InsertTime = insertTime.HasValue
|
||||
? insertTime.Value.ToString("yyyy/MM/dd HH:mm")
|
||||
: null
|
||||
};
|
||||
}).ToList();
|
||||
|
||||
return new ResultDto<List<AnnouncementDto>>
|
||||
@@ -78,6 +101,7 @@ namespace Complex.Application.Services.Announcement
|
||||
public long Id { get; set; }
|
||||
public Guid ComplexId { get; set; }
|
||||
public string? PersonMobileNumber { get; set; }
|
||||
public string? PersonName { get; set; }
|
||||
public string? Body { get; set; }
|
||||
public byte? ChatTypeId { get; set; }
|
||||
public string? InsertTime { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user