| namespace GrpcShared.DTO.Search | namespace GrpcShared.DTO.Search | ||||
| { | { | ||||
| [ProtoContract] | [ProtoContract] | ||||
| public class SearchDetailsRequest | |||||
| public class SearchRequest | |||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public string Query { get; set; } | public string Query { get; set; } |
| namespace GrpcShared.DTO.Search | namespace GrpcShared.DTO.Search | ||||
| { | { | ||||
| [ProtoContract] | [ProtoContract] | ||||
| public class SearhForItemResponse | |||||
| public class SearchResponse | |||||
| { | { | ||||
| public partial class SearchContracts | public partial class SearchContracts | ||||
| { | { | ||||
| [ProtoMember(2)] | [ProtoMember(2)] | ||||
| public Item[]? Items { get; set; } | |||||
| public List<Item>? Items { get; set; } | |||||
| } | } | ||||
| public partial class Item | public partial class Item | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public Album Album { get; set; } | |||||
| public Album? Album { get; set; } | |||||
| [ProtoMember(2)] | [ProtoMember(2)] | ||||
| <Nullable>enable</Nullable> | <Nullable>enable</Nullable> | ||||
| </PropertyGroup> | </PropertyGroup> | ||||
| <ItemGroup> | |||||
| <Folder Include="DTO\" /> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | <ItemGroup> | ||||
| <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | ||||
| </ItemGroup> | </ItemGroup> |
| [Service] | [Service] | ||||
| public interface ISearchService | public interface ISearchService | ||||
| { | { | ||||
| Task<SearchDetails> ListSearchAsync(SearchDetailsRequest request); | |||||
| Task<SearchResponse> ListSearchAsync(SearchRequest request); | |||||
| } | } | ||||
| } | } |
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityProvider", "IdentityProvider\IdentityProvider.csproj", "{D160945A-5068-4D6A-A09D-5DD7A9EFBC01}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityProvider", "IdentityProvider\IdentityProvider.csproj", "{D160945A-5068-4D6A-A09D-5DD7A9EFBC01}" | ||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GrpcShared", "GrpcShared\GrpcShared.csproj", "{C142D6DF-066A-4ADA-86A3-1C736136C1FA}" | |||||
| EndProject | |||||
| Global | Global | ||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| Debug|Any CPU = Debug|Any CPU | Debug|Any CPU = Debug|Any CPU | ||||
| {D160945A-5068-4D6A-A09D-5DD7A9EFBC01}.Debug|Any CPU.Build.0 = Debug|Any CPU | {D160945A-5068-4D6A-A09D-5DD7A9EFBC01}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| {D160945A-5068-4D6A-A09D-5DD7A9EFBC01}.Release|Any CPU.ActiveCfg = Release|Any CPU | {D160945A-5068-4D6A-A09D-5DD7A9EFBC01}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| {D160945A-5068-4D6A-A09D-5DD7A9EFBC01}.Release|Any CPU.Build.0 = Release|Any CPU | {D160945A-5068-4D6A-A09D-5DD7A9EFBC01}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| {C142D6DF-066A-4ADA-86A3-1C736136C1FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
| {C142D6DF-066A-4ADA-86A3-1C736136C1FA}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
| {C142D6DF-066A-4ADA-86A3-1C736136C1FA}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
| {C142D6DF-066A-4ADA-86A3-1C736136C1FA}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
| HideSolutionNode = FALSE | HideSolutionNode = FALSE |
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" /> | <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | |||||
| <ProjectReference Include="..\GrpcShared\GrpcShared.csproj" /> | |||||
| </ItemGroup> | |||||
| </Project> | </Project> |
| @page "/" | @page "/" | ||||
| @using Grpc.Net.Client | @using Grpc.Net.Client | ||||
| @using Grpc.Net.Client.Web | @using Grpc.Net.Client.Web | ||||
| @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> |
| 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 NemAnBlazor.Services; | |||||
| using NemAnBlazor.Services.Interface; | |||||
| 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.AddScoped(_ => | |||||
| { | |||||
| var grpcWebHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler()); | |||||
| var channel = GrpcChannel.ForAddress(builder.HostEnvironment.BaseAddress, new GrpcChannelOptions { HttpHandler = grpcWebHandler }); | |||||
| return channel; | |||||
| }); | |||||
| builder.Services.AddScoped<ISearchClientService, SearchClientService>(); | |||||
| await builder.Build().RunAsync(); | await builder.Build().RunAsync(); | ||||
| { | { | ||||
| "iisSettings": { | "iisSettings": { | ||||
| "windowsAuthentication": false, | "windowsAuthentication": false, | ||||
| "anonymousAuthentication": true, | |||||
| "iisExpress": { | |||||
| "applicationUrl": "http://localhost:50338", | |||||
| "sslPort": 44375 | |||||
| } | |||||
| "anonymousAuthentication": true | |||||
| }, | }, | ||||
| "profiles": { | "profiles": { | ||||
| "NemAnCore": { | "NemAnCore": { | ||||
| "commandName": "Project", | "commandName": "Project", | ||||
| "dotnetRunMessages": true, | |||||
| "launchBrowser": true, | |||||
| "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | |||||
| "applicationUrl": "https://localhost:7229;http://localhost:5229", | |||||
| "environmentVariables": { | |||||
| "ASPNETCORE_ENVIRONMENT": "Development" | |||||
| } | |||||
| }, | |||||
| "IIS Express": { | |||||
| "commandName": "IISExpress", | |||||
| "launchBrowser": true, | "launchBrowser": true, | ||||
| "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | |||||
| "environmentVariables": { | "environmentVariables": { | ||||
| "ASPNETCORE_ENVIRONMENT": "Development" | "ASPNETCORE_ENVIRONMENT": "Development" | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| using GrpcShared.DTO.Search; | |||||
| namespace NemAnBlazor.Services.Interface | |||||
| { | |||||
| public interface ISearchClientService | |||||
| { | |||||
| Task<SearchResponse> GetListSearchAsync(SearchRequest request); | |||||
| } | |||||
| } |
| using GrpcShared.DTO.Search; | |||||
| using GrpcShared.Interfaces; | |||||
| using NemAnBlazor.Services.Interface; | |||||
| namespace NemAnBlazor.Services | |||||
| { | |||||
| public class SearchClientService : ISearchClientService | |||||
| { | |||||
| private ISearchService _serviceClient; | |||||
| public SearchClientService(ISearchService serviceClient) | |||||
| { | |||||
| _serviceClient = serviceClient; | |||||
| } | |||||
| public async Task<SearchResponse> GetListSearchAsync(SearchRequest request) | |||||
| { | |||||
| return await _serviceClient.ListSearchAsync(request); | |||||
| } | |||||
| } | |||||
| } |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Globalization; | |||||
| using System.Text.Json.Serialization; | |||||
| namespace SpotifyService.Contracts | |||||
| { | |||||
| public partial class SearchContracts | |||||
| { | |||||
| [JsonPropertyName("tracks")] | |||||
| public Tracks? Tracks { get; set; } | |||||
| } | |||||
| public partial class Tracks | |||||
| { | |||||
| [JsonPropertyName("href")] | |||||
| public Uri Href { get; set; } | |||||
| [JsonPropertyName("items")] | |||||
| public Items[]? Items { get; set; } | |||||
| } | |||||
| public partial class Items | |||||
| { | |||||
| [JsonPropertyName("album")] | |||||
| public Album Album { get; set; } | |||||
| [JsonPropertyName("artists")] | |||||
| public Artist[] Artists { get; set; } | |||||
| [JsonPropertyName("duration_ms")] | |||||
| public long DurationMs { get; set; } | |||||
| [JsonPropertyName("external_urls")] | |||||
| public ExternalUrls ExternalUrls { get; set; } | |||||
| [JsonPropertyName("href")] | |||||
| public Uri Href { get; set; } | |||||
| [JsonPropertyName("id")] | |||||
| public string Id { get; set; } | |||||
| [JsonPropertyName("name")] | |||||
| public string Name { get; set; } | |||||
| [JsonPropertyName("popularity")] | |||||
| public long Popularity { get; set; } | |||||
| [JsonPropertyName("track_number")] | |||||
| public long TrackNumber { get; set; } | |||||
| [JsonPropertyName("type")] | |||||
| public string Type { get; set; } | |||||
| [JsonPropertyName("uri")] | |||||
| public string Uri { get; set; } | |||||
| } | |||||
| public partial class Album | |||||
| { | |||||
| [JsonPropertyName("href")] | |||||
| public Uri Href { get; set; } | |||||
| [JsonPropertyName("id")] | |||||
| public string Id { get; set; } | |||||
| [JsonPropertyName("images")] | |||||
| public Image[] Images { get; set; } | |||||
| [JsonPropertyName("name")] | |||||
| public string Name { get; set; } | |||||
| [JsonPropertyName("release_date")] | |||||
| public DateTimeOffset ReleaseDate { get; set; } | |||||
| [JsonPropertyName("total_tracks")] | |||||
| public long TotalTracks { get; set; } | |||||
| [JsonPropertyName("type")] | |||||
| public string Type { get; set; } | |||||
| [JsonPropertyName("uri")] | |||||
| public string Uri { get; set; } | |||||
| } | |||||
| public partial class Image | |||||
| { | |||||
| [JsonPropertyName("height")] | |||||
| public long Height { get; set; } | |||||
| [JsonPropertyName("url")] | |||||
| public Uri Url { get; set; } | |||||
| [JsonPropertyName("width")] | |||||
| public long Width { get; set; } | |||||
| } | |||||
| public partial class Artist | |||||
| { | |||||
| [JsonPropertyName("external_urls")] | |||||
| public ExternalUrls ExternalUrls { get; set; } | |||||
| [JsonPropertyName("href")] | |||||
| public Uri Href { get; set; } | |||||
| [JsonPropertyName("id")] | |||||
| public string Id { get; set; } | |||||
| [JsonPropertyName("name")] | |||||
| public string Name { get; set; } | |||||
| [JsonPropertyName("type")] | |||||
| public string Type { get; set; } | |||||
| [JsonPropertyName("uri")] | |||||
| public string Uri { get; set; } | |||||
| } | |||||
| public partial class ExternalUrls | |||||
| { | |||||
| [JsonPropertyName("spotify")] | |||||
| public Uri Spotify { get; set; } | |||||
| } | |||||
| } |
| using Grpc.Net.Client; | |||||
| using Microsoft.AspNetCore.Server.Kestrel.Core; | |||||
| using ProtoBuf.Grpc.Server; | |||||
| using SpotifyService.Services; | using SpotifyService.Services; | ||||
| var builder = WebApplication.CreateBuilder(args); | var builder = WebApplication.CreateBuilder(args); | ||||
| // 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 | |||||
| #if DEBUG | |||||
| /* | |||||
| builder.WebHost.ConfigureKestrel(options => | |||||
| { | |||||
| options.ListenLocalhost(5050, o => o.Protocols = | |||||
| HttpProtocols.Http2); | |||||
| options.ListenLocalhost(5051, o => o.Protocols = | |||||
| HttpProtocols.Http1AndHttp2); | |||||
| }); | |||||
| */ | |||||
| #endif | |||||
| // Add services to the container. | // Add services to the container. | ||||
| builder.Services.AddControllersWithViews(); | |||||
| builder.Services.AddRazorPages(); | |||||
| builder.Services.AddEndpointsApiExplorer(); | |||||
| builder.Services.AddSwaggerGen(); | |||||
| builder.Services.AddGrpc(); | builder.Services.AddGrpc(); | ||||
| builder.Services.AddCodeFirstGrpc(); | |||||
| builder.Services.AddCodeFirstGrpcReflection(); | |||||
| var app = builder.Build(); | |||||
| builder.Services.AddHttpClient(); | |||||
| app.UseSwagger(); | |||||
| app.UseSwaggerUI(); | |||||
| builder.Services.AddCors(o => o.AddPolicy("AllowAll", builder => | |||||
| // Configure the HTTP request pipeline. | |||||
| if (app.Environment.IsDevelopment()) | |||||
| { | |||||
| app.UseWebAssemblyDebugging(); | |||||
| } | |||||
| else | |||||
| { | { | ||||
| builder.AllowAnyOrigin() | |||||
| .AllowAnyMethod() | |||||
| .AllowAnyHeader() | |||||
| .WithExposedHeaders("Grpc-Status", "Grpc-Message", "Grpc-Encoding", "Grpc-Accept-Encoding"); | |||||
| })); | |||||
| app.UseExceptionHandler("/Error"); | |||||
| // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | |||||
| app.UseHsts(); | |||||
| } | |||||
| var app = builder.Build(); | |||||
| app.UseHttpsRedirection(); | |||||
| app.UseRouting(); | |||||
| app.UseBlazorFrameworkFiles(); | |||||
| app.UseStaticFiles(); | |||||
| app.UseCors(); | |||||
| app.UseRouting(); | |||||
| // Configure the HTTP request pipeline. | |||||
| app.MapGrpcService<SearchService>(); | |||||
| app.UseGrpcWeb(); | app.UseGrpcWeb(); | ||||
| app.UseEndpoints(endpoints => | |||||
| { | |||||
| endpoints.MapGrpcService<SearchService>().EnableGrpcWeb().RequireCors("AllowAll"); | |||||
| }); | |||||
| app.MapRazorPages(); | |||||
| app.MapControllers(); | |||||
| //app.MapGrpcService<WeatherService>(); | |||||
| app.MapGrpcService<SearchService>().EnableGrpcWeb(); | |||||
| app.MapCodeFirstGrpcReflectionService(); | |||||
| app.MapFallbackToFile("index.html"); | |||||
| app.Run(); | app.Run(); |
| { | { | ||||
| "iisSettings": { | |||||
| "windowsAuthentication": false, | |||||
| "anonymousAuthentication": true, | |||||
| "iisExpress": { | |||||
| "applicationUrl": "http://localhost:28725", | |||||
| "sslPort": 44342 | |||||
| } | |||||
| }, | |||||
| "profiles": { | "profiles": { | ||||
| "gRPCServer": { | |||||
| "IIS Express": { | |||||
| "commandName": "IISExpress", | |||||
| "launchBrowser": true, | |||||
| "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | |||||
| "environmentVariables": { | |||||
| "ASPNETCORE_ENVIRONMENT": "Development" | |||||
| } | |||||
| }, | |||||
| "SpotifyService": { | |||||
| "commandName": "Project", | "commandName": "Project", | ||||
| "dotnetRunMessages": true, | |||||
| "launchBrowser": false, | |||||
| "applicationUrl": "http://localhost:5251;https://localhost:7251", | |||||
| "dotnetRunMessages": "true", | |||||
| "launchBrowser": true, | |||||
| "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | |||||
| "applicationUrl": "https://localhost:5001;http://localhost:5000", | |||||
| "environmentVariables": { | "environmentVariables": { | ||||
| "ASPNETCORE_ENVIRONMENT": "Development" | "ASPNETCORE_ENVIRONMENT": "Development" | ||||
| } | } |
| using SpotifyService.Protos; | |||||
| using Grpc.Core; | |||||
| using Grpc.Core; | |||||
| using System.Text.Json; | using System.Text.Json; | ||||
| using SpotifyService.Contracts; | |||||
| namespace SpotifyService.Services | namespace SpotifyService.Services | ||||
| { | { |
| </PropertyGroup> | </PropertyGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <PackageReference Include="Google.Protobuf" Version="3.21.4" /> | |||||
| <PackageReference Include="Grpc.AspNetCore" Version="2.40.0" /> | <PackageReference Include="Grpc.AspNetCore" Version="2.40.0" /> | ||||
| <PackageReference Include="Grpc.AspNetCore.Web" Version="2.47.0" /> | <PackageReference Include="Grpc.AspNetCore.Web" Version="2.47.0" /> | ||||
| <PackageReference Include="Grpc.Net.Client" Version="2.47.0" /> | |||||
| <PackageReference Include="Grpc.Tools" Version="2.47.0"> | |||||
| <PrivateAssets>all</PrivateAssets> | |||||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |||||
| </PackageReference> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.8" /> | |||||
| <PackageReference Include="protobuf-net.Grpc.AspNetCore" Version="1.0.152" /> | |||||
| <PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" Version="1.0.152" /> | |||||
| <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <ProjectReference Include="..\GrpcShared\GrpcShared.csproj" /> | |||||
| <ProjectReference Include="..\NemAnCore\NemAnBlazor.csproj" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| </Project> | </Project> |