Skip to content

Commit 5609ce8

Browse files
authored
Merge pull request #67 from appwrite/dev
Add inc/dec
2 parents 713a790 + 4319bd1 commit 5609ce8

17 files changed

+173
-41
lines changed

Appwrite/Appwrite.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
44
<PackageId>Appwrite</PackageId>
5-
<Version>0.14.0</Version>
5+
<Version>0.15.0</Version>
66
<Authors>Appwrite Team</Authors>
77
<Company>Appwrite Team</Company>
88
<Description>

Appwrite/Client.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public Client(
6969
_headers = new Dictionary<string, string>()
7070
{
7171
{ "content-type", "application/json" },
72-
{ "user-agent" , $"AppwriteDotNetSDK/0.14.0 ({Environment.OSVersion.Platform}; {Environment.OSVersion.VersionString})"},
72+
{ "user-agent" , $"AppwriteDotNetSDK/0.15.0 ({Environment.OSVersion.Platform}; {Environment.OSVersion.VersionString})"},
7373
{ "x-sdk-name", ".NET" },
7474
{ "x-sdk-platform", "server" },
7575
{ "x-sdk-language", "dotnet" },
76-
{ "x-sdk-version", "0.14.0"},
76+
{ "x-sdk-version", "0.15.0"},
7777
{ "X-Appwrite-Response-Format", "1.7.0" }
7878
};
7979

Appwrite/Models/AttributeString.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public class AttributeString
3939
[JsonPropertyName("default")]
4040
public string? Default { get; private set; }
4141

42+
[JsonPropertyName("encrypt")]
43+
public bool? Encrypt { get; private set; }
44+
4245
public AttributeString(
4346
string key,
4447
string type,
@@ -49,7 +52,8 @@ public AttributeString(
4952
string createdAt,
5053
string updatedAt,
5154
long size,
52-
string? xdefault
55+
string? xdefault,
56+
bool? encrypt
5357
) {
5458
Key = key;
5559
Type = type;
@@ -61,6 +65,7 @@ public AttributeString(
6165
UpdatedAt = updatedAt;
6266
Size = size;
6367
Default = xdefault;
68+
Encrypt = encrypt;
6469
}
6570

6671
public static AttributeString From(Dictionary<string, object> map) => new AttributeString(
@@ -73,7 +78,8 @@ public AttributeString(
7378
createdAt: map["$createdAt"].ToString(),
7479
updatedAt: map["$updatedAt"].ToString(),
7580
size: Convert.ToInt64(map["size"]),
76-
xdefault: map.TryGetValue("default", out var xdefault) ? xdefault?.ToString() : null
81+
xdefault: map.TryGetValue("default", out var xdefault) ? xdefault?.ToString() : null,
82+
encrypt: (bool?)map["encrypt"]
7783
);
7884

7985
public Dictionary<string, object?> ToMap() => new Dictionary<string, object?>()
@@ -87,7 +93,8 @@ public AttributeString(
8793
{ "$createdAt", CreatedAt },
8894
{ "$updatedAt", UpdatedAt },
8995
{ "size", Size },
90-
{ "default", Default }
96+
{ "default", Default },
97+
{ "encrypt", Encrypt }
9198
};
9299
}
93100
}

Appwrite/Models/Document.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class Document
1212
[JsonPropertyName("$id")]
1313
public string Id { get; private set; }
1414

15+
[JsonPropertyName("$sequence")]
16+
public long Sequence { get; private set; }
17+
1518
[JsonPropertyName("$collectionId")]
1619
public string CollectionId { get; private set; }
1720

@@ -31,6 +34,7 @@ public class Document
3134

3235
public Document(
3336
string id,
37+
long sequence,
3438
string collectionId,
3539
string databaseId,
3640
string createdAt,
@@ -39,6 +43,7 @@ public Document(
3943
Dictionary<string, object> data
4044
) {
4145
Id = id;
46+
Sequence = sequence;
4247
CollectionId = collectionId;
4348
DatabaseId = databaseId;
4449
CreatedAt = createdAt;
@@ -49,17 +54,19 @@ Dictionary<string, object> data
4954

5055
public static Document From(Dictionary<string, object> map) => new Document(
5156
id: map["$id"].ToString(),
57+
sequence: Convert.ToInt64(map["$sequence"]),
5258
collectionId: map["$collectionId"].ToString(),
5359
databaseId: map["$databaseId"].ToString(),
5460
createdAt: map["$createdAt"].ToString(),
5561
updatedAt: map["$updatedAt"].ToString(),
56-
permissions: map["$permissions"] is JsonElement jsonArrayProp6 ? jsonArrayProp6.Deserialize<List<string>>()! : (List<string>)map["$permissions"],
62+
permissions: map["$permissions"] is JsonElement jsonArrayProp7 ? jsonArrayProp7.Deserialize<List<string>>()! : (List<string>)map["$permissions"],
5763
data: map
5864
);
5965

6066
public Dictionary<string, object?> ToMap() => new Dictionary<string, object?>()
6167
{
6268
{ "$id", Id },
69+
{ "$sequence", Sequence },
6370
{ "$collectionId", CollectionId },
6471
{ "$databaseId", DatabaseId },
6572
{ "$createdAt", CreatedAt },

Appwrite/Services/Account.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public Task<object> DeleteMfaAuthenticator(Appwrite.Enums.AuthenticatorType type
384384

385385
var apiParameters = new Dictionary<string, object?>()
386386
{
387-
{ "factor", factor }
387+
{ "factor", factor?.Value }
388388
};
389389

390390
var apiHeaders = new Dictionary<string, string>()

Appwrite/Services/Databases.cs

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -925,11 +925,11 @@ static Models.AttributeIp Convert(Dictionary<string, object> it) =>
925925
var apiParameters = new Dictionary<string, object?>()
926926
{
927927
{ "relatedCollectionId", relatedCollectionId },
928-
{ "type", type },
928+
{ "type", type?.Value },
929929
{ "twoWay", twoWay },
930930
{ "key", key },
931931
{ "twoWayKey", twoWayKey },
932-
{ "onDelete", onDelete }
932+
{ "onDelete", onDelete?.Value }
933933
};
934934

935935
var apiHeaders = new Dictionary<string, string>()
@@ -1177,7 +1177,7 @@ public Task<object> DeleteAttribute(string databaseId, string collectionId, stri
11771177

11781178
var apiParameters = new Dictionary<string, object?>()
11791179
{
1180-
{ "onDelete", onDelete },
1180+
{ "onDelete", onDelete?.Value },
11811181
{ "newKey", newKey }
11821182
};
11831183

@@ -1319,6 +1319,7 @@ static Models.DocumentList Convert(Dictionary<string, object> it) =>
13191319
/// new collection resource using either a [server
13201320
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
13211321
/// API or directly from your database console.
1322+
///
13221323
/// </para>
13231324
/// </summary>
13241325
public Task<Models.DocumentList> UpsertDocuments(string databaseId, string collectionId, List<object> documents)
@@ -1570,6 +1571,78 @@ public Task<object> DeleteDocument(string databaseId, string collectionId, strin
15701571

15711572
}
15721573

1574+
/// <para>
1575+
/// Decrement a specific attribute of a document by a given value.
1576+
/// </para>
1577+
/// </summary>
1578+
public Task<Models.Document> DecrementDocumentAttribute(string databaseId, string collectionId, string documentId, string attribute, double? xvalue = null, double? min = null)
1579+
{
1580+
var apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement"
1581+
.Replace("{databaseId}", databaseId)
1582+
.Replace("{collectionId}", collectionId)
1583+
.Replace("{documentId}", documentId)
1584+
.Replace("{attribute}", attribute);
1585+
1586+
var apiParameters = new Dictionary<string, object?>()
1587+
{
1588+
{ "value", xvalue },
1589+
{ "min", min }
1590+
};
1591+
1592+
var apiHeaders = new Dictionary<string, string>()
1593+
{
1594+
{ "content-type", "application/json" }
1595+
};
1596+
1597+
1598+
static Models.Document Convert(Dictionary<string, object> it) =>
1599+
Models.Document.From(map: it);
1600+
1601+
return _client.Call<Models.Document>(
1602+
method: "PATCH",
1603+
path: apiPath,
1604+
headers: apiHeaders,
1605+
parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!,
1606+
convert: Convert);
1607+
1608+
}
1609+
1610+
/// <para>
1611+
/// Increment a specific attribute of a document by a given value.
1612+
/// </para>
1613+
/// </summary>
1614+
public Task<Models.Document> IncrementDocumentAttribute(string databaseId, string collectionId, string documentId, string attribute, double? xvalue = null, double? max = null)
1615+
{
1616+
var apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment"
1617+
.Replace("{databaseId}", databaseId)
1618+
.Replace("{collectionId}", collectionId)
1619+
.Replace("{documentId}", documentId)
1620+
.Replace("{attribute}", attribute);
1621+
1622+
var apiParameters = new Dictionary<string, object?>()
1623+
{
1624+
{ "value", xvalue },
1625+
{ "max", max }
1626+
};
1627+
1628+
var apiHeaders = new Dictionary<string, string>()
1629+
{
1630+
{ "content-type", "application/json" }
1631+
};
1632+
1633+
1634+
static Models.Document Convert(Dictionary<string, object> it) =>
1635+
Models.Document.From(map: it);
1636+
1637+
return _client.Call<Models.Document>(
1638+
method: "PATCH",
1639+
path: apiPath,
1640+
headers: apiHeaders,
1641+
parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!,
1642+
convert: Convert);
1643+
1644+
}
1645+
15731646
/// <para>
15741647
/// List indexes in the collection.
15751648
/// </para>
@@ -1617,7 +1690,7 @@ static Models.IndexList Convert(Dictionary<string, object> it) =>
16171690
var apiParameters = new Dictionary<string, object?>()
16181691
{
16191692
{ "key", key },
1620-
{ "type", type },
1693+
{ "type", type?.Value },
16211694
{ "attributes", attributes },
16221695
{ "orders", orders },
16231696
{ "lengths", lengths }

Appwrite/Services/Functions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static Models.FunctionList Convert(Dictionary<string, object> it) =>
6161
{
6262
{ "functionId", functionId },
6363
{ "name", name },
64-
{ "runtime", runtime },
64+
{ "runtime", runtime?.Value },
6565
{ "execute", execute },
6666
{ "events", events },
6767
{ "schedule", schedule },
@@ -197,7 +197,7 @@ static Models.Function Convert(Dictionary<string, object> it) =>
197197
var apiParameters = new Dictionary<string, object?>()
198198
{
199199
{ "name", name },
200-
{ "runtime", runtime },
200+
{ "runtime", runtime?.Value },
201201
{ "execute", execute },
202202
{ "events", events },
203203
{ "schedule", schedule },
@@ -466,7 +466,7 @@ static Models.Deployment Convert(Dictionary<string, object> it) =>
466466

467467
var apiParameters = new Dictionary<string, object?>()
468468
{
469-
{ "type", type },
469+
{ "type", type?.Value },
470470
{ "reference", reference },
471471
{ "activate", activate }
472472
};
@@ -563,7 +563,7 @@ public Task<byte[]> GetDeploymentDownload(string functionId, string deploymentId
563563

564564
var apiParameters = new Dictionary<string, object?>()
565565
{
566-
{ "type", type }
566+
{ "type", type?.Value }
567567
};
568568

569569
var apiHeaders = new Dictionary<string, string>()
@@ -665,7 +665,7 @@ static Models.ExecutionList Convert(Dictionary<string, object> it) =>
665665
{ "body", body },
666666
{ "async", xasync },
667667
{ "path", xpath },
668-
{ "method", method },
668+
{ "method", method?.Value },
669669
{ "headers", headers },
670670
{ "scheduledAt", scheduledAt }
671671
};

Appwrite/Services/Messaging.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static Models.Message Convert(Dictionary<string, object> it) =>
160160
{ "scheduledAt", scheduledAt },
161161
{ "contentAvailable", contentAvailable },
162162
{ "critical", critical },
163-
{ "priority", priority }
163+
{ "priority", priority?.Value }
164164
};
165165

166166
var apiHeaders = new Dictionary<string, string>()
@@ -212,7 +212,7 @@ static Models.Message Convert(Dictionary<string, object> it) =>
212212
{ "scheduledAt", scheduledAt },
213213
{ "contentAvailable", contentAvailable },
214214
{ "critical", critical },
215-
{ "priority", priority }
215+
{ "priority", priority?.Value }
216216
};
217217

218218
var apiHeaders = new Dictionary<string, string>()
@@ -851,7 +851,7 @@ static Models.Provider Convert(Dictionary<string, object> it) =>
851851
{ "port", port },
852852
{ "username", username },
853853
{ "password", password },
854-
{ "encryption", encryption },
854+
{ "encryption", encryption?.Value },
855855
{ "autoTLS", autoTLS },
856856
{ "mailer", mailer },
857857
{ "fromName", fromName },
@@ -895,7 +895,7 @@ static Models.Provider Convert(Dictionary<string, object> it) =>
895895
{ "port", port },
896896
{ "username", username },
897897
{ "password", password },
898-
{ "encryption", encryption },
898+
{ "encryption", encryption?.Value },
899899
{ "autoTLS", autoTLS },
900900
{ "mailer", mailer },
901901
{ "fromName", fromName },

Appwrite/Services/Sites.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ static Models.SiteList Convert(Dictionary<string, object> it) =>
5858
{
5959
{ "siteId", siteId },
6060
{ "name", name },
61-
{ "framework", framework },
61+
{ "framework", framework?.Value },
6262
{ "enabled", enabled },
6363
{ "logging", logging },
6464
{ "timeout", timeout },
6565
{ "installCommand", installCommand },
6666
{ "buildCommand", buildCommand },
6767
{ "outputDirectory", outputDirectory },
68-
{ "buildRuntime", buildRuntime },
69-
{ "adapter", adapter },
68+
{ "buildRuntime", buildRuntime?.Value },
69+
{ "adapter", adapter?.Value },
7070
{ "installationId", installationId },
7171
{ "fallbackFile", fallbackFile },
7272
{ "providerRepositoryId", providerRepositoryId },
@@ -195,15 +195,15 @@ static Models.Site Convert(Dictionary<string, object> it) =>
195195
var apiParameters = new Dictionary<string, object?>()
196196
{
197197
{ "name", name },
198-
{ "framework", framework },
198+
{ "framework", framework?.Value },
199199
{ "enabled", enabled },
200200
{ "logging", logging },
201201
{ "timeout", timeout },
202202
{ "installCommand", installCommand },
203203
{ "buildCommand", buildCommand },
204204
{ "outputDirectory", outputDirectory },
205-
{ "buildRuntime", buildRuntime },
206-
{ "adapter", adapter },
205+
{ "buildRuntime", buildRuntime?.Value },
206+
{ "adapter", adapter?.Value },
207207
{ "fallbackFile", fallbackFile },
208208
{ "installationId", installationId },
209209
{ "providerRepositoryId", providerRepositoryId },
@@ -457,7 +457,7 @@ static Models.Deployment Convert(Dictionary<string, object> it) =>
457457

458458
var apiParameters = new Dictionary<string, object?>()
459459
{
460-
{ "type", type },
460+
{ "type", type?.Value },
461461
{ "reference", reference },
462462
{ "activate", activate }
463463
};
@@ -554,7 +554,7 @@ public Task<byte[]> GetDeploymentDownload(string siteId, string deploymentId, Ap
554554

555555
var apiParameters = new Dictionary<string, object?>()
556556
{
557-
{ "type", type }
557+
{ "type", type?.Value }
558558
};
559559

560560
var apiHeaders = new Dictionary<string, string>()

0 commit comments

Comments
 (0)