| @@ -8,7 +8,7 @@ using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.Search | |||
| { | |||
| [ProtoContract] | |||
| public class SearchDetailsRequest | |||
| public class SearchRequest | |||
| { | |||
| [ProtoMember(1)] | |||
| public string Query { get; set; } | |||
| @@ -8,7 +8,7 @@ using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.Search | |||
| { | |||
| [ProtoContract] | |||
| public class SearhForItemResponse | |||
| public class SearchResponse | |||
| { | |||
| public partial class SearchContracts | |||
| { | |||
| @@ -24,14 +24,14 @@ namespace GrpcShared.DTO.Search | |||
| [ProtoMember(2)] | |||
| public Item[]? Items { get; set; } | |||
| public List<Item>? Items { get; set; } | |||
| } | |||
| public partial class Item | |||
| { | |||
| [ProtoMember(1)] | |||
| public Album Album { get; set; } | |||
| public Album? Album { get; set; } | |||
| [ProtoMember(2)] | |||
| @@ -7,10 +7,6 @@ | |||
| <Nullable>enable</Nullable> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <Folder Include="DTO\" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | |||
| </ItemGroup> | |||
| @@ -11,6 +11,6 @@ namespace GrpcShared.Interfaces | |||
| [Service] | |||
| public interface ISearchService | |||
| { | |||
| Task<SearchDetails> ListSearchAsync(SearchDetailsRequest request); | |||
| Task<SearchResponse> ListSearchAsync(SearchRequest request); | |||
| } | |||
| } | |||
| @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpotifyWorker", "SpotifyWor | |||
| EndProject | |||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityProvider", "IdentityProvider\IdentityProvider.csproj", "{D160945A-5068-4D6A-A09D-5DD7A9EFBC01}" | |||
| EndProject | |||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GrpcShared", "GrpcShared\GrpcShared.csproj", "{C142D6DF-066A-4ADA-86A3-1C736136C1FA}" | |||
| EndProject | |||
| Global | |||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
| Debug|Any CPU = Debug|Any CPU | |||
| @@ -33,6 +35,10 @@ Global | |||
| {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.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 | |||
| GlobalSection(SolutionProperties) = preSolution | |||
| HideSolutionNode = FALSE | |||
| @@ -18,4 +18,8 @@ | |||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ProjectReference Include="..\GrpcShared\GrpcShared.csproj" /> | |||
| </ItemGroup> | |||
| </Project> | |||
| @@ -1,9 +1,8 @@ | |||
| @page "/" | |||
| @using Grpc.Net.Client | |||
| @using Grpc.Net.Client.Web | |||
| @using SpotifyService.Protos | |||
| @inject NavigationManager NavigationManager | |||
| @inject Search.SearchClient SearchClient | |||
| <PageTitle>Index</PageTitle> | |||
| <h1>Pozdrav Diligent!</h1> | |||
| @@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Components; | |||
| using Microsoft.AspNetCore.Components.Web; | |||
| using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | |||
| using NemAnBlazor; | |||
| using NemAnBlazor.Services; | |||
| using NemAnBlazor.Services.Interface; | |||
| var builder = WebAssemblyHostBuilder.CreateDefault(args); | |||
| builder.RootComponents.Add<App>("#app"); | |||
| @@ -11,5 +13,15 @@ builder.RootComponents.Add<HeadOutlet>("head::after"); | |||
| 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(); | |||
| @@ -1,30 +1,16 @@ | |||
| { | |||
| "iisSettings": { | |||
| "windowsAuthentication": false, | |||
| "anonymousAuthentication": true, | |||
| "iisExpress": { | |||
| "applicationUrl": "http://localhost:50338", | |||
| "sslPort": 44375 | |||
| } | |||
| "anonymousAuthentication": true | |||
| }, | |||
| "profiles": { | |||
| "NemAnCore": { | |||
| "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, | |||
| "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | |||
| "environmentVariables": { | |||
| "ASPNETCORE_ENVIRONMENT": "Development" | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| using GrpcShared.DTO.Search; | |||
| namespace NemAnBlazor.Services.Interface | |||
| { | |||
| public interface ISearchClientService | |||
| { | |||
| Task<SearchResponse> GetListSearchAsync(SearchRequest request); | |||
| } | |||
| } | |||
| @@ -0,0 +1,21 @@ | |||
| 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); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,127 +0,0 @@ | |||
| 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; } | |||
| } | |||
| } | |||
| @@ -1,37 +1,68 @@ | |||
| using Grpc.Net.Client; | |||
| using Microsoft.AspNetCore.Server.Kestrel.Core; | |||
| using ProtoBuf.Grpc.Server; | |||
| using SpotifyService.Services; | |||
| 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. | |||
| builder.Services.AddControllersWithViews(); | |||
| builder.Services.AddRazorPages(); | |||
| builder.Services.AddEndpointsApiExplorer(); | |||
| builder.Services.AddSwaggerGen(); | |||
| 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.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(); | |||
| @@ -1,10 +1,27 @@ | |||
| { | |||
| "iisSettings": { | |||
| "windowsAuthentication": false, | |||
| "anonymousAuthentication": true, | |||
| "iisExpress": { | |||
| "applicationUrl": "http://localhost:28725", | |||
| "sslPort": 44342 | |||
| } | |||
| }, | |||
| "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", | |||
| "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": { | |||
| "ASPNETCORE_ENVIRONMENT": "Development" | |||
| } | |||
| @@ -1,7 +1,5 @@ | |||
| using SpotifyService.Protos; | |||
| using Grpc.Core; | |||
| using Grpc.Core; | |||
| using System.Text.Json; | |||
| using SpotifyService.Contracts; | |||
| namespace SpotifyService.Services | |||
| { | |||
| @@ -7,14 +7,17 @@ | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="Google.Protobuf" Version="3.21.4" /> | |||
| <PackageReference Include="Grpc.AspNetCore" Version="2.40.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> | |||
| </Project> | |||