| @@ -0,0 +1,16 @@ | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO | |||
| { | |||
| [ProtoContract] | |||
| public class HeaderParams | |||
| { | |||
| [ProtoMember(1)] | |||
| public string Token { get; set; } | |||
| } | |||
| } | |||
| @@ -10,6 +10,7 @@ namespace GrpcShared.DTO.Search | |||
| [ProtoContract] | |||
| public class SearchRequest | |||
| { | |||
| [ProtoMember(1)] | |||
| public string Query { get; set; } | |||
| @@ -24,5 +25,7 @@ namespace GrpcShared.DTO.Search | |||
| [ProtoMember(5)] | |||
| public int Offset { get; set; } | |||
| [ProtoMember(6)] | |||
| public string Token { get; set; } | |||
| } | |||
| } | |||
| @@ -1,57 +1,24 @@ | |||
| @page "/fetchdata" | |||
| @inject HttpClient Http | |||
| @page "/search" | |||
| @using GrpcShared.DTO.Search | |||
| @using NemAnBlazor.Services.Interfaces | |||
| @*@inject HttpClient Http*@ | |||
| @inject Blazored.SessionStorage.ISessionStorageService sessionStorage | |||
| @inject ISearchClientService SearchService | |||
| <PageTitle>Weather forecast</PageTitle> | |||
| <h1>Weather forecast</h1> | |||
| <PageTitle>Search</PageTitle> | |||
| <p>This component demonstrates fetching data from the server.</p> | |||
| <h1>Search</h1> | |||
| @if (forecasts == null) | |||
| { | |||
| <p><em>Loading...</em></p> | |||
| } | |||
| else | |||
| { | |||
| <table class="table"> | |||
| <thead> | |||
| <tr> | |||
| <th>Date</th> | |||
| <th>Temp. (C)</th> | |||
| <th>Temp. (F)</th> | |||
| <th>Summary</th> | |||
| </tr> | |||
| </thead> | |||
| <tbody> | |||
| @foreach (var forecast in forecasts) | |||
| { | |||
| <tr> | |||
| <td>@forecast.Date.ToShortDateString()</td> | |||
| <td>@forecast.TemperatureC</td> | |||
| <td>@forecast.TemperatureF</td> | |||
| <td>@forecast.Summary</td> | |||
| </tr> | |||
| } | |||
| </tbody> | |||
| </table> | |||
| } | |||
| @code { | |||
| private WeatherForecast[]? forecasts; | |||
| protected override async Task OnInitializedAsync() | |||
| { | |||
| forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json"); | |||
| } | |||
| public class WeatherForecast | |||
| { | |||
| public DateTime Date { get; set; } | |||
| var token = await sessionStorage.GetItemAsync<string>("token"); | |||
| public int TemperatureC { get; set; } | |||
| SearchRequest request = new() { Query = "aitch", Type = "track", Token = token }; | |||
| SearchResponse searchResponse = await SearchService.GetListSearchAsync(request); | |||
| } | |||
| public string? Summary { get; set; } | |||
| public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | |||
| } | |||
| } | |||
| @@ -6,7 +6,7 @@ | |||
| @using GrpcShared.DTO.Search | |||
| @using NemAnBlazor.Services.Interfaces | |||
| @inject NavigationManager NavigationManager | |||
| @*@inject IAuthClientService AuthService*@ | |||
| @inject IAuthClientService AuthService | |||
| @inject ISearchClientService SearchService | |||
| <PageTitle>Index</PageTitle> | |||
| @@ -13,6 +13,7 @@ namespace SpotifyService.Services | |||
| { | |||
| private readonly IHttpClientFactory _httpClientFactory; | |||
| public SearchService(IHttpClientFactory httpClientFactory) | |||
| { | |||
| _httpClientFactory = httpClientFactory; | |||
| @@ -21,7 +22,8 @@ namespace SpotifyService.Services | |||
| public async Task<SearchResponse> ListSearchAsync(SearchRequest request) | |||
| { | |||
| var client = _httpClientFactory.CreateClient("HttpClient"); | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer BQBG6iAJDhs8YGMsPG-Fj_nDP_6IrP6WIFtKJO2H_dBsEzSggWiIE9UQlEq9csweFIJTvoixP-OaWqQdI_OzW8zxsHjj-Hbsp9lKGV0EjbzsoezhMpa3Ee5D61akQGSRtZtO2L795kGHnfAtOcNhhtcayU9PsFsSlJbz3xbLACBPBzCk49DRRccDKeZUVgs"); | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + request.Token ); | |||
| var searchResult = await client.GetAsync($"search?q={request.Query}&type={request.Type}"); | |||