Blazor & WASM in combination to get statistics from Spotify API for performing the song analysis. With separate microservices for auth, Spotify, user data tracking, and application, connected through gRPC with Polly.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

StatsService.cs 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using GrpcShared.DTO;
  2. using GrpcShared.DTO.TopItem;
  3. using GrpcShared.DTO.Track;
  4. using GrpcShared.Interfaces;
  5. using Microsoft.Net.Http.Headers;
  6. using Newtonsoft.Json;
  7. using SpotifyService.HttpUtils;
  8. namespace SpotifyService.Services
  9. {
  10. public class StatsService : IStatsService
  11. {
  12. private readonly IHttpClientFactory _httpClientFactory;
  13. private IIdentityService _identityService;
  14. private IAuthService _authService;
  15. public StatsService(IHttpClientFactory httpClientFactory, IIdentityService identityService, IAuthService authService)
  16. {
  17. _httpClientFactory = httpClientFactory;
  18. _identityService = identityService;
  19. _authService = authService;
  20. }
  21. public async Task<CurrentTrackResponse> GetCurrentlyPlayingTrack(SessionMessage message)
  22. {
  23. string url = "me/player/currently-playing";
  24. var response = await HttpUtils<CurrentTrackResponse>
  25. .GetData(_httpClientFactory,
  26. url,
  27. message.UserId!,
  28. _identityService,
  29. _authService);
  30. return response;
  31. }
  32. public async Task<TopItemResponse> GetTopItems(TopItemRequest request)
  33. {
  34. //https://api.spotify.com/v1/me/top/albums?limit=10&offset=5
  35. //URL PARAMS
  36. string url = "me/top/";
  37. url += !request.IsTracks ? "artists" : "tracks";
  38. url += request.Limit == null ? "" : $"?limit={request.Limit}";
  39. if (request.Limit == null && request.Offset != null) url += $"?offset={request.Offset}";
  40. else url += request.Offset == null ? "" : $"&offset={request.Offset}";
  41. return await HttpUtils<TopItemResponse>
  42. .GetData(_httpClientFactory,
  43. url,
  44. request.UserId!,
  45. _identityService,
  46. _authService);
  47. }
  48. }
  49. }