| @@ -0,0 +1,160 @@ | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.Search | |||
| { | |||
| [ProtoContract] | |||
| public class SearchDetails | |||
| { | |||
| public partial class SearchContracts | |||
| { | |||
| [ProtoMember(1)] | |||
| public Tracks? Tracks { get; set; } | |||
| } | |||
| public partial class Tracks | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Href { get; set; } | |||
| [ProtoMember(2)] | |||
| public Item[]? Items { get; set; } | |||
| } | |||
| public partial class Item | |||
| { | |||
| [ProtoMember(1)] | |||
| public Album Album { get; set; } | |||
| [ProtoMember(2)] | |||
| public Artist[] Artists { get; set; } | |||
| [ProtoMember(3)] | |||
| public long DurationMs { get; set; } | |||
| [ProtoMember(4)] | |||
| public ExternalUrls ExternalUrls { get; set; } | |||
| [ProtoMember(5)] | |||
| public Uri Href { get; set; } | |||
| [ProtoMember(6)] | |||
| public string Id { get; set; } | |||
| [ProtoMember(7)] | |||
| public string Name { get; set; } | |||
| [ProtoMember(8)] | |||
| public long Popularity { get; set; } | |||
| [ProtoMember(9)] | |||
| public long TrackNumber { get; set; } | |||
| [ProtoMember(10)] | |||
| public string Type { get; set; } | |||
| [ProtoMember(11)] | |||
| public string Uri { get; set; } | |||
| } | |||
| public partial class Album | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Href { get; set; } | |||
| [ProtoMember(2)] | |||
| public string Id { get; set; } | |||
| [ProtoMember(3)] | |||
| public Image[] Images { get; set; } | |||
| [ProtoMember(4)] | |||
| public string Name { get; set; } | |||
| [ProtoMember(5)] | |||
| public DateTimeOffset ReleaseDate { get; set; } | |||
| [ProtoMember(6)] | |||
| public long TotalTracks { get; set; } | |||
| [ProtoMember(7)] | |||
| public string Type { get; set; } | |||
| [ProtoMember(8)] | |||
| public string Uri { get; set; } | |||
| } | |||
| public partial class Image | |||
| { | |||
| [ProtoMember(1)] | |||
| public long Height { get; set; } | |||
| [ProtoMember(2)] | |||
| public Uri Url { get; set; } | |||
| [ProtoMember(3)] | |||
| public long Width { get; set; } | |||
| } | |||
| public partial class Artist | |||
| { | |||
| [ProtoMember(1)] | |||
| public ExternalUrls ExternalUrls { get; set; } | |||
| [ProtoMember(2)] | |||
| public Uri Href { get; set; } | |||
| [ProtoMember(3)] | |||
| public string Id { get; set; } | |||
| [ProtoMember(4)] | |||
| public string Name { get; set; } | |||
| [ProtoMember(5)] | |||
| public string Type { get; set; } | |||
| [ProtoMember(6)] | |||
| public string Uri { get; set; } | |||
| } | |||
| public partial class ExternalUrls | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Spotify { get; set; } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,28 @@ | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.Search | |||
| { | |||
| [ProtoContract] | |||
| public class SearchDetailsRequest | |||
| { | |||
| [ProtoMember(1)] | |||
| public string Query { get; set; } | |||
| [ProtoMember(2)] | |||
| public string Type { get; set; } | |||
| [ProtoMember(3)] | |||
| public string Include_External { get; set; } | |||
| [ProtoMember(4)] | |||
| public int Limit { get; set; } | |||
| [ProtoMember(5)] | |||
| public int Offset { get; set; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,160 @@ | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.Search | |||
| { | |||
| [ProtoContract] | |||
| public class SearhForItemResponse | |||
| { | |||
| public partial class SearchContracts | |||
| { | |||
| [ProtoMember(1)] | |||
| public Tracks? Tracks { get; set; } | |||
| } | |||
| public partial class Tracks | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Href { get; set; } | |||
| [ProtoMember(2)] | |||
| public Item[]? Items { get; set; } | |||
| } | |||
| public partial class Item | |||
| { | |||
| [ProtoMember(1)] | |||
| public Album Album { get; set; } | |||
| [ProtoMember(2)] | |||
| public Artist[] Artists { get; set; } | |||
| [ProtoMember(3)] | |||
| public long DurationMs { get; set; } | |||
| [ProtoMember(4)] | |||
| public ExternalUrls ExternalUrls { get; set; } | |||
| [ProtoMember(5)] | |||
| public Uri Href { get; set; } | |||
| [ProtoMember(6)] | |||
| public string Id { get; set; } | |||
| [ProtoMember(7)] | |||
| public string Name { get; set; } | |||
| [ProtoMember(8)] | |||
| public long Popularity { get; set; } | |||
| [ProtoMember(9)] | |||
| public long TrackNumber { get; set; } | |||
| [ProtoMember(10)] | |||
| public string Type { get; set; } | |||
| [ProtoMember(11)] | |||
| public string Uri { get; set; } | |||
| } | |||
| public partial class Album | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Href { get; set; } | |||
| [ProtoMember(2)] | |||
| public string Id { get; set; } | |||
| [ProtoMember(3)] | |||
| public Image[] Images { get; set; } | |||
| [ProtoMember(4)] | |||
| public string Name { get; set; } | |||
| [ProtoMember(5)] | |||
| public DateTimeOffset ReleaseDate { get; set; } | |||
| [ProtoMember(6)] | |||
| public long TotalTracks { get; set; } | |||
| [ProtoMember(7)] | |||
| public string Type { get; set; } | |||
| [ProtoMember(8)] | |||
| public string Uri { get; set; } | |||
| } | |||
| public partial class Image | |||
| { | |||
| [ProtoMember(1)] | |||
| public long Height { get; set; } | |||
| [ProtoMember(2)] | |||
| public Uri Url { get; set; } | |||
| [ProtoMember(3)] | |||
| public long Width { get; set; } | |||
| } | |||
| public partial class Artist | |||
| { | |||
| [ProtoMember(1)] | |||
| public ExternalUrls ExternalUrls { get; set; } | |||
| [ProtoMember(2)] | |||
| public Uri Href { get; set; } | |||
| [ProtoMember(3)] | |||
| public string Id { get; set; } | |||
| [ProtoMember(4)] | |||
| public string Name { get; set; } | |||
| [ProtoMember(5)] | |||
| public string Type { get; set; } | |||
| [ProtoMember(6)] | |||
| public string Uri { get; set; } | |||
| } | |||
| public partial class ExternalUrls | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Spotify { get; set; } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| <Project Sdk="Microsoft.NET.Sdk"> | |||
| <PropertyGroup> | |||
| <OutputType>Library</OutputType> | |||
| <TargetFramework>net6.0</TargetFramework> | |||
| <ImplicitUsings>enable</ImplicitUsings> | |||
| <Nullable>enable</Nullable> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <Folder Include="DTO\" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | |||
| </ItemGroup> | |||
| </Project> | |||
| @@ -0,0 +1,16 @@ | |||
| using GrpcShared.DTO.Search; | |||
| using ProtoBuf.Grpc.Configuration; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace GrpcShared.Interfaces | |||
| { | |||
| [Service] | |||
| public interface ISearchService | |||
| { | |||
| Task<SearchDetails> ListSearchAsync(SearchDetailsRequest request); | |||
| } | |||
| } | |||
| @@ -6,10 +6,6 @@ | |||
| <ImplicitUsings>enable</ImplicitUsings> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <None Remove="Protos\search.proto" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="Google.Protobuf" Version="3.21.4" /> | |||
| <PackageReference Include="Grpc.Net.Client" Version="2.47.0" /> | |||
| @@ -22,8 +18,4 @@ | |||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Protobuf Include="Protos\search.proto" GrpcServices="Client" /> | |||
| </ItemGroup> | |||
| </Project> | |||
| @@ -10,25 +10,7 @@ | |||
| Dobrodošli u našu NemAn aplikaciju. | |||
| <button class="btn-outline-success" @onclick="Grpc">Spotify</button> | |||
| @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"); | |||
| } | |||
| private async Task Grpc() | |||
| { | |||
| var httpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler()); | |||
| var channel = GrpcChannel.ForAddress("https://localhost:7251/", new GrpcChannelOptions | |||
| { | |||
| HttpHandler = httpHandler | |||
| }); | |||
| // 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); | |||
| } | |||
| } | |||
| @@ -4,7 +4,6 @@ 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"); | |||
| @@ -12,13 +11,5 @@ 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(); | |||
| @@ -1,3 +0,0 @@ | |||
| syntax = "proto3"; | |||
| option csharp_namespace = "SpotifyService.Protos"; | |||
| @@ -1,74 +0,0 @@ | |||
| syntax = "proto3"; | |||
| option csharp_namespace = "SpotifyService.Protos"; | |||
| package search; | |||
| service Search{ | |||
| rpc SearchForItem(SearchForItemRequest) returns (SearchForItemResponse); | |||
| } | |||
| message SearchForItemRequest{ | |||
| string query = 1; | |||
| string type = 2; | |||
| //string include_external = 3; | |||
| //int32 limit = 4; | |||
| //int32 offset = 5; | |||
| } | |||
| message SearchForItemResponse{ | |||
| message Tracks { | |||
| string href = 1; | |||
| repeated Items items = 2; | |||
| } | |||
| Tracks tracks = 1; | |||
| message Items{ | |||
| Album album = 1; | |||
| repeated Artists artists = 2; | |||
| int32 duration_ms = 3; | |||
| External_urls1 external_urls = 4; | |||
| string href = 5; | |||
| string id = 6; | |||
| string name = 7; | |||
| int32 popularity = 8; | |||
| int32 track_number = 9; | |||
| string type = 10; | |||
| string uri = 11; | |||
| } | |||
| } | |||
| message Images { | |||
| uint32 height = 1; | |||
| string url = 2; | |||
| uint32 width = 3; | |||
| } | |||
| message Album { | |||
| string href = 1; | |||
| string id = 2; | |||
| repeated Images images = 3; | |||
| string name = 4; | |||
| string release_date = 5; | |||
| uint32 total_tracks = 6; | |||
| string type = 7; | |||
| string uri = 8; | |||
| } | |||
| message External_urls { | |||
| string spotify = 1; | |||
| } | |||
| message Artists { | |||
| External_urls external_urls = 1; | |||
| string href = 2; | |||
| string id = 3; | |||
| string name = 4; | |||
| string type = 5; | |||
| string uri = 6; | |||
| } | |||
| message External_urls1 { | |||
| string spotify = 1; | |||
| } | |||
| @@ -1,74 +0,0 @@ | |||
| syntax = "proto3"; | |||
| option csharp_namespace = "SpotifyService.Protos"; | |||
| package search; | |||
| service Search{ | |||
| rpc SearchForItem(SearchForItemRequest) returns (SearchForItemResponse); | |||
| } | |||
| message SearchForItemRequest{ | |||
| string query = 1; | |||
| string type = 2; | |||
| //string include_external = 3; | |||
| //int32 limit = 4; | |||
| //int32 offset = 5; | |||
| } | |||
| message SearchForItemResponse{ | |||
| message Tracks { | |||
| string href = 1; | |||
| repeated Items items = 2; | |||
| } | |||
| Tracks tracks = 1; | |||
| message Items{ | |||
| Album album = 1; | |||
| repeated Artists artists = 2; | |||
| int32 duration_ms = 3; | |||
| External_urls1 external_urls = 4; | |||
| string href = 5; | |||
| string id = 6; | |||
| string name = 7; | |||
| int32 popularity = 8; | |||
| int32 track_number = 9; | |||
| string type = 10; | |||
| string uri = 11; | |||
| } | |||
| } | |||
| message Images { | |||
| uint32 height = 1; | |||
| string url = 2; | |||
| uint32 width = 3; | |||
| } | |||
| message Album { | |||
| string href = 1; | |||
| string id = 2; | |||
| repeated Images images = 3; | |||
| string name = 4; | |||
| string release_date = 5; | |||
| uint32 total_tracks = 6; | |||
| string type = 7; | |||
| string uri = 8; | |||
| } | |||
| message External_urls { | |||
| string spotify = 1; | |||
| } | |||
| message Artists { | |||
| External_urls external_urls = 1; | |||
| string href = 2; | |||
| string id = 3; | |||
| string name = 4; | |||
| string type = 5; | |||
| string uri = 6; | |||
| } | |||
| message External_urls1 { | |||
| string spotify = 1; | |||
| } | |||
| @@ -5,7 +5,7 @@ using SpotifyService.Contracts; | |||
| namespace SpotifyService.Services | |||
| { | |||
| public class SearchService : Search.SearchBase | |||
| public class SearchService | |||
| { | |||
| private readonly IHttpClientFactory _httpClientFactory; | |||
| @@ -13,23 +13,6 @@ namespace SpotifyService.Services | |||
| { | |||
| _httpClientFactory = httpClientFactory; | |||
| } | |||
| public override async Task<SearchForItemResponse> SearchForItem(SearchForItemRequest request, ServerCallContext context) | |||
| { | |||
| 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); | |||
| Console.WriteLine(tracks); | |||
| //return new SearchForItemResponse | |||
| //{ | |||
| // Tracks = tracks!.Tracks | |||
| //}; | |||
| return null; | |||
| } | |||
| } | |||
| } | |||
| @@ -17,8 +17,4 @@ | |||
| </PackageReference> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Protobuf Include="Protos\search.proto" GrpcServices="Server"></Protobuf> | |||
| </ItemGroup> | |||
| </Project> | |||