fix(merchant-service): resolve MapToDetailDto NullRef on shop detail API
- Add null-safe access for Type, Category, Status, ContactInfo, Branches - Fixes 500 error when loading shop details in admin UI
This commit is contained in:
@@ -88,30 +88,30 @@ public class GetShopByIdQueryHandler : IRequestHandler<GetShopByIdQuery, ShopDet
|
||||
MerchantId = shop.MerchantId,
|
||||
Name = shop.Name,
|
||||
Slug = shop.Slug,
|
||||
Type = shop.Type.Name,
|
||||
Category = shop.Category.Name,
|
||||
Status = shop.Status.Name,
|
||||
Type = shop.Type?.Name ?? "Unknown",
|
||||
Category = shop.Category?.Name ?? "Other",
|
||||
Status = shop.Status?.Name ?? "Unknown",
|
||||
Description = shop.Description,
|
||||
LogoUrl = shop.LogoUrl,
|
||||
CoverImageUrl = shop.CoverImageUrl,
|
||||
ContactInfo = new ContactInfoDto
|
||||
ContactInfo = shop.ContactInfo != null ? new ContactInfoDto
|
||||
{
|
||||
Phone = shop.ContactInfo.Phone,
|
||||
Email = shop.ContactInfo.Email,
|
||||
Website = shop.ContactInfo.Website
|
||||
},
|
||||
} : new ContactInfoDto(),
|
||||
OperatingHours = shop.OperatingHours != null ? new OperatingHoursDto
|
||||
{
|
||||
OpenTime = shop.OperatingHours.OpenTime.ToString("HH:mm"),
|
||||
CloseTime = shop.OperatingHours.CloseTime.ToString("HH:mm"),
|
||||
OpenDays = shop.OperatingHours.OpenDays.Select(d => d.ToString()).ToList()
|
||||
OpenDays = shop.OperatingHours.OpenDays?.Select(d => d.ToString()).ToList() ?? new()
|
||||
} : null,
|
||||
Branches = shop.Branches.Select(b => new ShopBranchDto
|
||||
Branches = shop.Branches?.Select(b => new ShopBranchDto
|
||||
{
|
||||
Id = b.Id,
|
||||
Name = b.Name,
|
||||
Code = b.Code,
|
||||
Address = new AddressDto
|
||||
Address = b.Address != null ? new AddressDto
|
||||
{
|
||||
Street = b.Address.Street,
|
||||
Ward = b.Address.Ward,
|
||||
@@ -119,7 +119,7 @@ public class GetShopByIdQueryHandler : IRequestHandler<GetShopByIdQuery, ShopDet
|
||||
City = b.Address.City,
|
||||
Province = b.Address.Province,
|
||||
FullAddress = b.Address.FullAddress
|
||||
},
|
||||
} : new AddressDto(),
|
||||
Location = b.Location != null ? new GeoLocationDto
|
||||
{
|
||||
Latitude = b.Location.Latitude,
|
||||
@@ -127,7 +127,7 @@ public class GetShopByIdQueryHandler : IRequestHandler<GetShopByIdQuery, ShopDet
|
||||
} : null,
|
||||
Phone = b.Phone,
|
||||
IsActive = b.IsActive
|
||||
}).ToList(),
|
||||
}).ToList() ?? new(),
|
||||
CreatedAt = shop.CreatedAt,
|
||||
UpdatedAt = shop.UpdatedAt
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user