aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/src/Endpoints/Internal/Account
diff options
context:
space:
mode:
Diffstat (limited to 'code/api/src/Endpoints/Internal/Account')
-rw-r--r--code/api/src/Endpoints/Internal/Account/DeleteAccountRoute.cs8
-rw-r--r--code/api/src/Endpoints/Internal/Account/GetArchiveRoute.cs61
-rw-r--r--code/api/src/Endpoints/Internal/Account/UserArchiveDto.cs131
3 files changed, 0 insertions, 200 deletions
diff --git a/code/api/src/Endpoints/Internal/Account/DeleteAccountRoute.cs b/code/api/src/Endpoints/Internal/Account/DeleteAccountRoute.cs
index 5df1fb6..e5bbb10 100644
--- a/code/api/src/Endpoints/Internal/Account/DeleteAccountRoute.cs
+++ b/code/api/src/Endpoints/Internal/Account/DeleteAccountRoute.cs
@@ -28,17 +28,9 @@ public class DeleteAccountRoute : RouteBaseAsync.WithoutRequest.WithActionResult
return Ok();
}
- var githubMappings = _database.TimeCategories.Where(c => c.UserId == user.Id);
var passwordResets = _database.ForgotPasswordRequests.Where(c => c.UserId == user.Id);
- var entries = _database.TimeEntries.Where(c => c.UserId == user.Id);
- var labels = _database.TimeLabels.Where(c => c.UserId == user.Id);
- var categories = _database.TimeCategories.Where(c => c.UserId == user.Id);
- _database.TimeCategories.RemoveRange(githubMappings);
_database.ForgotPasswordRequests.RemoveRange(passwordResets);
- _database.TimeEntries.RemoveRange(entries);
- _database.TimeLabels.RemoveRange(labels);
- _database.TimeCategories.RemoveRange(categories);
_database.Users.Remove(user);
await _database.SaveChangesAsync(cancellationToken);
diff --git a/code/api/src/Endpoints/Internal/Account/GetArchiveRoute.cs b/code/api/src/Endpoints/Internal/Account/GetArchiveRoute.cs
deleted file mode 100644
index 0d9f817..0000000
--- a/code/api/src/Endpoints/Internal/Account/GetArchiveRoute.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-namespace IOL.GreatOffice.Api.Endpoints.Internal.Account;
-
-public class GetAccountArchiveRoute : RouteBaseAsync.WithoutRequest.WithActionResult<UserArchiveDto>
-{
- private readonly MainAppDatabase _database;
-
- public GetAccountArchiveRoute(MainAppDatabase database) {
- _database = database;
- }
-
- /// <summary>
- /// Get a data archive with the currently logged on user's data.
- /// </summary>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- [HttpGet("~/_/account/archive")]
- public override async Task<ActionResult<UserArchiveDto>> HandleAsync(CancellationToken cancellationToken = default) {
- var user = _database.Users.SingleOrDefault(c => c.Id == LoggedInUser.Id);
- if (user == default) {
- await HttpContext.SignOutAsync();
- return Unauthorized();
- }
-
- var entries = _database.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");
- }
-} \ No newline at end of file
diff --git a/code/api/src/Endpoints/Internal/Account/UserArchiveDto.cs b/code/api/src/Endpoints/Internal/Account/UserArchiveDto.cs
deleted file mode 100644
index 5d259ab..0000000
--- a/code/api/src/Endpoints/Internal/Account/UserArchiveDto.cs
+++ /dev/null
@@ -1,131 +0,0 @@
-
-namespace IOL.GreatOffice.Api.Endpoints.Internal.Account;
-
-/// <summary>
-/// Represents a user archive as it is provided to users.
-/// </summary>
-public class UserArchiveDto
-{
- /// <inheritdoc cref="UserArchiveDto"/>
- public UserArchiveDto(User user) {
- Meta = new MetaDto {
- GeneratedAt = AppDateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ")
- };
- User = new UserDto(user);
- Entries = new List<EntryDto>();
- }
-
- /// <summary>
- /// Metadata for the user archive.
- /// </summary>
- public MetaDto Meta { get; }
-
- /// <summary>
- /// Relevant user data for the archive.
- /// </summary>
- public UserDto User { get; }
-
- /// <summary>
- /// List of entries that the user has created.
- /// </summary>
- public List<EntryDto> Entries { get; }
-
- public void CountEntries() {
- Meta.EntryCount = Entries.Count;
- }
-
- /// <summary>
- /// Represents a time entry in the data archive.
- /// </summary>
- public class EntryDto
- {
- public string CreatedAt { get; init; }
-
- [JsonIgnore]
- public DateTime StartDateTime { get; init; }
-
- /// <summary>
- /// ISO 8601 string of the UTC date the time entry started.
- /// </summary>
- public string Start => StartDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ");
-
- [JsonIgnore]
- public DateTime StopDateTime { get; init; }
-
- /// <summary>
- /// ISO 8601 string of the UTC date the time entry stopped.
- /// </summary>
- public string Stop => StopDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ");
-
- /// <summary>
- /// Total amount of minutes elapsed from start to stop on this time entry.
- /// </summary>
- public double Minutes => StopDateTime.Subtract(StartDateTime).TotalMinutes;
-
- public string Description { get; init; }
-
- /// <summary>
- /// Archive spesific category for this time entry.
- /// </summary>
- public CategoryDto Category { get; init; }
-
- /// <summary>
- /// Archive spesific list of labels for this time entry.
- /// </summary>
- public List<LabelDto> Labels { get; init; }
- }
-
- /// <summary>
- /// Time entry category as it is written to the user archive.
- /// </summary>
- public class CategoryDto
- {
- public string Name { get; init; }
- public string Color { get; init; }
- }
-
- /// <summary>
- /// Time entry label as it is written to the user archive.
- /// </summary>
- public class LabelDto
- {
- public string Name { get; init; }
- public string Color { get; init; }
- }
-
-
- /// <summary>
- /// Represents the user who this archive's data is based on.
- /// </summary>
- public class UserDto
- {
- /// <inheritdoc cref="UserDto"/>
- public UserDto(User user) {
- Username = user.Username;
- CreatedAt = user.CreatedAt;
- }
-
- /// <summary>
- /// UTC date this user was created.
- /// </summary>
- public DateTime CreatedAt { get; }
-
- public string Username { get; }
- }
-
- /// <summary>
- /// Represents the meta object which contains metdata for this archive.
- /// </summary>
- public class MetaDto
- {
- /// <summary>
- /// ISO 8601 UTC date string for when this archive was created.
- /// </summary>
- public string GeneratedAt { get; init; }
-
- /// <summary>
- /// Amount of entries in the archive.
- /// </summary>
- public int EntryCount { get; set; }
- }
-}