2026-06-03 01:43:55 +03:30
|
|
|
using JobsMedical.Web.Data;
|
|
|
|
|
using JobsMedical.Web.Models;
|
2026-06-03 08:18:19 +03:30
|
|
|
using JobsMedical.Web.Services.Scraping;
|
2026-06-03 01:43:55 +03:30
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace JobsMedical.Web.Pages.Admin;
|
|
|
|
|
|
2026-06-03 08:18:19 +03:30
|
|
|
[Authorize(Roles = "Admin")]
|
2026-06-03 01:43:55 +03:30
|
|
|
public class IndexModel : PageModel
|
|
|
|
|
{
|
|
|
|
|
private readonly AppDbContext _db;
|
2026-06-03 08:18:19 +03:30
|
|
|
private readonly IngestionService _ingest;
|
|
|
|
|
|
|
|
|
|
public IndexModel(AppDbContext db, IngestionService ingest)
|
|
|
|
|
{
|
|
|
|
|
_db = db;
|
|
|
|
|
_ingest = ingest;
|
|
|
|
|
}
|
2026-06-03 01:43:55 +03:30
|
|
|
|
|
|
|
|
public List<RawListing> Queue { get; private set; } = new();
|
2026-06-03 08:18:19 +03:30
|
|
|
public List<RawListing> Flagged { get; private set; } = new();
|
2026-06-04 00:44:11 +03:30
|
|
|
public IReadOnlyList<string> SourceNames { get; private set; } = new List<string>();
|
2026-06-03 01:43:55 +03:30
|
|
|
public int PublishedShifts { get; private set; }
|
|
|
|
|
public int PublishedJobs { get; private set; }
|
|
|
|
|
|
|
|
|
|
[BindProperty] public string? SourceChannel { get; set; }
|
|
|
|
|
[BindProperty] public string? RawText { get; set; }
|
|
|
|
|
|
2026-06-03 08:18:19 +03:30
|
|
|
[TempData] public string? IngestMessage { get; set; }
|
|
|
|
|
|
2026-06-03 01:43:55 +03:30
|
|
|
public async Task OnGetAsync() => await LoadAsync();
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> OnPostAddAsync()
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(RawText))
|
|
|
|
|
{
|
|
|
|
|
_db.RawListings.Add(new RawListing
|
|
|
|
|
{
|
|
|
|
|
SourceChannel = string.IsNullOrWhiteSpace(SourceChannel) ? "ورود دستی" : SourceChannel.Trim(),
|
|
|
|
|
RawText = RawText.Trim(),
|
|
|
|
|
Status = RawListingStatus.New,
|
|
|
|
|
});
|
|
|
|
|
await _db.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
return RedirectToPage();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 08:18:19 +03:30
|
|
|
public async Task<IActionResult> OnPostRunIngestionAsync()
|
|
|
|
|
{
|
|
|
|
|
var s = await _ingest.RunAsync();
|
|
|
|
|
IngestMessage = $"جمعآوری انجام شد — {s.TotalQueued} در صف، {s.TotalFlagged} پرچمخورده، " +
|
|
|
|
|
$"{s.TotalSpam} اسپم، {s.TotalDuplicates} تکراری.";
|
|
|
|
|
return RedirectToPage();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 01:43:55 +03:30
|
|
|
private async Task LoadAsync()
|
|
|
|
|
{
|
|
|
|
|
Queue = await _db.RawListings
|
|
|
|
|
.Where(r => r.Status == RawListingStatus.New)
|
2026-06-03 08:18:19 +03:30
|
|
|
.OrderByDescending(r => r.Confidence).ThenByDescending(r => r.FetchedAt).ToListAsync();
|
|
|
|
|
Flagged = await _db.RawListings
|
|
|
|
|
.Where(r => r.Status == RawListingStatus.Flagged)
|
2026-06-03 01:43:55 +03:30
|
|
|
.OrderByDescending(r => r.FetchedAt).ToListAsync();
|
2026-06-04 00:44:11 +03:30
|
|
|
SourceNames = _ingest.SourceNames;
|
2026-06-03 01:43:55 +03:30
|
|
|
PublishedShifts = await _db.Shifts.CountAsync(s => s.Source != ShiftSource.Direct);
|
|
|
|
|
PublishedJobs = await _db.JobOpenings.CountAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|