diff --git a/PcgsInvUi/Services/CoinCollection.cs b/PcgsInvUi/Services/CoinCollection.cs deleted file mode 100644 index dc89845..0000000 --- a/PcgsInvUi/Services/CoinCollection.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections.Generic; -using PcgsInvUi.Models; - -namespace PcgsInvUi.Services; - -public class CoinCollection { - public IEnumerable GetItems() => new[] { - new Coin(), - new Coin(), - new Coin(), - }; -} \ No newline at end of file diff --git a/PcgsInvUi/Services/CoinDatabase.cs b/PcgsInvUi/Services/CoinDatabase.cs index 194fbf4..03e6cc1 100644 --- a/PcgsInvUi/Services/CoinDatabase.cs +++ b/PcgsInvUi/Services/CoinDatabase.cs @@ -76,11 +76,12 @@ public class CoinDatabase { /// /// Atttempts to initialize the PCGS API client. /// + /// The API key to verify. /// A Task with a return value that returns true if the client intializes properly. public async Task TryInitApiClient(string apiKey) { Console.Write("Attempting to initialize API client with key param... "); _pcgsClient = await PcgsClient.CreateClient(apiKey); - // TODO Check if the API key is valid and if it is, then add to the database. + // Check if the API key is valid and if it is, then add to the database. if (_pcgsClient is null) { IsClientConnected = false; Console.WriteLine("Failed. API key was invalid."); @@ -150,6 +151,9 @@ public class CoinDatabase { Console.WriteLine("API table initialized."); } + /// + /// Creates a table to store the collection. + /// public void CreateCollection(string collectionName) { // Create a table to store the collection. if (!IsConnected) { @@ -436,3 +440,7 @@ public class CoinDatabase { return actualGrade; } } + +public class NotConnectedToDatabaseException : Exception { + public NotConnectedToDatabaseException() : base("Not connected to database.") { } +} diff --git a/PcgsInvUi/Services/PcgsClient.cs b/PcgsInvUi/Services/PcgsClient.cs index 9602343..0f70915 100644 --- a/PcgsInvUi/Services/PcgsClient.cs +++ b/PcgsInvUi/Services/PcgsClient.cs @@ -31,7 +31,6 @@ public class PcgsClient : ReactiveObject { /// private PcgsClient(string apiKey) { _apiKey = apiKey; - // "E8xivTVN_k4Q8ubk8Xv_uU11U91WX0wDht4S4m4BAf2HPmKnGrZ0J2f9nccM7Ns1VkGoT1SXYR74I7aNaMKqXlJGEy3oobseKV0nGiqu1IKvFkOTVjhV37SWUVExSDFMC6FLzs7xJQIHwkcxr5JFOQNmc4ZytEh_-hmCN3NL-z0fEk98tzBmPJ_F7bq_xNru86QMD2A9yalu_dWe-lCysfyE2bCA2EDqwvWenRYf-0XnNtp6qlxxCMlCd-TDqqRKLC3qefCwpXSemwBiNSP5gbC9pwcKrZugkruuJ0nyxxThZymm"; } /// @@ -47,6 +46,10 @@ public class PcgsClient : ReactiveObject { return testClient; } + /// + /// Sends a request to the API to verify the credentials. + /// + /// A boolean indicating whether or not the credentials are valid. public async Task VerifyCredentials() { // Create a way to check if the api key given is valid // I think the best way to do this is to make a request to the api and see if it returns the expected response. @@ -55,6 +58,13 @@ public class PcgsClient : ReactiveObject { return true; } + /// + /// Gets the coin information for a given PCGS number and grade. + /// + /// The PCGS number of the coin. + /// The grade of the coin. + /// Whether or not the coin is a plus grade. + /// A tuple containing the error type and the coin information. public async Task<(ErrorType, Coin?)> GetCoinFactsByGrade(int pcgsNumber, string grade, bool plusGrade = false) { using (HttpClient client = new HttpClient()) { var gradeParam = GetGradeFromString(grade); @@ -77,15 +87,25 @@ public class PcgsClient : ReactiveObject { return (ErrorType.ApiKeyInvalid, null); } + /// + /// Utility function to parse the grade number from the grade string passed from the front end. + /// + /// The grade string. + /// The grade number. private int GetGradeFromString(string grade) { var actualGrade = int.Parse(grade.Substring(grade.Length - 2)); // Throws an exception if the grade doesn't exist. Console.WriteLine($"Grade is {actualGrade}"); return actualGrade; } + /// + /// Parses the json response from the api. + /// + /// The json response. + /// A tuple containing an error type and the coin information. private (ErrorType, Coin?) ParseJsonResponse(string json) { Console.WriteLine(json); - // TODO Check for errors in the response + // Check for errors in the response if (json.Contains("\"ServerMessage\":\"No data found\"")) return (ErrorType.NoCoinFound, null); if (json.Contains("\"IsValidRequest\":false")) return (ErrorType.InvalidRequestFormat, null); diff --git a/PcgsInvUi/ViewModels/ApiKeyViewModel.cs b/PcgsInvUi/ViewModels/ApiKeyViewModel.cs index 6f2f9a7..468b2dd 100644 --- a/PcgsInvUi/ViewModels/ApiKeyViewModel.cs +++ b/PcgsInvUi/ViewModels/ApiKeyViewModel.cs @@ -1,6 +1,5 @@ using ReactiveUI; using System.Reactive; -using System; namespace PcgsInvUi.ViewModels;