fix(merchant): fix NullReferenceException in Shop.Publish() and build errors
- Shop.Publish(): use StatusId (persisted int) instead of _status (null when EF Core loads entity without navigation property hydration) - Shop.SetInactive(): same fix for _status null check - SubscribeCommand: fix 'userId' → 'request.UserId' build error - StaffQueries: fix 'userId' → 'request.UserId' build error Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -48,7 +48,7 @@ public class SubscribeCommandHandler : IRequestHandler<SubscribeCommand, Subscri
|
||||
var merchant = await _merchantRepository.GetByUserIdAsync(request.UserId, cancellationToken);
|
||||
if (merchant == null)
|
||||
{
|
||||
_logger.LogWarning("EN: Merchant not found for user {UserId} / VI: Không tìm thấy merchant cho user {UserId}", userId);
|
||||
_logger.LogWarning("EN: Merchant not found for user {UserId} / VI: Không tìm thấy merchant cho user {UserId}", request.UserId);
|
||||
return new SubscribeCommandResult(false, "Merchant not found / Không tìm thấy merchant", -1, "");
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class GetMyStaffQueryHandler : IRequestHandler<GetMyStaffQuery, IReadOnly
|
||||
// VI: Nếu user không phải chủ merchant, thử tìm merchant qua tư cách nhân viên
|
||||
if (merchant == null)
|
||||
{
|
||||
var staffMember = await _staffRepository.GetByUserIdAsync(userId, cancellationToken);
|
||||
var staffMember = await _staffRepository.GetByUserIdAsync(request.UserId, cancellationToken);
|
||||
if (staffMember != null)
|
||||
merchant = await _merchantRepository.GetByIdAsync(staffMember.MerchantId, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -281,8 +281,10 @@ public partial class Shop : Entity, IAggregateRoot
|
||||
/// </summary>
|
||||
public void Publish()
|
||||
{
|
||||
if (_status != ShopStatus.Draft && _status != ShopStatus.Inactive)
|
||||
throw new DomainException($"Cannot publish shop with status {_status.Name}");
|
||||
// EN: Use StatusId (persisted int) instead of _status (may be null when EF loads entity).
|
||||
// VI: Dùng StatusId (int đã persist) thay vì _status (có thể null khi EF load entity).
|
||||
if (StatusId != ShopStatus.Draft.Id && StatusId != ShopStatus.Inactive.Id)
|
||||
throw new DomainException($"Cannot publish shop with status ID {StatusId}");
|
||||
|
||||
_status = ShopStatus.Active;
|
||||
StatusId = ShopStatus.Active.Id;
|
||||
@@ -297,7 +299,7 @@ public partial class Shop : Entity, IAggregateRoot
|
||||
/// </summary>
|
||||
public void SetInactive()
|
||||
{
|
||||
if (_status == ShopStatus.Closed)
|
||||
if (StatusId == ShopStatus.Closed.Id)
|
||||
throw new DomainException("Cannot change status of closed shop");
|
||||
|
||||
_status = ShopStatus.Inactive;
|
||||
|
||||
Reference in New Issue
Block a user