Kaynağa Gözat

fixed issue with multuple endpoints

tags/v1.1.0^2
anastasijasavov 3 yıl önce
ebeveyn
işleme
9742c618df

+ 10
- 10
NemAnCore/Pages/Index.razor Dosyayı Görüntüle

@using Grpc.Net.Client.Web @using Grpc.Net.Client.Web
@using SpotifyService.Protos @using SpotifyService.Protos
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject Search.SearchClient SearchClient
<PageTitle>Index</PageTitle> <PageTitle>Index</PageTitle>


<h1>Pozdrav Diligent!</h1> <h1>Pozdrav Diligent!</h1>


Dobrodošli u našu NemAn aplikaciju. Dobrodošli u našu NemAn aplikaciju.


<button class="btn-outline-success" @onclick="SpotifyRedirect">Spotify</button>
<button class="btn-outline-success" @onclick="Grpc">Spotify</button>


@code{
private void SpotifyRedirect()
@code {
private async Task SpotifyRedirect()
{ {
NavigationManager.NavigateTo( NavigationManager.NavigateTo(
"https://accounts.spotify.com/en/authorize?client_id=83e1d09876b049c4bb1953185a4b3bfb&redirect_uri=https%3A%2F%2Flocalhost%3A7229%2F&response_type=code&scope=user-read-currently-playing%20user-read-email%20user-library-modify%20user-top-read%0A%0A%0A&show_dialog=true"); "https://accounts.spotify.com/en/authorize?client_id=83e1d09876b049c4bb1953185a4b3bfb&redirect_uri=https%3A%2F%2Flocalhost%3A7229%2F&response_type=code&scope=user-read-currently-playing%20user-read-email%20user-library-modify%20user-top-read%0A%0A%0A&show_dialog=true");


private async Task Grpc() private async Task Grpc()
{ {
var channel = GrpcChannel.ForAddress("https://localhost:7251", new GrpcChannelOptions
var httpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler());
var channel = GrpcChannel.ForAddress("https://localhost:7251/", new GrpcChannelOptions
{ {
HttpHandler = new GrpcWebHandler(new HttpClientHandler())
HttpHandler = httpHandler
}); });


var client = new Search.SearchClient(channel);
var response = await client.SearchForItemAsync(new SearchForItemRequest { Query = "venom", Type = "track", Limit = 5, Offset = 0, IncludeExternal = "audio"});

// var client = new Search.SearchClient(channel);
var response = SearchClient.SearchForItem(new SearchForItemRequest { Query = "venom", Type = "track"/*, Limit = 5, Offset = 0, IncludeExternal = "audio"*/});
Console.WriteLine(response);
} }
} }

+ 11
- 1
NemAnCore/Program.cs Dosyayı Görüntüle


using Grpc.Net.Client;
using Grpc.Net.Client.Web;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using NemAnBlazor; using NemAnBlazor;
using SpotifyService.Protos;


var builder = WebAssemblyHostBuilder.CreateDefault(args); var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app"); builder.RootComponents.Add<App>("#app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });




builder.Services.AddSingleton(services =>
{
var httpClient = new HttpClient(new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler()));
var baseUri = services.GetRequiredService<NavigationManager>().BaseUri;
var channel = GrpcChannel.ForAddress(baseUri, new GrpcChannelOptions { HttpClient = httpClient });
return new Search.SearchClient(channel);
});
await builder.Build().RunAsync(); await builder.Build().RunAsync();



+ 3
- 3
NemAnCore/Protos/search.proto Dosyayı Görüntüle

message SearchForItemRequest{ message SearchForItemRequest{
string query = 1; string query = 1;
string type = 2; string type = 2;
string include_external = 3;
int32 limit = 4;
int32 offset = 5;
//string include_external = 3;
//int32 limit = 4;
//int32 offset = 5;


} }



+ 2
- 2
gRPCServer/Contracts/SeacrhContracts.cs Dosyayı Görüntüle

public Uri Href { get; set; } public Uri Href { get; set; }


[JsonPropertyName("items")] [JsonPropertyName("items")]
public Item[]? Items { get; set; }
public Items[]? Items { get; set; }
} }


public partial class Item
public partial class Items
{ {
[JsonPropertyName("album")] [JsonPropertyName("album")]
public Album Album { get; set; } public Album Album { get; set; }

+ 0
- 3
gRPCServer/Protos/genres.proto Dosyayı Görüntüle

syntax = "proto3";

option csharp_namespace = "SpotifyService.Protos";

+ 4
- 4
gRPCServer/Protos/search.proto Dosyayı Görüntüle

message SearchForItemRequest{ message SearchForItemRequest{
string query = 1; string query = 1;
string type = 2; string type = 2;
string include_external = 3;
int32 limit = 4;
int32 offset = 5;
//string include_external = 3;
//int32 limit = 4;
//int32 offset = 5;


} }


} }


} }
message Images {
message Images {
uint32 height = 1; uint32 height = 1;
string url = 2; string url = 2;
uint32 width = 3; uint32 width = 3;

+ 7
- 6
gRPCServer/Services/SearchService.cs Dosyayı Görüntüle

{ {


var httpClient = _httpClientFactory.CreateClient(); var httpClient = _httpClientFactory.CreateClient();
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "BQB7gF3eqg3xxqizhCuto24OgIbr_RFE6u6RJj30gHF7urqm2A0Q9venGsRXUlVuUSNOxdiG-8qb8Qp9_7luX_FqgrLswcnkgvtjm5toGR81HW-Dedul0E-K1OFc4sHz_iFsCN5QwBvIKqJjWmb6fioK4AZxp1N268WcoXzvW2LX9dv1gd6w-zSV");
var responseText = await httpClient.GetStringAsync($"https://api.spotify.com/v1/search?q={request.Query}&type={request.Type}"); var responseText = await httpClient.GetStringAsync($"https://api.spotify.com/v1/search?q={request.Query}&type={request.Type}");


var tracks = JsonSerializer.Deserialize<SearchContracts>(responseText); var tracks = JsonSerializer.Deserialize<SearchContracts>(responseText);
return new SearchForItemResponse
{
Tracks = tracks!.Tracks.Items
};
//return null;
Console.WriteLine(tracks);
//return new SearchForItemResponse
//{
// Tracks = tracks!.Tracks
//};
return null;


} }
} }

Loading…
İptal
Kaydet