[CLAUDE] App+Domain+Infra+Api+FE: Notifications module end-to-end
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 2m43s

Domain:
- Notification entity + NotificationType enum (stable ints)
- Nullable RefId cho correlation (contract, user, ...)

Infrastructure:
- NotificationConfiguration: bảng Notifications, index theo (UserId, ReadAt)
- NotificationService: ghi vào DbContext, không SaveChanges (để caller quyết
  định unit-of-work — đảm bảo atomic với domain mutation)
- EF migration AddNotifications

Application:
- INotificationService (Notify + NotifyMany)
- CQRS: ListMyNotifications / GetMyUnreadCount / MarkRead / MarkAllRead

Api:
- NotificationsController: GET /api/notifications + unread-count + mark-read

Integration:
- ContractWorkflowService emit notification tới Drafter khi HĐ chuyển phase
  (skip nếu actor chính là Drafter). Title + type theo phase đích:
  DaPhatHanh → ContractPublished, TuChoi → ContractRejected, khác →
  ContractPhaseTransition.

FE:
- Both NotificationBell (admin + user) dùng /api/notifications thật
  (thay cho derived-from-inbox MVP trước đó). 30s refetch, click mark-read,
  'Đọc hết' bulk action.

Foundation sẵn cho SignalR push + email outbox sau này — chỉ cần mở rộng
NotificationService mà không đổi caller.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
pqhuy1987
2026-04-21 15:24:09 +07:00
parent 6c0e20649a
commit 49c0ddc8f4
17 changed files with 1619 additions and 110 deletions

View File

@ -0,0 +1,17 @@
using SolutionErp.Domain.Common;
namespace SolutionErp.Domain.Notifications;
public class Notification : BaseEntity
{
public Guid UserId { get; set; }
public NotificationType Type { get; set; }
public string Title { get; set; } = string.Empty;
public string? Description { get; set; }
public string? Href { get; set; }
public DateTime? ReadAt { get; set; }
// Optional correlation to source entity (contract, user, etc.). Interpretation
// depends on Type. Kept nullable to avoid a discriminated-union migration.
public Guid? RefId { get; set; }
}

View File

@ -0,0 +1,13 @@
namespace SolutionErp.Domain.Notifications;
// Stable ints — order matters for persistence + analytics. Don't renumber.
public enum NotificationType
{
ContractPhaseTransition = 1,
ContractCommentAdded = 2,
SlaWarning = 3,
SlaOverdue = 4,
ContractPublished = 5,
ContractRejected = 6,
Generic = 99,
}