fix: wire up admin attendance page to real API, add BFF shop attendance endpoint

- BFF: add GET /api/bff/shops/{shopId}/attendance proxy to merchant-service
- ShopAttendance.razor: replace mock data with real attendance API call
- Calculate present/late/absent counts from actual attendance records

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-03-13 15:30:12 +07:00
parent 8086bc627f
commit 598193e6cb
2 changed files with 22 additions and 4 deletions

View File

@@ -124,10 +124,17 @@
{
var staff = await DataService.GetStaffForShopAsync(shopGuid);
_staffCount = staff.Count;
// EN: Mock attendance for now — will proxy to real API
// VI: Mock chấm công tạm thời — sẽ proxy đến API thực
_records = new();
_presentToday = staff.Count;
// EN: Load real attendance data from merchant-service via BFF.
// VI: Tải dữ liệu chấm công thực từ merchant-service qua BFF.
var attendance = await DataService.GetListFromApiAsync<AttendanceRow>(
$"api/bff/shops/{shopGuid}/attendance?month={_month}&year={_year}");
_records = attendance;
var today = DateTime.UtcNow.Date;
_presentToday = attendance.Count(a => a.Date.Date == today);
_lateCount = attendance.Count(a => a.Date.Date == today && a.CheckIn.HasValue && a.CheckIn.Value.Hour >= 9);
_absentCount = _staffCount - _presentToday;
}
}
catch { }

View File

@@ -414,6 +414,17 @@ public class StaffController : ControllerBase
return await _merchant.PostAsJsonAsync("/api/v1/attendance/check-out", payload).ProxyAsync();
}
/// <summary>
/// EN: Get attendance records for a shop (admin) — proxies to merchant-service.
/// VI: Lấy bản ghi chấm công theo shop (admin) — proxy đến merchant-service.
/// </summary>
[HttpGet("shops/{shopId:guid}/attendance")]
public Task<IActionResult> GetShopAttendance(Guid shopId, [FromQuery] int month = 0, [FromQuery] int year = 0)
{
var qs = $"?month={month}&year={year}";
return _merchant.GetAsync($"/api/v1/attendance/shop/{shopId}{qs}").ProxyAsync();
}
/// <summary>
/// EN: Get all available staff roles.
/// VI: Lấy tất cả vai trò nhân viên hiện có.