feat(giving): include Sunday attendance total in offering session list
This commit is contained in:
@@ -164,4 +164,27 @@ public class OfferingSessionServiceTests
|
|||||||
Assert.Equal("PP-456", line.PayPalTransactionId);
|
Assert.Equal("PP-456", line.PayPalTransactionId);
|
||||||
Assert.Equal("C-789", line.CheckNumber);
|
Assert.Equal("C-789", line.CheckNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetPagedAsync_IncludesSundayAttendanceTotal_WhenRowExists()
|
||||||
|
{
|
||||||
|
using var db = BuildDb();
|
||||||
|
var catId = await SeedCategoryAsync(db);
|
||||||
|
var svc = new OfferingSessionService(db, BuildAccessor(), new NoOpFileStorage());
|
||||||
|
|
||||||
|
var withDate = new DateOnly(2026, 5, 31);
|
||||||
|
var withoutDate = new DateOnly(2026, 5, 24);
|
||||||
|
await svc.CreateAsync(BuildRequest(catId, withDate));
|
||||||
|
await svc.CreateAsync(BuildRequest(catId, withoutDate));
|
||||||
|
db.MealAttendances.Add(new MealAttendance
|
||||||
|
{ AttendanceDate = withDate, AdultCount = 40, YouthCount = 12, KidCount = 8 });
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
var page = await svc.GetPagedAsync(1, 20, null, null);
|
||||||
|
|
||||||
|
var withItem = page.Items.Single(i => i.SessionDate == "2026-05-31");
|
||||||
|
var withoutItem = page.Items.Single(i => i.SessionDate == "2026-05-24");
|
||||||
|
Assert.Equal(60, withItem.SundayAttendanceCount); // 40 + 12 + 8
|
||||||
|
Assert.Null(withoutItem.SundayAttendanceCount); // no attendance row -> null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,5 @@ public class OfferingSessionListItemDto
|
|||||||
public decimal Difference { get; set; }
|
public decimal Difference { get; set; }
|
||||||
public int LineCount { get; set; }
|
public int LineCount { get; set; }
|
||||||
public bool HasProof { get; set; }
|
public bool HasProof { get; set; }
|
||||||
|
public int? SundayAttendanceCount { get; set; } // null = no attendance recorded for the date
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ public class OfferingSessionService : IOfferingSessionService
|
|||||||
.Select(grp => new { Id = grp.Key, Count = grp.Count() })
|
.Select(grp => new { Id = grp.Key, Count = grp.Count() })
|
||||||
.ToDictionaryAsync(x => x.Id, x => x.Count);
|
.ToDictionaryAsync(x => x.Id, x => x.Count);
|
||||||
|
|
||||||
|
var dates = rows.Select(r => r.SessionDate).ToList();
|
||||||
|
var attendance = await _db.MealAttendances.AsNoTracking()
|
||||||
|
.Where(a => dates.Contains(a.AttendanceDate))
|
||||||
|
.ToDictionaryAsync(a => a.AttendanceDate, a => a.AdultCount + a.YouthCount + a.KidCount);
|
||||||
|
|
||||||
var items = rows.Select(s => new OfferingSessionListItemDto
|
var items = rows.Select(s => new OfferingSessionListItemDto
|
||||||
{
|
{
|
||||||
Id = s.Id, SessionDate = s.SessionDate.ToString("yyyy-MM-dd"), Status = s.Status,
|
Id = s.Id, SessionDate = s.SessionDate.ToString("yyyy-MM-dd"), Status = s.Status,
|
||||||
@@ -52,6 +57,7 @@ public class OfferingSessionService : IOfferingSessionService
|
|||||||
SystemTotal = s.SystemTotal, Difference = s.Difference,
|
SystemTotal = s.SystemTotal, Difference = s.Difference,
|
||||||
LineCount = counts.TryGetValue(s.Id, out var c) ? c : 0,
|
LineCount = counts.TryGetValue(s.Id, out var c) ? c : 0,
|
||||||
HasProof = s.ProofPdfPath != null,
|
HasProof = s.ProofPdfPath != null,
|
||||||
|
SundayAttendanceCount = attendance.TryGetValue(s.SessionDate, out var att) ? att : (int?)null,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
return new PagedResult<OfferingSessionListItemDto>
|
return new PagedResult<OfferingSessionListItemDto>
|
||||||
|
|||||||
Reference in New Issue
Block a user