-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroup.cs
More file actions
101 lines (77 loc) · 3.33 KB
/
Copy pathGroup.cs
File metadata and controls
101 lines (77 loc) · 3.33 KB
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
using System.ComponentModel.DataAnnotations;
using System.IO.Hashing;
using System.Text;
namespace SplitzBackend.Models;
public class Group
{
public Guid GroupId { get; set; }
[Required]
[MinLength(1, ErrorMessage = "Group name cannot be empty")]
[MaxLength(256)]
public required string Name { get; set; }
[MaxLength(256)] public string? Photo { get; set; }
public List<SplitzUser> Members { get; set; } = new();
[MaxLength(16)] public required string MembersIdHash { get; set; }
public List<Transaction> Transactions { get; set; } = new();
public List<GroupBalance> Balances { get; set; } = new();
/// <summary>
/// The number of transactions of the group.
/// This number is only for searching purposes and may not be accurate if transactions are deleted or modified.
/// </summary>
[Range(0, int.MaxValue, ErrorMessage = "Transaction count cannot be negative")]
public required int TransactionCount { get; set; } = 0;
/// <summary>
/// The date of the last transaction of the group.
/// This is only for searching purposes and may not be accurate if transactions are deleted or modified.
/// </summary>
public required DateTime LastActivityTime { get; set; } = DateTime.UtcNow;
public void UpdateMembersIdHash()
{
// use xxhash3 to create membersIdHash
var membersId = string.Join(",", Members.Select(m => m.Id).OrderBy(m => m));
var xxhash3 = XxHash3.Hash(Encoding.UTF8.GetBytes(membersId));
MembersIdHash = Convert.ToHexString(xxhash3).ToLower();
}
}
public class GroupDto
{
public required Guid GroupId { get; set; }
[Required]
[MinLength(1, ErrorMessage = "Group name cannot be empty")]
[MaxLength(256)]
public required string Name { get; set; }
[MaxLength(256)] public string? Photo { get; set; }
public required List<SplitzUserReducedDto> Members { get; set; } = new();
[MaxLength(16)] public required string MembersIdHash { get; set; }
public required List<GroupBalanceDto> Balances { get; set; } = new();
/// <summary>
/// The number of transactions between the user and their friend.
/// This number is only for searching purposes and may not be accurate if transactions are deleted or modified.
/// </summary>
[Range(0, int.MaxValue, ErrorMessage = "Transaction count cannot be negative")]
public required int TransactionCount { get; set; } = 0;
/// <summary>
/// The date of the last transaction between the user and their friend.
/// This is only for searching purposes and may not be accurate if transactions are deleted or modified.
/// </summary>
public required DateTime LastActivityTime { get; set; } = DateTime.UtcNow;
}
public class GroupReducedDto
{
public required Guid GroupId { get; set; }
[Required]
[MinLength(1, ErrorMessage = "Group name cannot be empty")]
[MaxLength(256)]
public required string Name { get; set; }
[MaxLength(256)] public string? Photo { get; set; }
}
public class GroupInputDto
{
[Required]
[MinLength(1, ErrorMessage = "Group name cannot be empty")]
[MaxLength(256)]
public required string Name { get; set; }
[Required]
[MinLength(1, ErrorMessage = "At least one member is required")]
public required List<string> MembersId { get; set; }
}