Implement movie fetching
This commit is contained in:
@@ -1,7 +1,24 @@
|
|||||||
@page "/favorites"
|
@page "/favorites"
|
||||||
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
<PageTitle>Favorites</PageTitle>
|
<PageTitle>Favorites</PageTitle>
|
||||||
|
|
||||||
<h1>TODO</h1>
|
<h1>TODO</h1>
|
||||||
|
|
||||||
|
<button class="btn btn-primary" @onclick="FaiCose">FaiCose</button>
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
builder.Services.AddRazorComponents()
|
builder.Services.AddRazorComponents()
|
||||||
.AddInteractiveServerComponents();
|
.AddInteractiveServerComponents();
|
||||||
|
|
||||||
|
// Mine services
|
||||||
|
builder.Services.AddSingleton<OmdbService>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
using System.Reflection.Metadata;
|
||||||
|
|
||||||
class OmdbService
|
class OmdbService
|
||||||
{
|
{
|
||||||
private readonly string url;
|
private readonly string url;
|
||||||
@@ -9,16 +11,26 @@ class OmdbService
|
|||||||
var apiKey = File.ReadAllText("APIKey.txt").Trim();
|
var apiKey = File.ReadAllText("APIKey.txt").Trim();
|
||||||
apiKey = System.Net.WebUtility.UrlEncode(apiKey);
|
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<string> 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<string> 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
24
test-alebro.sln
Normal file
24
test-alebro.sln
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user