Fix API offset limit 400 Bad Request, implement requested UI/UX improvements
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Predictalytics.Domain.Entities;
|
||||
using Predictalytics.Domain.Enums;
|
||||
using Predictalytics.Domain.Interfaces;
|
||||
|
||||
namespace Predictalytics.Infrastructure.Data.Repositories;
|
||||
|
||||
public class JobRepository : IJobRepository
|
||||
{
|
||||
private readonly AppDbContext _db;
|
||||
|
||||
public JobRepository(AppDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task<BackgroundJob?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
return await _db.BackgroundJobs.Include(j => j.Trader).FirstOrDefaultAsync(j => j.Id == id, ct);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<BackgroundJob>> GetAllAsync(int skip = 0, int take = 50, CancellationToken ct = default)
|
||||
{
|
||||
return await _db.BackgroundJobs
|
||||
.Include(j => j.Trader)
|
||||
.OrderByDescending(j => j.CreatedAt)
|
||||
.Skip(skip)
|
||||
.Take(take)
|
||||
.ToListAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<BackgroundJob?> GetNextPendingJobAsync(JobType type, CancellationToken ct = default)
|
||||
{
|
||||
return await _db.BackgroundJobs
|
||||
.Where(j => j.JobType == type && j.Status == JobStatus.Pending)
|
||||
.OrderBy(j => j.CreatedAt)
|
||||
.FirstOrDefaultAsync(ct);
|
||||
}
|
||||
|
||||
public async Task AddAsync(BackgroundJob job, CancellationToken ct = default)
|
||||
{
|
||||
_db.BackgroundJobs.Add(job);
|
||||
await _db.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(BackgroundJob job, CancellationToken ct = default)
|
||||
{
|
||||
_db.BackgroundJobs.Update(job);
|
||||
await _db.SaveChangesAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -141,8 +141,8 @@ public class MarketRepository : IMarketRepository
|
||||
|
||||
if (existingEventsMap.TryGetValue(ev.PlatformEventId, out var existing))
|
||||
{
|
||||
existing.Slug = ev.Slug;
|
||||
existing.Title = ev.Title;
|
||||
existing.Slug = ev.Slug!;
|
||||
existing.Title = ev.Title!;
|
||||
existing.Description = ev.Description;
|
||||
existing.ImageUrl = ev.ImageUrl;
|
||||
existing.Tags = ev.Tags;
|
||||
@@ -164,7 +164,7 @@ public class MarketRepository : IMarketRepository
|
||||
else
|
||||
{
|
||||
market.EventId = existing.Id;
|
||||
market.Event = null; // Prevent EF tracking issue
|
||||
market.Event = null!; // Prevent EF tracking issue
|
||||
existing.Markets.Add(market);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using Predictalytics.Domain.Entities;
|
||||
using Predictalytics.Domain.Enums;
|
||||
using Predictalytics.Domain.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Text;
|
||||
|
||||
namespace Predictalytics.Infrastructure.Data.Repositories;
|
||||
|
||||
@@ -65,7 +66,29 @@ public class TraderRepository : ITraderRepository
|
||||
{ _db.Traders.Add(trader); await _db.SaveChangesAsync(ct); }
|
||||
|
||||
public async Task UpdateAsync(Trader trader, CancellationToken ct = default)
|
||||
{ _db.Traders.Update(trader); await _db.SaveChangesAsync(ct); }
|
||||
{
|
||||
_db.Traders.Update(trader);
|
||||
await _db.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public async Task UpdateRanksAsync(IEnumerable<(int TraderId, int Rank)> ranks, CancellationToken ct = default)
|
||||
{
|
||||
// Batch update ranks using raw SQL to avoid N+1 and loading entities
|
||||
var sql = new StringBuilder();
|
||||
sql.AppendLine("UPDATE TraderScores SET Rank = CASE TraderId");
|
||||
var ids = new List<int>();
|
||||
foreach (var r in ranks)
|
||||
{
|
||||
sql.AppendLine($"WHEN {r.TraderId} THEN {r.Rank}");
|
||||
ids.Add(r.TraderId);
|
||||
}
|
||||
sql.AppendLine("ELSE Rank END WHERE TraderId IN (" + string.Join(",", ids) + ");");
|
||||
|
||||
if (ids.Count > 0)
|
||||
{
|
||||
await _db.Database.ExecuteSqlRawAsync(sql.ToString(), ct);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user