Parcourir la source

fixed issue with multuple endpoints

tags/v1.1.0^2
anastasijasavov il y a 3 ans
Parent
révision
9742c618df

+ 10
- 10
NemAnCore/Pages/Index.razor Voir le fichier

@@ -3,17 +3,17 @@
@using Grpc.Net.Client.Web
@using SpotifyService.Protos
@inject NavigationManager NavigationManager
@inject Search.SearchClient SearchClient
<PageTitle>Index</PageTitle>

<h1>Pozdrav Diligent!</h1>

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(
"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");
@@ -21,14 +21,14 @@ Dobrodošli u našu NemAn aplikaciju.

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 Voir le fichier

@@ -1,7 +1,10 @@

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

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
@@ -10,5 +13,12 @@ builder.RootComponents.Add<HeadOutlet>("head::after");
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();


+ 3
- 3
NemAnCore/Protos/search.proto Voir le fichier

@@ -11,9 +11,9 @@ service Search{
message SearchForItemRequest{
string query = 1;
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 Voir le fichier

@@ -19,10 +19,10 @@ namespace SpotifyService.Contracts
public Uri Href { get; set; }

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

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

+ 0
- 3
gRPCServer/Protos/genres.proto Voir le fichier

@@ -1,3 +0,0 @@
syntax = "proto3";

option csharp_namespace = "SpotifyService.Protos";

+ 4
- 4
gRPCServer/Protos/search.proto Voir le fichier

@@ -11,9 +11,9 @@ service Search{
message SearchForItemRequest{
string query = 1;
string type = 2;
string include_external = 3;
int32 limit = 4;
int32 offset = 5;
//string include_external = 3;
//int32 limit = 4;
//int32 offset = 5;

}

@@ -39,7 +39,7 @@ message SearchForItemResponse{
}

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

+ 7
- 6
gRPCServer/Services/SearchService.cs Voir le fichier

@@ -18,15 +18,16 @@ namespace SpotifyService.Services
{

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 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;

}
}

Chargement…
Annuler
Enregistrer