Notify matching users when a new shift/job is posted (in-app notifications)
- Notification entity + NotificationService: on publish, notify users whose saved prefs match the listing (role/city/+shift type); users with no preference aren't spammed - Wired into PostShift, PostJob, and Admin Review publish - 🔔 bell with unread count in the header (@inject) + /Me/Notifications page (mark-all-read on open) - Reliable in-app delivery (works in Iran without FCM); Web Push can ride the same records later - Verified: employee pref → employer posts matching shift → employee bell=۱ + 'شیفت جدید: پزشک عمومی' Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -15,12 +15,14 @@ public class PostJobModel : PageModel
|
||||
private readonly AppDbContext _db;
|
||||
private readonly CaptchaService _captcha;
|
||||
private readonly SubmissionGuard _guard;
|
||||
private readonly NotificationService _notify;
|
||||
|
||||
public PostJobModel(AppDbContext db, CaptchaService captcha, SubmissionGuard guard)
|
||||
public PostJobModel(AppDbContext db, CaptchaService captcha, SubmissionGuard guard, NotificationService notify)
|
||||
{
|
||||
_db = db;
|
||||
_captcha = captcha;
|
||||
_guard = guard;
|
||||
_notify = notify;
|
||||
}
|
||||
|
||||
public List<Facility> MyFacilities { get; private set; } = new();
|
||||
@@ -68,7 +70,7 @@ public class PostJobModel : PageModel
|
||||
if (await _guard.PostingRateExceededAsync(uid))
|
||||
{ Error = $"در یک ساعت اخیر بیش از حد مجاز ({SubmissionGuard.MaxListingsPerHour}) آگهی ثبت کردهاید. بعداً تلاش کنید."; NewCaptcha(); return Page(); }
|
||||
|
||||
_db.JobOpenings.Add(new JobOpening
|
||||
var job = new JobOpening
|
||||
{
|
||||
FacilityId = FacilityId,
|
||||
RoleId = RoleId,
|
||||
@@ -81,8 +83,10 @@ public class PostJobModel : PageModel
|
||||
Requirements = Requirements,
|
||||
Status = ShiftStatus.Open,
|
||||
Source = ShiftSource.Direct,
|
||||
});
|
||||
};
|
||||
_db.JobOpenings.Add(job);
|
||||
await _db.SaveChangesAsync();
|
||||
await _notify.NotifyNewJobAsync(job.Id); // notify matching staff
|
||||
return RedirectToPage("/Employer/Index");
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,14 @@ public class PostShiftModel : PageModel
|
||||
private readonly AppDbContext _db;
|
||||
private readonly CaptchaService _captcha;
|
||||
private readonly SubmissionGuard _guard;
|
||||
private readonly NotificationService _notify;
|
||||
|
||||
public PostShiftModel(AppDbContext db, CaptchaService captcha, SubmissionGuard guard)
|
||||
public PostShiftModel(AppDbContext db, CaptchaService captcha, SubmissionGuard guard, NotificationService notify)
|
||||
{
|
||||
_db = db;
|
||||
_captcha = captcha;
|
||||
_guard = guard;
|
||||
_notify = notify;
|
||||
}
|
||||
|
||||
public List<Facility> MyFacilities { get; private set; } = new();
|
||||
@@ -72,7 +74,7 @@ public class PostShiftModel : PageModel
|
||||
{ Error = $"در یک ساعت اخیر بیش از حد مجاز ({SubmissionGuard.MaxListingsPerHour}) آگهی ثبت کردهاید. بعداً تلاش کنید."; NewCaptcha(); return Page(); }
|
||||
|
||||
var role = await _db.Roles.FindAsync(RoleId);
|
||||
_db.Shifts.Add(new Shift
|
||||
var shift = new Shift
|
||||
{
|
||||
FacilityId = FacilityId,
|
||||
RoleId = RoleId,
|
||||
@@ -89,8 +91,10 @@ public class PostShiftModel : PageModel
|
||||
GenderRequirement = GenderRequirement,
|
||||
Status = ShiftStatus.Open,
|
||||
Source = ShiftSource.Direct, // posted directly by the facility
|
||||
});
|
||||
};
|
||||
_db.Shifts.Add(shift);
|
||||
await _db.SaveChangesAsync();
|
||||
await _notify.NotifyNewShiftAsync(shift.Id); // notify matching staff
|
||||
return RedirectToPage("/Employer/Index");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user