Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update playground for SDK version 0.4.2 #15

Merged
merged 5 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 17 additions & 46 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ public static async Task Main(string[] args)
/**
Create Database
*/

try
{
Console.WriteLine("Running Create Database API");
database = await databases.Create(
databaseId: ID.Unique(),
name: "MoviesDB"
);
name: "MoviesDB");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right position for the closing bracket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the style recommended in the C# Coding Conventions

Console.WriteLine("Done");
}
catch (AppwriteException e)
{
Console.WriteLine($"Error: {e.Message}");
throw;
}

/**
Expand All @@ -55,45 +54,38 @@ Create Collection
databaseId: database.Id,
collectionId: ID.Unique(),
name: "Movies",
permissions: new List<string> { Permission.Read(Role.Any()), Permission.Write(Role.Any()) }
);

permissions: new List<string> { Permission.Read(Role.Any()), Permission.Write(Role.Any()) });
Console.WriteLine("Creating Attribute \"name\"");

await databases.CreateStringAttribute(
databaseId: database.Id,
collectionId: collection.Id,
key: "name",
size: 255,
required: true
);

required: true);
Console.WriteLine("Creating Attribute \"release_year\"");

await databases.CreateIntegerAttribute(
databaseId: database.Id,
collectionId: collection.Id,
key: "release_year",
required: true
);

required: true);
Console.WriteLine("Done");
}
catch (AppwriteException e)
{
Console.WriteLine($"Error: {e.Message}");
throw;
}

/**
List Collections
*/

try
{
Console.WriteLine("Running List Collection API");
var collectionsList = await databases.ListCollections(
databaseId: database.Id
);
databaseId: database.Id);
foreach (var element in collectionsList.Collections)
{
Console.WriteLine($"- {element.Name}");
Expand All @@ -102,12 +94,12 @@ List Collections
catch (AppwriteException e)
{
Console.WriteLine($"Error: {e.Message}");
throw;
}

/**
Add Document
*/

Movie movie1 = new Movie("Alien", 1979);
Movie movie2 = new Movie("Equilibrium", 2002);
try
Expand All @@ -117,32 +109,29 @@ await databases.CreateDocument(
databaseId: database.Id,
collectionId: collection.Id,
documentId: ID.Unique(),
data: movie1
);
data: movie1);
await databases.CreateDocument(
databaseId: database.Id,
collectionId: collection.Id,
documentId: ID.Unique(),
data: movie2
);
data: movie2);
Console.WriteLine("Done");
}
catch (AppwriteException e)
{
Console.WriteLine($"Error: {e.Message}");
throw;
}

/**
List Documents
*/

try
{
Console.WriteLine("Running List Documents API");
var documentsList = await databases.ListDocuments(
databaseId: database.Id,
collectionId: collection.Id
);
collectionId: collection.Id);
foreach (var element in documentsList.Documents)
{
var movie = JsonConvert.DeserializeObject<Movie>(JsonConvert.SerializeObject(element.Data));
Expand All @@ -152,7 +141,6 @@ List Documents
catch (AppwriteException e)
{
Console.WriteLine($"Error: {e.Message}");
throw;
}

/**
Expand All @@ -166,15 +154,12 @@ Create Bucket
bucket = await storage.CreateBucket(
bucketId: ID.Unique(),
name: "Files",
permissions: new List<string> { Permission.Read(Role.Any()), Permission.Write(Role.Any()) }
);

permissions: new List<string> { Permission.Read(Role.Any()), Permission.Write(Role.Any()) });
Console.WriteLine("Done");
}
catch (AppwriteException e)
{
Console.WriteLine($"Error: {e.Message}");
throw;
}

/**
Expand All @@ -184,20 +169,16 @@ Create File
try
{
Console.WriteLine("Running Create File API");

var file = await storage.CreateFile(
bucketId: bucket.Id,
fileId: ID.Unique(),
file: InputFile.FromPath("[DIRECTORY_PATH]/appwrite-overview.png"),
permissions: new List<string> { Permission.Read(Role.Any()), Permission.Write(Role.Any()) }
);

file: InputFile.FromPath("appwrite-overview.png"),
permissions: new List<string> { Permission.Read(Role.Any()), Permission.Write(Role.Any()) });
Console.WriteLine("Done");
}
catch (AppwriteException e)
{
Console.WriteLine($"Error: {e.Message}");
throw;
}

/**
Expand All @@ -207,19 +188,14 @@ Create Function Execution
try
{
Console.WriteLine("Running Create Function Execution API");

var execution = await functions.CreateExecution(
functionId: "[FUNCTION_ID]"
);

functionId: "[FUNCTION_ID]");
Console.WriteLine($"Response Message: {execution.Response}");

Console.WriteLine("Done");
}
catch (AppwriteException e)
{
Console.WriteLine($"Error: {e.Message}");
throw;
}

/**
Expand All @@ -229,20 +205,16 @@ Create User
try
{
Console.WriteLine("Running Create User API");

var user = await users.Create(
userId: ID.Unique(),
email: "[email protected]",
password: "test12345",
name: "Walter O' Brian"
);

name: "Walter O' Brian");
Console.WriteLine("Done");
}
catch (AppwriteException e)
{
Console.WriteLine($"Error: {e.Message}");
throw;
}
}
}
Expand All @@ -257,6 +229,5 @@ public Movie(string name, int releaseYear)
public string Name { get; }
[JsonProperty("release_year")]
public int ReleaseYear { get; }

}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Restore all project dependencies:
```sh
dotnet restore
```
Replace `[ENDPOINT]`, `[PROJECT_ID]` and `[API_KEY]` with your credentials, `[FUNCTION_ID]` with the id of any Appwrite function you would like to test and `[DIRECTORY_PATH]` with the path of your project directory in *Program.cs*.
Replace `[ENDPOINT]`, `[PROJECT_ID]` and `[API_KEY]` with your credentials, and `[FUNCTION_ID]` with the id of any Appwrite function you would like to test in *Program.cs*.

To run your Playground, run following command:

Expand Down
7 changes: 6 additions & 1 deletion playground-for-dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
<RootNamespace>playground_for_dotnet</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Appwrite" Version="0.4.1" />
<PackageReference Include="Appwrite" Version="0.4.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<None Update="appwrite-overview.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>