-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCollection.cs
More file actions
95 lines (81 loc) · 3.06 KB
/
Copy pathCollection.cs
File metadata and controls
95 lines (81 loc) · 3.06 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
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using Appwrite.Enums;
using Appwrite.Extensions;
namespace Appwrite.Models
{
public class Collection
{
[JsonPropertyName("$id")]
public string Id { get; private set; }
[JsonPropertyName("$createdAt")]
public string CreatedAt { get; private set; }
[JsonPropertyName("$updatedAt")]
public string UpdatedAt { get; private set; }
[JsonPropertyName("$permissions")]
public List<string> Permissions { get; private set; }
[JsonPropertyName("databaseId")]
public string DatabaseId { get; private set; }
[JsonPropertyName("name")]
public string Name { get; private set; }
[JsonPropertyName("enabled")]
public bool Enabled { get; private set; }
[JsonPropertyName("documentSecurity")]
public bool DocumentSecurity { get; private set; }
[JsonPropertyName("attributes")]
public List<object> Attributes { get; private set; }
[JsonPropertyName("indexes")]
public List<Index> Indexes { get; private set; }
public Collection(
string id,
string createdAt,
string updatedAt,
List<string> permissions,
string databaseId,
string name,
bool enabled,
bool documentSecurity,
List<object> attributes,
List<Index> indexes
) {
Id = id;
CreatedAt = createdAt;
UpdatedAt = updatedAt;
Permissions = permissions;
DatabaseId = databaseId;
Name = name;
Enabled = enabled;
DocumentSecurity = documentSecurity;
Attributes = attributes;
Indexes = indexes;
}
public static Collection From(Dictionary<string, object> map) => new Collection(
id: map["$id"].ToString(),
createdAt: map["$createdAt"].ToString(),
updatedAt: map["$updatedAt"].ToString(),
permissions: map["$permissions"].ConvertToList<string>(),
databaseId: map["databaseId"].ToString(),
name: map["name"].ToString(),
enabled: (bool)map["enabled"],
documentSecurity: (bool)map["documentSecurity"],
attributes: map["attributes"].ConvertToList<object>(),
indexes: map["indexes"].ConvertToList<Dictionary<string, object>>().Select(it => Index.From(map: it)).ToList()
);
public Dictionary<string, object?> ToMap() => new Dictionary<string, object?>()
{
{ "$id", Id },
{ "$createdAt", CreatedAt },
{ "$updatedAt", UpdatedAt },
{ "$permissions", Permissions },
{ "databaseId", DatabaseId },
{ "name", Name },
{ "enabled", Enabled },
{ "documentSecurity", DocumentSecurity },
{ "attributes", Attributes },
{ "indexes", Indexes.Select(it => it.ToMap()) }
};
}
}