diff --git a/Components/Pages/Favorites.razor b/Components/Pages/Favorites.razor
index a638a0d..932fd64 100644
--- a/Components/Pages/Favorites.razor
+++ b/Components/Pages/Favorites.razor
@@ -1,7 +1,24 @@
@page "/favorites"
+@rendermode InteractiveServer
Favorites
TODO
+
+@inject OmdbService OmdbService
+@inject IJSRuntime JSRuntime
+
+@code {
+ private async Task FaiCose()
+ {
+ await JSRuntime.InvokeVoidAsync("console.log", "Cose fatte!");
+
+ var movies = await OmdbService.FetchMovies("Matrix");
+ var movieDetail = await OmdbService.FetchMovieDetail("tt28228084");
+
+ await JSRuntime.InvokeVoidAsync("console.log", movies);
+ await JSRuntime.InvokeVoidAsync("console.log", movieDetail);
+ }
+}
diff --git a/Program.cs b/Program.cs
index f2f6806..e4ac6c2 100644
--- a/Program.cs
+++ b/Program.cs
@@ -6,6 +6,9 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
+// Mine services
+builder.Services.AddSingleton();
+
var app = builder.Build();
// Configure the HTTP request pipeline.
diff --git a/Services/OmdbService.cs b/Services/OmdbService.cs
index 815304c..08a21c4 100644
--- a/Services/OmdbService.cs
+++ b/Services/OmdbService.cs
@@ -1,5 +1,7 @@
+using System.Reflection.Metadata;
+
class OmdbService
{
private readonly string url;
@@ -9,16 +11,26 @@ class OmdbService
var apiKey = File.ReadAllText("APIKey.txt").Trim();
apiKey = System.Net.WebUtility.UrlEncode(apiKey);
- url = "http://www.omdbapi.com/?apikey=" + apiKey + "&";
+ url = "http://www.omdbapi.com/?apikey=" + apiKey
+ + "&type=movie"
+ + "&r=json";
}
- public async void FetchMovieDetail(string id)
+ public async Task FetchMovieDetail(string id)
{
- // TODO
+ var requestUrl = url + "i=" + System.Net.WebUtility.UrlEncode(id);
+ using var httpClient = new HttpClient();
+
+ var response = await httpClient.GetStringAsync(requestUrl);
+ return response.ToString();
}
- public async void FetchMovies(string searchTitle)
+ public async Task FetchMovies(string searchTitle)
{
- // TODO
+ var requestUrl = url + "&t=" + System.Net.WebUtility.UrlEncode(searchTitle);
+ using var httpClient = new HttpClient();
+
+ var response = await httpClient.GetStringAsync(requestUrl);
+ return response.ToString();
}
}
\ No newline at end of file
diff --git a/test-alebro.sln b/test-alebro.sln
new file mode 100644
index 0000000..4dc2df2
--- /dev/null
+++ b/test-alebro.sln
@@ -0,0 +1,24 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.2.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test-alebro", "test-alebro.csproj", "{80C175CB-7DB0-93BB-681F-01F9DB017FB2}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {80C175CB-7DB0-93BB-681F-01F9DB017FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {80C175CB-7DB0-93BB-681F-01F9DB017FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {80C175CB-7DB0-93BB-681F-01F9DB017FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {80C175CB-7DB0-93BB-681F-01F9DB017FB2}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {4E9E6522-3307-4F89-B6D6-2D4D61E7B65B}
+ EndGlobalSection
+EndGlobal