-
Notifications
You must be signed in to change notification settings - Fork 7
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed4e987
Refactor code to follow C# conventions
adityaoberai 3a41fa7
Include image in build output directory for Storage API example
adityaoberai 30d4beb
Remove unnecessary throw statements
adityaoberai e7e2e83
Update sdk version
adityaoberai 2e25182
Merge branch 'main' into main
adityaoberai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
Console.WriteLine("Done"); | ||
} | ||
catch (AppwriteException e) | ||
{ | ||
Console.WriteLine($"Error: {e.Message}"); | ||
throw; | ||
} | ||
|
||
/** | ||
|
@@ -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}"); | ||
|
@@ -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 | ||
|
@@ -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)); | ||
|
@@ -152,7 +141,6 @@ List Documents | |
catch (AppwriteException e) | ||
{ | ||
Console.WriteLine($"Error: {e.Message}"); | ||
throw; | ||
} | ||
|
||
/** | ||
|
@@ -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; | ||
} | ||
|
||
/** | ||
|
@@ -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; | ||
} | ||
|
||
/** | ||
|
@@ -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; | ||
} | ||
|
||
/** | ||
|
@@ -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; | ||
} | ||
} | ||
} | ||
|
@@ -257,6 +229,5 @@ public Movie(string name, int releaseYear) | |
public string Name { get; } | ||
[JsonProperty("release_year")] | ||
public int ReleaseYear { get; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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