| @@ -1,4 +1,5 @@ | |||
| using ProtoBuf; | |||
| using Newtonsoft.Json; | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| @@ -11,11 +12,14 @@ namespace GrpcShared.DTO.Auth | |||
| public class TokenRequest | |||
| { | |||
| [ProtoMember(1)] | |||
| public string grant_type { get; set; } = "authorization_code"; | |||
| [JsonProperty("grant_type")] | |||
| public string GrantType { get; set; } = "authorization_code"; | |||
| [ProtoMember(2)] | |||
| public string? code { get; set; } | |||
| [JsonProperty("code")] | |||
| public string? Code { get; set; } | |||
| [ProtoMember(3)] | |||
| public string? redirect_uri { get; set; } | |||
| [JsonProperty("redirect_uri")] | |||
| public string? RedirectUri { get; set; } | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| using ProtoBuf; | |||
| using Newtonsoft.Json; | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| @@ -11,10 +12,13 @@ namespace GrpcShared.DTO.Auth | |||
| public class TokenResponse | |||
| { | |||
| [ProtoMember(1)] | |||
| public string? access_token { get; set; } | |||
| [JsonProperty("access_token")] | |||
| public string? AccessToken { get; set; } | |||
| [ProtoMember(2)] | |||
| public string? refresh_token{ get; set; } | |||
| [JsonProperty("refresh_token")] | |||
| public string? RefreshToken{ get; set; } | |||
| [ProtoMember(3)] | |||
| public int? expires_in { get; set; } | |||
| [JsonProperty("expires_in")] | |||
| public int? Expiration { get; set; } | |||
| } | |||
| } | |||
| @@ -1,16 +0,0 @@ | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO | |||
| { | |||
| [ProtoContract] | |||
| public class HeaderParams | |||
| { | |||
| [ProtoMember(1)] | |||
| public string Token { get; set; } | |||
| } | |||
| } | |||
| @@ -20,142 +20,112 @@ namespace GrpcShared.DTO.Search | |||
| public partial class Tracks | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Href { get; set; } | |||
| public Uri? Href { get; set; } | |||
| [ProtoMember(2)] | |||
| public Item[]? Items { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Item | |||
| { | |||
| [ProtoMember(1)] | |||
| public Album Album { get; set; } | |||
| public Album? Album { get; set; } | |||
| [ProtoMember(2)] | |||
| public Artist[] Artists { get; set; } | |||
| public Artist[]? Artists { get; set; } | |||
| [ProtoMember(3)] | |||
| public long DurationMs { get; set; } | |||
| public int? DurationMs { get; set; } | |||
| [ProtoMember(4)] | |||
| public ExternalUrls ExternalUrls { get; set; } | |||
| public ExternalUrls? ExternalUrls { get; set; } | |||
| [ProtoMember(5)] | |||
| public Uri Href { get; set; } | |||
| public Uri? Href { get; set; } | |||
| [ProtoMember(6)] | |||
| public string Id { get; set; } | |||
| public string? Id { get; set; } | |||
| [ProtoMember(7)] | |||
| public string Name { get; set; } | |||
| public string? Name { get; set; } | |||
| [ProtoMember(8)] | |||
| public long Popularity { get; set; } | |||
| public int? Popularity { get; set; } | |||
| [ProtoMember(9)] | |||
| public long TrackNumber { get; set; } | |||
| public int? TrackNumber { get; set; } | |||
| [ProtoMember(10)] | |||
| public string Type { get; set; } | |||
| public string? Type { get; set; } | |||
| [ProtoMember(11)] | |||
| public string Uri { get; set; } | |||
| public string? Uri { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Album | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Href { get; set; } | |||
| public Uri? Href { get; set; } | |||
| [ProtoMember(2)] | |||
| public string Id { get; set; } | |||
| public string? Id { get; set; } | |||
| [ProtoMember(3)] | |||
| public Image[] Images { get; set; } | |||
| public Image[]? Images { get; set; } | |||
| [ProtoMember(4)] | |||
| public string Name { get; set; } | |||
| public string? Name { get; set; } | |||
| [ProtoMember(5)] | |||
| public DateTimeOffset ReleaseDate { get; set; } | |||
| public DateTimeOffset? ReleaseDate { get; set; } | |||
| [ProtoMember(6)] | |||
| public long TotalTracks { get; set; } | |||
| public int? TotalTracks { get; set; } | |||
| [ProtoMember(7)] | |||
| public string Type { get; set; } | |||
| public string? Type { get; set; } | |||
| [ProtoMember(8)] | |||
| public string Uri { get; set; } | |||
| public string? Uri { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Image | |||
| { | |||
| [ProtoMember(1)] | |||
| public long Height { get; set; } | |||
| public int? Height { get; set; } | |||
| [ProtoMember(2)] | |||
| public Uri Url { get; set; } | |||
| public Uri? Url { get; set; } | |||
| [ProtoMember(3)] | |||
| public long Width { get; set; } | |||
| public int? Width { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Artist | |||
| { | |||
| [ProtoMember(1)] | |||
| public ExternalUrls ExternalUrls { get; set; } | |||
| public ExternalUrls? ExternalUrls { get; set; } | |||
| [ProtoMember(2)] | |||
| public Uri Href { get; set; } | |||
| public Uri? Href { get; set; } | |||
| [ProtoMember(3)] | |||
| public string Id { get; set; } | |||
| public string? Id { get; set; } | |||
| [ProtoMember(4)] | |||
| public string Name { get; set; } | |||
| public string? Name { get; set; } | |||
| [ProtoMember(5)] | |||
| public string Type { get; set; } | |||
| public string? Type { get; set; } | |||
| [ProtoMember(6)] | |||
| public string Uri { get; set; } | |||
| public string? Uri { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class ExternalUrls | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Spotify { get; set; } | |||
| public Uri? Spotify { get; set; } | |||
| } | |||
| } | |||
| } | |||
| @@ -8,24 +8,23 @@ using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.Search | |||
| { | |||
| [ProtoContract] | |||
| public class SearchRequest | |||
| public class SearchRequest : TokenMessage | |||
| { | |||
| [ProtoMember(1)] | |||
| public string Query { get; set; } | |||
| public string? Query { get; set; } | |||
| [ProtoMember(2)] | |||
| public string Type { get; set; } | |||
| public string? Type { get; set; } | |||
| [ProtoMember(3)] | |||
| public string Include_External { get; set; } | |||
| public string? Include_External { get; set; } | |||
| [ProtoMember(4)] | |||
| public int Limit { get; set; } | |||
| public int? Limit { get; set; } | |||
| [ProtoMember(5)] | |||
| public int Offset { get; set; } | |||
| [ProtoMember(6)] | |||
| public string Token { get; set; } | |||
| public int? Offset { get; set; } | |||
| } | |||
| } | |||
| @@ -17,141 +17,111 @@ namespace GrpcShared.DTO.Search | |||
| public class Tracks | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Href { get; set; } | |||
| public Uri? Href { get; set; } | |||
| [ProtoMember(2)] | |||
| public List<Item>? Items { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public class Item | |||
| { | |||
| [ProtoMember(1)] | |||
| public Album? Album { get; set; } | |||
| [ProtoMember(2)] | |||
| public Artist[] Artists { get; set; } | |||
| public Artist[]? Artists { get; set; } | |||
| [ProtoMember(3)] | |||
| public long DurationMs { get; set; } | |||
| public int? DurationMs { get; set; } | |||
| [ProtoMember(4)] | |||
| public ExternalUrls ExternalUrls { get; set; } | |||
| public ExternalUrls? ExternalUrls { get; set; } | |||
| [ProtoMember(5)] | |||
| public Uri Href { get; set; } | |||
| public Uri? Href { get; set; } | |||
| [ProtoMember(6)] | |||
| public string Id { get; set; } | |||
| public string? Id { get; set; } | |||
| [ProtoMember(7)] | |||
| public string Name { get; set; } | |||
| public string? Name { get; set; } | |||
| [ProtoMember(8)] | |||
| public long Popularity { get; set; } | |||
| public int? Popularity { get; set; } | |||
| [ProtoMember(9)] | |||
| public long TrackNumber { get; set; } | |||
| public int? TrackNumber { get; set; } | |||
| [ProtoMember(10)] | |||
| public string Type { get; set; } | |||
| public string? Type { get; set; } | |||
| [ProtoMember(11)] | |||
| public string Uri { get; set; } | |||
| public string? Uri { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public class Album | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Href { get; set; } | |||
| public Uri? Href { get; set; } | |||
| [ProtoMember(2)] | |||
| public string Id { get; set; } | |||
| public string? Id { get; set; } | |||
| [ProtoMember(3)] | |||
| public Image[] Images { get; set; } | |||
| public Image[]? Images { get; set; } | |||
| [ProtoMember(4)] | |||
| public string Name { get; set; } | |||
| public string? Name { get; set; } | |||
| [ProtoMember(5)] | |||
| public DateTimeOffset ReleaseDate { get; set; } | |||
| public DateTimeOffset? ReleaseDate { get; set; } | |||
| [ProtoMember(6)] | |||
| public long TotalTracks { get; set; } | |||
| public int? TotalTracks { get; set; } | |||
| [ProtoMember(7)] | |||
| public string Type { get; set; } | |||
| public string? Type { get; set; } | |||
| [ProtoMember(8)] | |||
| public string Uri { get; set; } | |||
| public string? Uri { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public class Image | |||
| { | |||
| [ProtoMember(1)] | |||
| public long Height { get; set; } | |||
| public int? Height { get; set; } | |||
| [ProtoMember(2)] | |||
| public Uri Url { get; set; } | |||
| public Uri? Url { get; set; } | |||
| [ProtoMember(3)] | |||
| public long Width { get; set; } | |||
| public int? Width { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public class Artist | |||
| { | |||
| [ProtoMember(1)] | |||
| public ExternalUrls ExternalUrls { get; set; } | |||
| public ExternalUrls? ExternalUrls { get; set; } | |||
| [ProtoMember(2)] | |||
| public Uri Href { get; set; } | |||
| public Uri? Href { get; set; } | |||
| [ProtoMember(3)] | |||
| public string Id { get; set; } | |||
| public string? Id { get; set; } | |||
| [ProtoMember(4)] | |||
| public string Name { get; set; } | |||
| public string? Name { get; set; } | |||
| [ProtoMember(5)] | |||
| public string Type { get; set; } | |||
| public string? Type { get; set; } | |||
| [ProtoMember(6)] | |||
| public string Uri { get; set; } | |||
| public string? Uri { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public class ExternalUrls | |||
| { | |||
| [ProtoMember(1)] | |||
| public Uri Spotify { get; set; } | |||
| public Uri? Spotify { get; set; } | |||
| } | |||
| } | |||
| @@ -1,4 +1,10 @@ | |||
| using ProtoBuf; | |||
| using GrpcShared.DTO.Search; | |||
| using GrpcShared.DTO.TopItem; | |||
| using GrpcShared.DTO.Track.MultipleTrack; | |||
| using GrpcShared.DTO.Track.SaveTracks; | |||
| using GrpcShared.DTO.Track.SingleTrack; | |||
| using GrpcShared.DTO.TrackByID; | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| @@ -7,15 +13,16 @@ using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO | |||
| { | |||
| [ProtoInclude(5, typeof(TopItemRequest))] | |||
| [ProtoInclude(6, typeof(SingleTrackRequest))] | |||
| [ProtoInclude(7, typeof(SearchRequest))] | |||
| [ProtoInclude(8,typeof(MultipleTrackRequest))] | |||
| [ProtoInclude(9,typeof(SaveTracksRequest))] | |||
| [ProtoInclude(10,typeof(TrackRequest))] | |||
| [ProtoContract(SkipConstructor = true)] | |||
| public class TokenMessage | |||
| { | |||
| public TokenMessage(string? token) | |||
| { | |||
| Token = token; | |||
| } | |||
| { | |||
| [ProtoMember(1)] | |||
| public string? Token { get; set; } | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.ComponentModel; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.TopItem | |||
| { | |||
| [ProtoContract] | |||
| public class TopItemRequest : TokenMessage | |||
| { | |||
| [ProtoMember(1)] | |||
| [DefaultValue(true)] | |||
| public bool IsTracks { get; set; } = true; | |||
| [ProtoMember(2)] | |||
| public int? Limit { get; set; } | |||
| [ProtoMember(3)] | |||
| public int? Offset { get; set; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,63 @@ | |||
| using Newtonsoft.Json; | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.TopItem | |||
| { | |||
| [ProtoContract] | |||
| public class TopItemResponse | |||
| { | |||
| [ProtoMember(1)] | |||
| [JsonProperty("items")] | |||
| public Item[]? Items { get; set; } | |||
| [ProtoMember(2)] | |||
| [JsonProperty("total")] | |||
| public int? Total { get; set; } | |||
| [ProtoMember(3)] | |||
| [JsonProperty("limit")] | |||
| public int? Limit { get; set; } | |||
| [ProtoMember(4)] | |||
| [JsonProperty("offset")] | |||
| public int? Offset { get; set; } | |||
| [ProtoMember(5)] | |||
| [JsonProperty("href")] | |||
| public Uri? Href { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Item | |||
| { | |||
| [ProtoMember(1)] | |||
| [JsonProperty("genres")] | |||
| public string[]? Genres { get; set; } | |||
| [ProtoMember(2)] | |||
| [JsonProperty("id")] | |||
| public string? Id { get; set; } | |||
| [ProtoMember(3)] | |||
| [JsonProperty("images")] | |||
| public Image[]? Images { get; set; } | |||
| [ProtoMember(4)] | |||
| [JsonProperty("name")] | |||
| public string? Name { get; set; } | |||
| [ProtoMember(5)] | |||
| [JsonProperty("uri")] | |||
| public string? Uri { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public partial class Image | |||
| { | |||
| [ProtoMember(1)] | |||
| [JsonProperty("height")] | |||
| public int? Height { get; set; } | |||
| [ProtoMember(2)] | |||
| [JsonProperty("url")] | |||
| public Uri? Url { get; set; } | |||
| [ProtoMember(3)] | |||
| [JsonProperty("width")] | |||
| public int? Width { get; set; } | |||
| } | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| using ProtoBuf; | |||
| using Newtonsoft.Json; | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| @@ -11,60 +12,79 @@ namespace GrpcShared.DTO.Track | |||
| public class CurrentTrackResponse | |||
| { | |||
| [ProtoMember(1)] | |||
| public string? timestamp{ get; set; } | |||
| [JsonProperty("timestamp")] | |||
| public string? Timestamp{ get; set; } | |||
| [ProtoMember(2)] | |||
| public int? progress_ms { get; set; } | |||
| [JsonProperty("progress_ms")] | |||
| public int? ProgressMs { get; set; } | |||
| [ProtoMember(3)] | |||
| public bool? is_playing { get; set; } | |||
| [JsonProperty("is_playing")] | |||
| public bool? IsPlaying { get; set; } | |||
| [ProtoMember(4)] | |||
| public Item? item { get; set; } | |||
| [JsonProperty("item")] | |||
| public Item? Item { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public class Item | |||
| { | |||
| [ProtoMember(1)] | |||
| public Album? album { get; set; } | |||
| [JsonProperty("album")] | |||
| public Album? Album { get; set; } | |||
| [ProtoMember(2)] | |||
| public Artist[]? artists { get; set; } | |||
| [JsonProperty("artists")] | |||
| public Artist[]? Artists { get; set; } | |||
| [ProtoMember(3)] | |||
| public string? id { get; set; } | |||
| [JsonProperty("id")] | |||
| public string? Id { get; set; } | |||
| [ProtoMember(4)] | |||
| public string? name { get; set; } | |||
| [JsonProperty("name")] | |||
| public string? Name { get; set; } | |||
| [ProtoMember(5)] | |||
| public string? href { get; set; } | |||
| [JsonProperty("href")] | |||
| public string? Href { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public class Album | |||
| { | |||
| [ProtoMember(1)] | |||
| public string? id { get; set; } | |||
| [JsonProperty("id")] | |||
| public string? Id { get; set; } | |||
| [ProtoMember(2)] | |||
| public string? name { get; set; } | |||
| [JsonProperty("name")] | |||
| public string? Name { get; set; } | |||
| [ProtoMember(3)] | |||
| public Image[]? images { get; set; } | |||
| [JsonProperty("images")] | |||
| public Image[]? Images { get; set; } | |||
| [ProtoMember(4)] | |||
| public string? href { get; set; } | |||
| [JsonProperty("href")] | |||
| public string? Href { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public class Artist | |||
| { | |||
| [ProtoMember(1)] | |||
| public string? id { get; set; } | |||
| [JsonProperty("id")] | |||
| public string? Id { get; set; } | |||
| [ProtoMember(2)] | |||
| public string? name { get; set; } | |||
| [JsonProperty("name")] | |||
| public string? Name { get; set; } | |||
| [ProtoMember(3)] | |||
| public string? href { get; set; } | |||
| [JsonProperty("href")] | |||
| public string? Href { get; set; } | |||
| } | |||
| [ProtoContract] | |||
| public class Image | |||
| { | |||
| [ProtoMember(1)] | |||
| public int? height{ get; set; } | |||
| [JsonProperty("height")] | |||
| public int? Height{ get; set; } | |||
| [ProtoMember(2)] | |||
| public string? url { get; set; } | |||
| [JsonProperty("url")] | |||
| public string? Url { get; set; } | |||
| [ProtoMember(3)] | |||
| public int? width { get; set; } | |||
| [JsonProperty("width")] | |||
| public int? Width { get; set; } | |||
| } | |||
| } | |||
| @@ -8,11 +8,10 @@ using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.Track.MultipleTrack | |||
| { | |||
| [ProtoContract] | |||
| public class MultipleTrackRequest | |||
| public class MultipleTrackRequest:TokenMessage | |||
| { | |||
| [ProtoMember(1)] | |||
| public List<string> Ids { get; set; } | |||
| [ProtoMember(2)] | |||
| public string Token { get; set; } | |||
| public List<string>? Ids { get; set; } | |||
| } | |||
| } | |||
| @@ -17,58 +17,58 @@ namespace GrpcShared.DTO.Track.MultipleTrack | |||
| public class AudioFeature | |||
| { | |||
| [ProtoMember(1)] | |||
| public double Danceability { get; set; } | |||
| public float? Danceability { get; set; } | |||
| [ProtoMember(2)] | |||
| public double Energy { get; set; } | |||
| public float? Energy { get; set; } | |||
| [ProtoMember(3)] | |||
| public long Key { get; set; } | |||
| public int? Key { get; set; } | |||
| [ProtoMember(4)] | |||
| public double Loudness { get; set; } | |||
| public float? Loudness { get; set; } | |||
| [ProtoMember(5)] | |||
| public long Mode { get; set; } | |||
| public int? Mode { get; set; } | |||
| [ProtoMember(6)] | |||
| public double Speechiness { get; set; } | |||
| public float? Speechiness { get; set; } | |||
| [ProtoMember(7)] | |||
| public double Acousticness { get; set; } | |||
| public float? Acousticness { get; set; } | |||
| [ProtoMember(8)] | |||
| public long Instrumentalness { get; set; } | |||
| public int? Instrumentalness { get; set; } | |||
| [ProtoMember(9)] | |||
| public double Liveness { get; set; } | |||
| public float? Liveness { get; set; } | |||
| [ProtoMember(10)] | |||
| public double Valence { get; set; } | |||
| public float? Valence { get; set; } | |||
| [ProtoMember(11)] | |||
| public double Tempo { get; set; } | |||
| public float? Tempo { get; set; } | |||
| [ProtoMember(12)] | |||
| public string Type { get; set; } | |||
| public string? Type { get; set; } | |||
| [ProtoMember(13)] | |||
| public string Id { get; set; } | |||
| public string? Id { get; set; } | |||
| [ProtoMember(14)] | |||
| public string Uri { get; set; } | |||
| public string? Uri { get; set; } | |||
| [ProtoMember(15)] | |||
| public Uri TrackHref { get; set; } | |||
| public Uri? TrackHref { get; set; } | |||
| [ProtoMember(16)] | |||
| public Uri AnalysisUrl { get; set; } | |||
| public Uri? AnalysisUrl { get; set; } | |||
| [ProtoMember(17)] | |||
| public long DurationMs { get; set; } | |||
| public int? DurationMs { get; set; } | |||
| [ProtoMember(18)] | |||
| public long TimeSignature { get; set; } | |||
| public int? TimeSignature { get; set; } | |||
| } | |||
| } | |||
| @@ -8,11 +8,10 @@ using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.Track.SaveTracks | |||
| { | |||
| [ProtoContract] | |||
| public class SaveTracksRequest | |||
| public class SaveTracksRequest : TokenMessage | |||
| { | |||
| [ProtoMember(1)] | |||
| public List<string> Ids { get; set; } | |||
| [ProtoMember(2)] | |||
| public string Token { get; set; } | |||
| public List<string>? Ids { get; set; } | |||
| } | |||
| } | |||
| @@ -8,11 +8,10 @@ using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.Track.SingleTrack | |||
| { | |||
| [ProtoContract] | |||
| public class SingleTrackRequest | |||
| public class SingleTrackRequest : TokenMessage | |||
| { | |||
| [ProtoMember(1)] | |||
| public string Id { get; set; } | |||
| [ProtoMember(2)] | |||
| public string Token { get; set; } | |||
| public string? Id { get; set; } | |||
| } | |||
| } | |||
| @@ -1,9 +1,4 @@ | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.Track.SingleTrack | |||
| { | |||
| @@ -11,57 +6,57 @@ namespace GrpcShared.DTO.Track.SingleTrack | |||
| public class SingleTrackResponse | |||
| { | |||
| [ProtoMember(1)] | |||
| public double Danceability { get; set; } | |||
| public float? Danceability { get; set; } | |||
| [ProtoMember(2)] | |||
| public double Energy { get; set; } | |||
| public float? Energy { get; set; } | |||
| [ProtoMember(3)] | |||
| public long Key { get; set; } | |||
| public int? Key { get; set; } | |||
| [ProtoMember(4)] | |||
| public double Loudness { get; set; } | |||
| public float? Loudness { get; set; } | |||
| [ProtoMember(5)] | |||
| public long Mode { get; set; } | |||
| public int? Mode { get; set; } | |||
| [ProtoMember(6)] | |||
| public double Speechiness { get; set; } | |||
| public float? Speechiness { get; set; } | |||
| [ProtoMember(7)] | |||
| public double Acousticness { get; set; } | |||
| public float? Acousticness { get; set; } | |||
| [ProtoMember(8)] | |||
| public long Instrumentalness { get; set; } | |||
| public int? Instrumentalness { get; set; } | |||
| [ProtoMember(9)] | |||
| public double Liveness { get; set; } | |||
| public float? Liveness { get; set; } | |||
| [ProtoMember(10)] | |||
| public double Valence { get; set; } | |||
| public float? Valence { get; set; } | |||
| [ProtoMember(11)] | |||
| public double Tempo { get; set; } | |||
| public float? Tempo { get; set; } | |||
| [ProtoMember(12)] | |||
| public string Type { get; set; } | |||
| public string? Type { get; set; } | |||
| [ProtoMember(13)] | |||
| public string Id { get; set; } | |||
| public string? Id { get; set; } | |||
| [ProtoMember(14)] | |||
| public string Uri { get; set; } | |||
| public string? Uri { get; set; } | |||
| [ProtoMember(15)] | |||
| public Uri TrackHref { get; set; } | |||
| public Uri? TrackHref { get; set; } | |||
| [ProtoMember(16)] | |||
| public Uri AnalysisUrl { get; set; } | |||
| public Uri? AnalysisUrl { get; set; } | |||
| [ProtoMember(17)] | |||
| public long DurationMs { get; set; } | |||
| public int? DurationMs { get; set; } | |||
| [ProtoMember(18)] | |||
| public long TimeSignature { get; set; } | |||
| public int? TimeSignature { get; set; } | |||
| } | |||
| } | |||
| @@ -9,13 +9,11 @@ using System.Threading.Tasks; | |||
| namespace GrpcShared.DTO.TrackByID | |||
| { | |||
| [ProtoContract] | |||
| public class TrackRequest | |||
| public class TrackRequest:TokenMessage | |||
| { | |||
| [ProtoMember(1)] | |||
| [JsonProperty("id")] | |||
| public string? TrackID { get; set; } | |||
| [ProtoMember(2)] | |||
| [JsonProperty("token")] | |||
| public string? Token { get; set; } | |||
| } | |||
| } | |||
| @@ -14,26 +14,26 @@ namespace GrpcShared.DTO.TrackByID | |||
| { | |||
| [ProtoMember(1)] | |||
| [JsonProperty("album")] | |||
| public Album Album { get; set; } | |||
| public Album? Album { get; set; } | |||
| [ProtoMember(2)] | |||
| [JsonProperty("artists")] | |||
| public Artist[] Artists { get; set; } | |||
| public Artist[]? Artists { get; set; } | |||
| [ProtoMember(3)] | |||
| [JsonProperty("duration_ms")] | |||
| public long DurationMs { get; set; } | |||
| public long? DurationMs { get; set; } | |||
| [ProtoMember(4)] | |||
| [JsonProperty("href")] | |||
| public Uri Href { get; set; } | |||
| public Uri? Href { get; set; } | |||
| [ProtoMember(5)] | |||
| [JsonProperty("id")] | |||
| public string Id { get; set; } | |||
| public string? Id { get; set; } | |||
| [ProtoMember(6)] | |||
| [JsonProperty("name")] | |||
| public string Name { get; set; } | |||
| public string? Name { get; set; } | |||
| } | |||
| } | |||
| @@ -1,9 +1,5 @@ | |||
| using ProtoBuf; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| using Newtonsoft.Json; | |||
| using ProtoBuf; | |||
| namespace GrpcShared.DTO.User | |||
| { | |||
| @@ -11,10 +7,13 @@ namespace GrpcShared.DTO.User | |||
| public class UserInfoResponse | |||
| { | |||
| [ProtoMember(1)] | |||
| public string? email { get; set; } | |||
| [JsonProperty("email")] | |||
| public string? Email { get; set; } | |||
| [ProtoMember(2)] | |||
| public string? id { get; set; } | |||
| [JsonProperty("id")] | |||
| public string? Id { get; set; } | |||
| [ProtoMember(3)] | |||
| public string? display_name { get; set; } | |||
| [JsonProperty("display_name")] | |||
| public string? DisplayName{ get; set; } | |||
| } | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| using GrpcShared.DTO; | |||
| using GrpcShared.DTO.TopItem; | |||
| using GrpcShared.DTO.Track; | |||
| using ProtoBuf.Grpc.Configuration; | |||
| using System; | |||
| @@ -13,5 +14,6 @@ namespace GrpcShared.Interfaces | |||
| public interface IStatsService | |||
| { | |||
| Task<CurrentTrackResponse> GetCurrentlyPlayingTrack(TokenMessage token); | |||
| Task<TopItemResponse> GetTopItems(TopItemRequest request); | |||
| } | |||
| } | |||
| @@ -42,7 +42,7 @@ namespace IdentityProvider.Services | |||
| //get client id and secret, and redirect uri from appsettings, convert to base64 and set as header | |||
| var secrets = await GetAuthParams(); | |||
| byte[] contentType = Encoding.UTF8.GetBytes($"{secrets.ClientId}:{secrets.ClientSecret}"); | |||
| tokenRequest.redirect_uri = secrets.RedirectURI; | |||
| tokenRequest.RedirectUri = secrets.RedirectURI; | |||
| //AUTHORIZATION HEADER | |||
| http.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Basic " + Convert.ToBase64String(contentType)); | |||
| @@ -53,22 +53,16 @@ namespace IdentityProvider.Services | |||
| //BODY PARAMS | |||
| var requestBody = new Dictionary<string, string>(); | |||
| requestBody["grant_type"] = tokenRequest.grant_type; | |||
| requestBody["code"] = tokenRequest.code!; | |||
| requestBody["redirect_uri"] = tokenRequest.redirect_uri!; | |||
| requestBody["grant_type"] = tokenRequest.GrantType; | |||
| requestBody["code"] = tokenRequest.Code!; | |||
| requestBody["redirect_uri"] = tokenRequest.RedirectUri!; | |||
| //REQUEST | |||
| var response = await http.PostAsync(url, new FormUrlEncodedContent(requestBody)); | |||
| var contents = JsonConvert.DeserializeObject<TokenResponse>(await response.Content.ReadAsStringAsync()); | |||
| if (contents != null) | |||
| return new TokenResponse | |||
| { | |||
| access_token = contents!.access_token, | |||
| refresh_token = contents!.refresh_token, | |||
| expires_in = contents!.expires_in | |||
| }; | |||
| else return null; | |||
| return contents; | |||
| } | |||
| public async Task<CodeRequest> GetAuthParams() | |||
| @@ -19,13 +19,13 @@ | |||
| //code is the only parameter in the url | |||
| string code = url.Split("=")[1]; | |||
| var response = await AuthService.GetAccessToken(new GrpcShared.DTO.Auth.TokenRequest { code = code}); | |||
| var response = await AuthService.GetAccessToken(new GrpcShared.DTO.Auth.TokenRequest { Code = code}); | |||
| //if (response.access_token == null) NavigationMgr.NavigateTo("/"); | |||
| //store access token in local storage | |||
| await sessionStorage.SetItemAsync("token", response.access_token); | |||
| await sessionStorage.SetItemAsync("refresh_token", response.refresh_token); | |||
| await sessionStorage.SetItemAsync("token", response.AccessToken); | |||
| await sessionStorage.SetItemAsync("refresh_token", response.RefreshToken); | |||
| //redirect to home | |||
| NavigationMgr.NavigateTo("/home"); | |||
| @@ -1,5 +1,4 @@ | |||
| @page "/search" | |||
| @attribute [Authorize] | |||
| @using Grpc.Core | |||
| @using GrpcShared.DTO | |||
| @using GrpcShared.DTO.Search | |||
| @@ -15,44 +14,32 @@ | |||
| @inject IAuthClientService AuthService | |||
| <AuthorizeView> | |||
| <Authorized> | |||
| The user is authorized | |||
| </Authorized> | |||
| <NotAuthorized> | |||
| The User is not authorized | |||
| </NotAuthorized> | |||
| </AuthorizeView> | |||
| <PageTitle>Search</PageTitle> | |||
| <h1>Search</h1> | |||
| <AuthorizeView> | |||
| <Authorized> | |||
| <button class="btn btn-primary" @onclick="Click">Click me</button> | |||
| </Authorized> | |||
| </AuthorizeView> | |||
| <button class="btn btn-primary" @onclick="Click">Click me</button> | |||
| @code { | |||
| protected override async Task OnInitializedAsync() | |||
| { | |||
| //MultipleTrackRequest mreq = new() { Ids = new List<string>(){"3JAeYOjyJodI4PRs44lx2l", "6clZa1yrZe7pJrYFUcD9KW"}, Token = token }; | |||
| //MultipleTrackResponse multipleTrackResponse = await SearchService.GetListMultipleTrackAsync(mreq); | |||
| //protected override async Task OnInitializedAsync() | |||
| //{ | |||
| //MultipleTrackRequest mreq = new() { Ids = new List<string>(){"3JAeYOjyJodI4PRs44lx2l", "6clZa1yrZe7pJrYFUcD9KW"}, Token = token }; | |||
| //MultipleTrackResponse multipleTrackResponse = await SearchService.GetListMultipleTrackAsync(mreq); | |||
| //SingleTrackRequest singleTrackRequest = new() { Id = "3JAeYOjyJodI4PRs44lx2l", Token = token }; | |||
| //SingleTrackResponse singleTrackResponse = await SearchService.GetListSingleTrackAsync(singleTrackRequest); | |||
| } | |||
| //SingleTrackRequest singleTrackRequest = new() { Id = "3JAeYOjyJodI4PRs44lx2l", Token = token }; | |||
| //SingleTrackResponse singleTrackResponse = await SearchService.GetListSingleTrackAsync(singleTrackRequest); | |||
| //} | |||
| private async Task Click(){ | |||
| private async Task Click() | |||
| { | |||
| var token = await sessionStorage.GetItemAsync<string>("token"); | |||
| TokenMessage tm = new(token) ; | |||
| SearchRequest request = new() { Query = "aitch", Type = "track", Token = token }; | |||
| SearchResponse searchResponse = await SearchService.GetListSearchAsync(request); | |||
| TokenMessage tm = new() { Token = token }; | |||
| SearchRequest request = new() { Query = "aitch", Type = "track", Token = token }; | |||
| SearchResponse searchResponse = await SearchService.GetListSearchAsync(request); | |||
| } | |||
| @@ -14,13 +14,14 @@ | |||
| protected override async Task OnInitializedAsync() | |||
| { | |||
| string tokenS = await sessionStorage.GetItemAsync<string>("token"); | |||
| TokenMessage token = new TokenMessage(tokenS); | |||
| TokenMessage token = new TokenMessage{Token = tokenS}; | |||
| // CurrentTrackResponse response = await spotifyService.GetCurrentlyPlayingTrack(token); | |||
| CurrentTrackResponse response = await spotifyService.GetCurrentlyPlayingTrack(token); | |||
| //napravi komponentu koja ce da prikazuje sta trenutno slusas i passuj joj parametre | |||
| //4fy1A2WBTPX55mUI16TQXa | |||
| var trackById = await trackService.GetById(new GrpcShared.DTO.TrackByID.TrackRequest { TrackID = "4fy1A2WBTPX55mUI16TQXa", Token = tokenS }); | |||
| //var trackById = await trackService.GetById(new GrpcShared.DTO.TrackByID.TrackRequest { TrackID = "4fy1A2WBTPX55mUI16TQXa", Token = tokenS }); | |||
| var items = await spotifyService.GetTopItems(new GrpcShared.DTO.TopItem.TopItemRequest { Token = tokenS, IsTracks = false, Offset = 5}); | |||
| } | |||
| } | |||
| @@ -11,8 +11,6 @@ | |||
| @using System.Security.Claims | |||
| <AuthorizeView> | |||
| <Authorized> | |||
| Dobrodosli @context.User.Claims.FirstOrDefault(x => x.Type == "name")?.Value.ToUpper() | |||
| @@ -34,7 +32,7 @@ Dobrodošli u našu NemAn aplikaciju. | |||
| @code { | |||
| private string message; | |||
| private string? message; | |||
| protected override async Task OnInitializedAsync() | |||
| { | |||
| @@ -71,13 +71,13 @@ namespace NemAnBlazor.Services | |||
| //token = "BQBMgFm6jnFNWWeZEMGIRP_f-ENPid7Kw8JubAyuWAe4JK0S1DPFGlaAdZ_Fey6ePkCnz8-cqC0oyRmrciWUy5ISUTQKDe8PTQn4iBRMYCgM0n4GnS1xAErHJcm4Vpu2TAngk-4vQUOfTQRcedNTfCaHKP4uFJgTlTI7JHGrtB-_EZLnFcZ2OQe31oFQIJ1wM3ZtvwnN"; | |||
| if (token == null) return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())); | |||
| var userInfo = await _serviceClient.GetUserInfo(new TokenMessage (token)); | |||
| var userInfo = await _serviceClient.GetUserInfo(new TokenMessage{Token = token}); | |||
| List<Claim> claims = new(); | |||
| claims.Add(new Claim("email", userInfo.email!)); | |||
| claims.Add(new Claim("id", userInfo.id!)); | |||
| claims.Add(new Claim("name", userInfo.display_name!)); | |||
| claims.Add(new Claim("email", userInfo.Email!)); | |||
| claims.Add(new Claim("id", userInfo.Id!)); | |||
| claims.Add(new Claim("name", userInfo.DisplayName!)); | |||
| ClaimsIdentity identity = new(claims, "jwt"); | |||
| //ClaimsIdentity identity = new(); | |||
| @@ -1,4 +1,5 @@ | |||
| using GrpcShared.DTO; | |||
| using GrpcShared.DTO.TopItem; | |||
| using GrpcShared.DTO.Track; | |||
| namespace NemAnBlazor.Services.Interfaces | |||
| @@ -6,5 +7,6 @@ namespace NemAnBlazor.Services.Interfaces | |||
| public interface IStatsClientService | |||
| { | |||
| Task<CurrentTrackResponse> GetCurrentlyPlayingTrack(TokenMessage token); | |||
| Task<TopItemResponse> GetTopItems(TopItemRequest request); | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| using Grpc.Net.Client; | |||
| using GrpcShared.DTO; | |||
| using GrpcShared.DTO.TopItem; | |||
| using GrpcShared.DTO.Track; | |||
| using GrpcShared.Interfaces; | |||
| using NemAnBlazor.Services.Interfaces; | |||
| @@ -18,5 +19,10 @@ namespace NemAnBlazor.Services | |||
| { | |||
| return await _serviceClient.GetCurrentlyPlayingTrack(token); | |||
| } | |||
| public async Task<TopItemResponse> GetTopItems(TopItemRequest request) | |||
| { | |||
| return await _serviceClient.GetTopItems(request); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| using Grpc.Net.Client; | |||
| using Microsoft.Net.Http.Headers; | |||
| using Newtonsoft.Json; | |||
| namespace SpotifyService.HttpUtils | |||
| { | |||
| public static class HttpUtils<T> | |||
| { | |||
| public static async Task<T> GetData(HttpClient client, string url, string token) | |||
| { | |||
| //add header | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + token); | |||
| //get request | |||
| var req = await client.GetAsync(url); | |||
| //read response | |||
| var response = JsonConvert.DeserializeObject<T>(await req.Content.ReadAsStringAsync())!; | |||
| return response; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,9 +1,11 @@ | |||
| | |||
| using GrpcShared.DTO; | |||
| using GrpcShared.DTO.TopItem; | |||
| using GrpcShared.DTO.Track; | |||
| using GrpcShared.Interfaces; | |||
| using Microsoft.Net.Http.Headers; | |||
| using Newtonsoft.Json; | |||
| using SpotifyService.HttpUtils; | |||
| namespace SpotifyService.Services | |||
| { | |||
| @@ -19,13 +21,26 @@ namespace SpotifyService.Services | |||
| public async Task<CurrentTrackResponse> GetCurrentlyPlayingTrack(TokenMessage token) | |||
| { | |||
| var client = _httpClientFactory.CreateClient("HttpClient"); | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + token.Token); | |||
| var searchResult = await client.GetAsync($"me/player/currently-playing"); | |||
| string url = "me/player/currently-playing"; | |||
| var responses = JsonConvert.DeserializeObject<CurrentTrackResponse>(await searchResult.Content.ReadAsStringAsync())!; | |||
| return await HttpUtils<CurrentTrackResponse>.GetData(client, url, token.Token!); | |||
| return responses; | |||
| } | |||
| public async Task<TopItemResponse> GetTopItems(TopItemRequest request) | |||
| { | |||
| //https://api.spotify.com/v1/me/top/albums?limit=10&offset=5 | |||
| var client = _httpClientFactory.CreateClient("HttpClient"); | |||
| //URL PARAMS | |||
| string url = "me/top/"; | |||
| url += !request.IsTracks ? "artists" : "tracks"; | |||
| url += request.Limit == null ? "" : $"?limit={request.Limit}"; | |||
| if (request.Limit == null && request.Offset != null) url += $"?offset={request.Offset}"; | |||
| else url += request.Offset == null ? "" : $"&offset={request.Offset}"; | |||
| return await HttpUtils<TopItemResponse>.GetData(client, url, request.Token!); | |||
| } | |||
| } | |||
| @@ -30,72 +30,31 @@ namespace SpotifyService.Services | |||
| var client = _httpClientFactory.CreateClient("HttpClient"); | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + request.Token ); | |||
| string url = $"search?q={request.Query}&type={request.Type}"; | |||
| var searchResult = await client.GetAsync($"search?q={request.Query}&type={request.Type}"); | |||
| var responses = JsonConvert.DeserializeObject<SearchResponse>(await searchResult.Content.ReadAsStringAsync())!; | |||
| return new SearchResponse | |||
| { | |||
| Tracks = responses!.Tracks | |||
| }; | |||
| return await HttpUtils.HttpUtils<SearchResponse>.GetData(client, url, request.Token!); | |||
| } | |||
| public async Task<SingleTrackResponse> ListSingleTrackAsync(SingleTrackRequest request) | |||
| { | |||
| var client = _httpClientFactory.CreateClient("HttpClient"); | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + request.Token); | |||
| var trackResult = await client.GetAsync($"audio-features/{request.Id}"); | |||
| var responses = JsonConvert.DeserializeObject<SingleTrackResponse>(await trackResult.Content.ReadAsStringAsync())!; | |||
| return new SingleTrackResponse | |||
| { | |||
| Id = responses!.Id, | |||
| Danceability = responses!.Danceability, | |||
| Key = responses!.Key, | |||
| Loudness = responses!.Loudness, | |||
| Mode = responses!.Mode, | |||
| Speechiness = responses!.Speechiness, | |||
| Acousticness = responses!.Acousticness, | |||
| Instrumentalness = responses!.Instrumentalness, | |||
| Liveness = responses!.Liveness, | |||
| Valence = responses!.Valence, | |||
| Tempo = responses!.Tempo, | |||
| Type = responses!.Type, | |||
| Uri = responses!.Uri, | |||
| TrackHref = responses!.TrackHref, | |||
| AnalysisUrl = responses!.AnalysisUrl, | |||
| DurationMs = responses!.DurationMs, | |||
| TimeSignature = responses!.TimeSignature, | |||
| }; | |||
| string url = $"audio-features/{request.Id}"; | |||
| return await HttpUtils.HttpUtils<SingleTrackResponse>.GetData(client, url, request.Token!); | |||
| } | |||
| public async Task<MultipleTrackResponse> ListMultipleTrackAsync(MultipleTrackRequest request) | |||
| { | |||
| var client = _httpClientFactory.CreateClient("HttpClient"); | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + request.Token); | |||
| var param = new Dictionary<string, List<string>>(); | |||
| param["ids"] = request.Ids; | |||
| param["ids"] = request.Ids!; | |||
| var query = UriUtil(param); | |||
| string url = $"audio-features{query}"; | |||
| var trackMultipleResult = await client.GetAsync($"audio-features{query}"); | |||
| var responses = JsonConvert.DeserializeObject<MultipleTrackResponse>(await trackMultipleResult.Content.ReadAsStringAsync())!; | |||
| return new MultipleTrackResponse | |||
| { | |||
| Audio_Features = responses!.Audio_Features | |||
| }; | |||
| return await HttpUtils.HttpUtils<MultipleTrackResponse>.GetData(client,url,request.Token!); | |||
| } | |||
| public async Task SaveTracks(SaveTracksRequest request) | |||
| { | |||
| var client = _httpClientFactory.CreateClient("HttpClient"); | |||
| @@ -103,7 +62,7 @@ namespace SpotifyService.Services | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + request.Token); | |||
| var param = new Dictionary<string, List<string>>(); | |||
| param["ids"] = request.Ids; | |||
| param["ids"] = request.Ids!; | |||
| var query = UriUtil(param); | |||
| @@ -112,7 +71,6 @@ namespace SpotifyService.Services | |||
| } | |||
| public static string UriUtil(Dictionary<string, List<string>> param) | |||
| { | |||
| bool startingQuestionMarkAdded = false; | |||
| @@ -134,16 +92,13 @@ namespace SpotifyService.Services | |||
| sb.Length = sb.Length - 3; | |||
| return sb.ToString(); | |||
| } | |||
| public async Task<TrackResponse> GetById(TrackRequest request) | |||
| { | |||
| var client = _httpClientFactory.CreateClient("HttpClient"); | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + request.Token); | |||
| var track = await client.GetAsync($"tracks/{request.TrackID}"); | |||
| string url = $"tracks/{request.TrackID}"; | |||
| var response = JsonConvert.DeserializeObject<TrackResponse>(await track!.Content.ReadAsStringAsync())!; | |||
| return response; | |||
| return await HttpUtils.HttpUtils<TrackResponse>.GetData(client, url, request.Token!); | |||
| } | |||
| } | |||
| } | |||