From b7e39b59fd0fc7b5610ebff29035bf622079e0d8 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Wed, 5 Oct 2022 20:45:21 +0800 Subject: refactor: Change file structure --- .../Endpoints/Internal/Account/GetArchiveRoute.cs | 62 ---------------------- 1 file changed, 62 deletions(-) delete mode 100644 server/src/Endpoints/Internal/Account/GetArchiveRoute.cs (limited to 'server/src/Endpoints/Internal/Account/GetArchiveRoute.cs') diff --git a/server/src/Endpoints/Internal/Account/GetArchiveRoute.cs b/server/src/Endpoints/Internal/Account/GetArchiveRoute.cs deleted file mode 100644 index f1b70f3..0000000 --- a/server/src/Endpoints/Internal/Account/GetArchiveRoute.cs +++ /dev/null @@ -1,62 +0,0 @@ -namespace IOL.GreatOffice.Api.Endpoints.Internal.Account; - -public class GetAccountArchiveRoute : RouteBaseAsync.WithoutRequest.WithActionResult -{ - private readonly AppDbContext _context; - - /// - public GetAccountArchiveRoute(AppDbContext context) { - _context = context; - } - - /// - /// Get a data archive with the currently logged on user's data. - /// - /// - /// - [HttpGet("~/_/account/archive")] - public override async Task> HandleAsync(CancellationToken cancellationToken = default) { - var user = _context.Users.SingleOrDefault(c => c.Id == LoggedInUser.Id); - if (user == default) { - await HttpContext.SignOutAsync(); - return Unauthorized(); - } - - var entries = _context.TimeEntries - .AsNoTracking() - .Include(c => c.Labels) - .Include(c => c.Category) - .Where(c => c.UserId == user.Id) - .ToList(); - - var jsonOptions = new JsonSerializerOptions { - WriteIndented = true - }; - - var dto = new UserArchiveDto(user); - dto.Entries.AddRange(entries.Select(entry => new UserArchiveDto.EntryDto { - CreatedAt = entry.CreatedAt.ToString("yyyy-MM-ddTHH:mm:ssZ"), - StartDateTime = entry.Start, - StopDateTime = entry.Stop, - Description = entry.Description, - Labels = entry.Labels - .Select(c => new UserArchiveDto.LabelDto { - Name = c.Name, - Color = c.Color - }) - .ToList(), - Category = new UserArchiveDto.CategoryDto { - Name = entry.Category.Name, - Color = entry.Category.Color - }, - })); - - dto.CountEntries(); - - var entriesSerialized = JsonSerializer.SerializeToUtf8Bytes(dto, jsonOptions); - - return File(entriesSerialized, - "application/json", - user.Username + "-time-tracker-archive-" + AppDateTime.UtcNow.ToString("yyyyMMddTHHmmss") + ".json"); - } -} -- cgit v1.3