summaryrefslogtreecommitdiffstats
path: root/server/src/Data/Dtos/UserArchiveDto.cs
blob: 63b1470c2aa85d75eb604a376dfbfa8df8367e69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
namespace IOL.GreatOffice.Api.Data.Dtos;

/// <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 = DateTime.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; }
	}
}