| @@ -10,14 +10,11 @@ namespace GrpcShared.DTO.Search | |||
| [ProtoContract] | |||
| public class SearchResponse | |||
| { | |||
| [ProtoMember(1)] | |||
| public Tracks? Tracks { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class SearchContracts | |||
| { | |||
| [ProtoMember(1)] | |||
| public Tracks? Tracks { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Tracks | |||
| public class Tracks | |||
| { | |||
| [ProtoMember(1)] | |||
| @@ -28,7 +25,7 @@ namespace GrpcShared.DTO.Search | |||
| public List<Item>? Items { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Item | |||
| public class Item | |||
| { | |||
| [ProtoMember(1)] | |||
| @@ -74,7 +71,7 @@ namespace GrpcShared.DTO.Search | |||
| public string Uri { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Album | |||
| public class Album | |||
| { | |||
| [ProtoMember(1)] | |||
| @@ -109,7 +106,7 @@ namespace GrpcShared.DTO.Search | |||
| public string Uri { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Image | |||
| public class Image | |||
| { | |||
| [ProtoMember(1)] | |||
| @@ -124,7 +121,7 @@ namespace GrpcShared.DTO.Search | |||
| public long Width { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Artist | |||
| public class Artist | |||
| { | |||
| [ProtoMember(1)] | |||
| @@ -151,11 +148,10 @@ namespace GrpcShared.DTO.Search | |||
| public string Uri { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class ExternalUrls | |||
| public class ExternalUrls | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Spotify { get; set; } | |||
| } | |||
| } | |||
| } | |||
| @@ -17,6 +17,7 @@ | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ProjectReference Include="..\gRPCServer\SpotifyService.csproj" /> | |||
| <ProjectReference Include="..\GrpcShared\GrpcShared.csproj" /> | |||
| <ProjectReference Include="..\NemAnCore\NemAnBlazor.csproj" /> | |||
| </ItemGroup> | |||
| @@ -3,6 +3,7 @@ using IdentityProvider.Services; | |||
| using Microsoft.AspNetCore.Server.Kestrel.Core; | |||
| using ProtoBuf.Grpc.Server; | |||
| using Microsoft.Extensions.Options; | |||
| using SpotifyService.Services; | |||
| var builder = WebApplication.CreateBuilder(args); | |||
| #if DEBUG | |||
| @@ -16,7 +17,12 @@ builder.WebHost.ConfigureKestrel(options => | |||
| }); | |||
| #endif | |||
| builder.Services.AddHttpClient("HttpClient", c => | |||
| { | |||
| c.BaseAddress = new Uri(SpotifyService.GLOBALS.SPOTIFYURL); | |||
| c.DefaultRequestHeaders.Add("Accept", SpotifyService.GLOBALS.MEDIATYPE); | |||
| }); | |||
| builder.Services.AddOptions(); | |||
| // Additional configuration is required to successfully run gRPC on macOS. | |||
| // For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682 | |||
| @@ -58,6 +64,7 @@ app.MapControllers(); | |||
| //app.MapGrpcService<WeatherService>(); | |||
| app.MapGrpcService<AuthService>().EnableGrpcWeb(); | |||
| app.MapGrpcService<SearchService>().EnableGrpcWeb(); | |||
| app.MapCodeFirstGrpcReflectionService(); | |||
| @@ -3,10 +3,11 @@ | |||
| @using Grpc.Net.Client.Web | |||
| @using GrpcShared | |||
| @using GrpcShared.DTO.Auth | |||
| @using GrpcShared.DTO.Search | |||
| @using NemAnBlazor.Services.Interfaces | |||
| @inject NavigationManager NavigationManager | |||
| @inject IAuthClientService AuthService | |||
| @*@inject ISearchClientService SearchService*@ | |||
| @*@inject IAuthClientService AuthService*@ | |||
| @inject ISearchClientService SearchService | |||
| <PageTitle>Index</PageTitle> | |||
| <h1>Pozdrav Diligent!</h1> | |||
| @@ -19,12 +20,14 @@ Dobrodošli u našu NemAn aplikaciju. | |||
| protected override async Task OnInitializedAsync() | |||
| { | |||
| //var response = await SearchService.GetListSearchAsync(new GrpcShared.DTO.Search.SearchRequest() { Query="venom", Type = "track"}); | |||
| AuthParams authParams = await AuthService.GetAuthParams(); | |||
| //AuthParams authParams = await AuthService.GetAuthParams(); | |||
| // await AuthService.GetAccessToken(new CodeResponse{ Code = "hello"}); | |||
| AuthRequest request = new() { ResponseType = "code", Scope = authParams.Scope, ClientId = authParams.ClientId, RedirectURI = authParams.RedirectURI}; | |||
| string url = $"https://accounts.spotify.com/en/authorize?client_id={request.ClientId}&redirect_uri={request.RedirectURI}&response_type={request.ResponseType}&scope={request.Scope}&show_dialog=true"; | |||
| //AuthRequest request = new() { ResponseType = "code", Scope = authParams.Scope, ClientId = authParams.ClientId, RedirectURI = authParams.RedirectURI}; | |||
| //string url = $"https://accounts.spotify.com/en/authorize?client_id={request.ClientId}&redirect_uri={request.RedirectURI}&response_type={request.ResponseType}&scope={request.Scope}&show_dialog=true"; | |||
| NavigationManager.NavigateTo(url); | |||
| //NavigationManager.NavigateTo(url); | |||
| SearchRequest request = new() { Query = "aitch", Type = "track" }; | |||
| SearchResponse searchResponse = await SearchService.GetListSearchAsync(request); | |||
| } | |||
| } | |||
| @@ -1,6 +1,8 @@ | |||
| using GrpcShared.DTO.Search; | |||
| using Grpc.Net.Client; | |||
| using GrpcShared.DTO.Search; | |||
| using GrpcShared.Interfaces; | |||
| using NemAnBlazor.Services.Interfaces; | |||
| using ProtoBuf.Grpc.Client; | |||
| namespace NemAnBlazor.Services | |||
| { | |||
| @@ -8,9 +10,9 @@ namespace NemAnBlazor.Services | |||
| { | |||
| private ISearchService _serviceClient; | |||
| public SearchClientService(ISearchService serviceClient) | |||
| public SearchClientService(GrpcChannel grpcChannel) | |||
| { | |||
| _serviceClient = serviceClient; | |||
| _serviceClient = grpcChannel.CreateGrpcService<ISearchService>(); | |||
| } | |||
| public async Task<SearchResponse> GetListSearchAsync(SearchRequest request) | |||
| @@ -0,0 +1,9 @@ | |||
| using System; | |||
| namespace SpotifyService | |||
| { | |||
| public static class GLOBALS | |||
| { | |||
| public const String SPOTIFYURL = "https://api.spotify.com/v1/"; | |||
| public const String MEDIATYPE = "application/json"; | |||
| } | |||
| } | |||
| @@ -19,6 +19,12 @@ builder.WebHost.ConfigureKestrel(options => | |||
| // Add services to the container. | |||
| builder.Services.AddHttpClient("HttpClient", c => | |||
| { | |||
| c.BaseAddress = new Uri(SpotifyService.GLOBALS.SPOTIFYURL); | |||
| c.DefaultRequestHeaders.Add("Accept", SpotifyService.GLOBALS.MEDIATYPE); | |||
| }); | |||
| builder.Services.AddControllersWithViews(); | |||
| builder.Services.AddRazorPages(); | |||
| @@ -59,7 +65,7 @@ app.MapRazorPages(); | |||
| app.MapControllers(); | |||
| //app.MapGrpcService<WeatherService>(); | |||
| app.MapGrpcService<SearchService>().EnableGrpcWeb(); | |||
| //app.MapGrpcService<SearchService>().EnableGrpcWeb(); | |||
| app.MapCodeFirstGrpcReflectionService(); | |||
| @@ -1,9 +1,15 @@ | |||
| using Grpc.Core; | |||
| using GrpcShared; | |||
| using GrpcShared.DTO.Search; | |||
| using GrpcShared.Interfaces; | |||
| using Microsoft.Net.Http.Headers; | |||
| using Newtonsoft.Json; | |||
| using System.Text; | |||
| using System.Text.Json; | |||
| namespace SpotifyService.Services | |||
| { | |||
| public class SearchService | |||
| public class SearchService : ISearchService | |||
| { | |||
| private readonly IHttpClientFactory _httpClientFactory; | |||
| @@ -11,6 +17,24 @@ namespace SpotifyService.Services | |||
| { | |||
| _httpClientFactory = httpClientFactory; | |||
| } | |||
| 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"); | |||
| var searchResult = await client.GetAsync($"search?q={request.Query}&type={request.Type}"); | |||
| var responses = JsonConvert.DeserializeObject<SearchResponse>(await searchResult.Content.ReadAsStringAsync())!; | |||
| return new SearchResponse | |||
| { | |||
| Tracks = responses!.Tracks | |||
| }; | |||
| } | |||
| } | |||
| } | |||
| @@ -10,6 +10,7 @@ | |||
| <PackageReference Include="Grpc.AspNetCore" Version="2.40.0" /> | |||
| <PackageReference Include="Grpc.AspNetCore.Web" Version="2.47.0" /> | |||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.8" /> | |||
| <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | |||
| <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | |||
| <PackageReference Include="protobuf-net.Grpc.AspNetCore" Version="1.0.152" /> | |||
| <PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" Version="1.0.152" /> | |||