| 12345678910111213141516171819202122232425262728293031323334 |
- using SpotifyService.Protos;
- using Grpc.Core;
- using System.Text.Json;
- using SpotifyService.Contracts;
-
- namespace SpotifyService.Services
- {
- public class SearchService : Search.SearchBase
- {
- private readonly IHttpClientFactory _httpClientFactory;
-
- public SearchService(IHttpClientFactory httpClientFactory)
- {
- _httpClientFactory = httpClientFactory;
- }
-
- public override async Task<SearchForItemResponse> SearchForItem(SearchForItemRequest request, ServerCallContext context)
- {
-
- var httpClient = _httpClientFactory.CreateClient();
- 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;
-
- }
- }
- }
|