Excel Export eingebaut
This commit is contained in:
@@ -459,6 +459,83 @@ trackerApi.MapGet("/month", async (ClaimsPrincipal claimsPrincipal, [FromQuery]
|
||||
return Results.Ok(days);
|
||||
});
|
||||
|
||||
trackerApi.MapGet("/export/week", async (ClaimsPrincipal claimsPrincipal, [FromQuery] string monday, ITimetrackerService trackerService, TimetrackerDbContext db) =>
|
||||
{
|
||||
var idClaim = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
if (!int.TryParse(idClaim, out var userId)) return Results.Unauthorized();
|
||||
|
||||
if (DateOnly.TryParse(monday, out var date))
|
||||
{
|
||||
var mondayDate = date;
|
||||
int diff = ((int)mondayDate.DayOfWeek - (int)DayOfWeek.Monday + 7) % 7;
|
||||
mondayDate = mondayDate.AddDays(-diff);
|
||||
var sundayDate = mondayDate.AddDays(6);
|
||||
|
||||
var fileBytes = await ExcelExporter.GenerateExcelExportAsync(
|
||||
userId,
|
||||
mondayDate,
|
||||
sundayDate,
|
||||
$"Wochenbericht KW {System.Globalization.ISOWeek.GetWeekOfYear(new DateTime(mondayDate.Year, mondayDate.Month, mondayDate.Day))}",
|
||||
trackerService,
|
||||
db);
|
||||
|
||||
return Results.File(
|
||||
fileBytes,
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
$"Wochenbericht_KW_{System.Globalization.ISOWeek.GetWeekOfYear(new DateTime(mondayDate.Year, mondayDate.Month, mondayDate.Day))}_{mondayDate:yyyyMMdd}.xlsx");
|
||||
}
|
||||
return Results.BadRequest("Ungültiges Datum.");
|
||||
});
|
||||
|
||||
trackerApi.MapGet("/export/month", async (ClaimsPrincipal claimsPrincipal, [FromQuery] int year, [FromQuery] int month, ITimetrackerService trackerService, TimetrackerDbContext db) =>
|
||||
{
|
||||
var idClaim = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
if (!int.TryParse(idClaim, out var userId)) return Results.Unauthorized();
|
||||
|
||||
if (month < 1 || month > 12) return Results.BadRequest("Ungültiger Monat.");
|
||||
|
||||
var startDate = new DateOnly(year, month, 1);
|
||||
var endDate = startDate.AddMonths(1).AddDays(-1);
|
||||
|
||||
var deCulture = new System.Globalization.CultureInfo("de-DE");
|
||||
var monthName = deCulture.DateTimeFormat.GetMonthName(month);
|
||||
|
||||
var fileBytes = await ExcelExporter.GenerateExcelExportAsync(
|
||||
userId,
|
||||
startDate,
|
||||
endDate,
|
||||
$"Monatsbericht {monthName} {year}",
|
||||
trackerService,
|
||||
db);
|
||||
|
||||
return Results.File(
|
||||
fileBytes,
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
$"Monatsbericht_{monthName}_{year}.xlsx");
|
||||
});
|
||||
|
||||
trackerApi.MapGet("/export/year", async (ClaimsPrincipal claimsPrincipal, [FromQuery] int year, ITimetrackerService trackerService, TimetrackerDbContext db) =>
|
||||
{
|
||||
var idClaim = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
if (!int.TryParse(idClaim, out var userId)) return Results.Unauthorized();
|
||||
|
||||
var startDate = new DateOnly(year, 1, 1);
|
||||
var endDate = new DateOnly(year, 12, 31);
|
||||
|
||||
var fileBytes = await ExcelExporter.GenerateExcelExportAsync(
|
||||
userId,
|
||||
startDate,
|
||||
endDate,
|
||||
$"Jahresbericht {year}",
|
||||
trackerService,
|
||||
db);
|
||||
|
||||
return Results.File(
|
||||
fileBytes,
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
$"Jahresbericht_{year}.xlsx");
|
||||
});
|
||||
|
||||
// ── Holiday-API-Endpoints (Protected) ─────────────────────────────────────────
|
||||
var holidaysApi = app.MapGroup("/api/holidays").RequireAuthorization();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user