Skip to content

Commit f3c8a9d

Browse files
committed
Made more fields nullable, they can be excluded using fields query param, fixes #477
1 parent 6f0e1b6 commit f3c8a9d

File tree

8 files changed

+50
-40
lines changed

8 files changed

+50
-40
lines changed

SpotifyAPI.Web.Examples/Example.ASPBlazor/Pages/Index.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ else
2626

2727
private PrivateUser _me;
2828

29-
private int _totalPlaylistCount;
29+
private int? _totalPlaylistCount;
3030

3131
protected override void OnInitialized()
3232
{

SpotifyAPI.Web.Examples/Example.BlazorWASM/Pages/Index.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ else
3333

3434
private PrivateUser _me;
3535

36-
private int _totalPlaylistCount;
36+
private int? _totalPlaylistCount;
3737

3838
private Uri _authUri;
3939

SpotifyAPI.Web/Clients/SimplePaginator.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public async IAsyncEnumerable<T> Paginate<T>(
6464
{
6565
Ensure.ArgumentNotNull(firstPage, nameof(firstPage));
6666
Ensure.ArgumentNotNull(connector, nameof(connector));
67+
if (firstPage.Items == null)
68+
{
69+
throw new ArgumentException("The first page has to contain an Items list!", nameof(firstPage));
70+
}
6771

6872
var page = firstPage;
6973
foreach (var item in page.Items)
@@ -73,7 +77,7 @@ public async IAsyncEnumerable<T> Paginate<T>(
7377
while (page.Next != null)
7478
{
7579
page = await connector.Get<Paging<T>>(new Uri(page.Next, UriKind.Absolute)).ConfigureAwait(false);
76-
foreach (var item in page.Items)
80+
foreach (var item in page.Items!)
7781
{
7882
yield return item;
7983
}
@@ -89,6 +93,10 @@ public async IAsyncEnumerable<T> Paginate<T, TNext>(
8993
Ensure.ArgumentNotNull(firstPage, nameof(firstPage));
9094
Ensure.ArgumentNotNull(mapper, nameof(mapper));
9195
Ensure.ArgumentNotNull(connector, nameof(connector));
96+
if (firstPage.Items == null)
97+
{
98+
throw new ArgumentException("The first page has to contain an Items list!", nameof(firstPage));
99+
}
92100

93101
var page = firstPage;
94102
foreach (var item in page.Items)
@@ -99,7 +107,7 @@ public async IAsyncEnumerable<T> Paginate<T, TNext>(
99107
{
100108
var next = await connector.Get<TNext>(new Uri(page.Next, UriKind.Absolute)).ConfigureAwait(false);
101109
page = mapper(next);
102-
foreach (var item in page.Items)
110+
foreach (var item in page.Items!)
103111
{
104112
yield return item;
105113
}

SpotifyAPI.Web/Models/IPaginatable.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ namespace SpotifyAPI.Web
55
public interface IPaginatable<T>
66
{
77
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
8-
string Next { get; set; }
8+
string? Next { get; set; }
99

10-
List<T> Items { get; set; }
10+
List<T>? Items { get; set; }
1111
}
1212

1313
public interface IPaginatable<T, TNext>
1414
{
1515
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
16-
string Next { get; set; }
16+
string? Next { get; set; }
1717

18-
List<T> Items { get; set; }
18+
List<T>? Items { get; set; }
1919
}
2020
}
2121

SpotifyAPI.Web/Models/Request/RequestParams.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ private void AddQueryParam(Dictionary<string, string> queryParams, PropertyInfo
122122
{
123123
if (StringAttribute.GetValue(enumType, enumVal, out var stringVal))
124124
{
125-
valueList.Add(stringVal);
125+
// .netstandard2.0 requires !
126+
valueList.Add(stringVal!);
126127
}
127128
}
128129
}
@@ -131,7 +132,8 @@ private void AddQueryParam(Dictionary<string, string> queryParams, PropertyInfo
131132
{
132133
if (StringAttribute.GetValue(enumType, valueAsEnum, out var stringVal))
133134
{
134-
valueList.Add(stringVal);
135+
// .netstandard2.0 requires !
136+
valueList.Add(stringVal!);
135137
}
136138
}
137139
queryParams.Add(attribute.Key ?? prop.Name, string.Join(",", valueList));

SpotifyAPI.Web/Models/Response/CursorPaging.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ namespace SpotifyAPI.Web
55
public class CursorPaging<T> : IPaginatable<T>
66
{
77
public string Href { get; set; } = default!;
8-
public List<T> Items { get; set; } = default!;
8+
public List<T>? Items { get; set; } = default!;
99
public int Limit { get; set; }
10-
public string Next { get; set; } = default!;
10+
public string? Next { get; set; } = default!;
1111
public Cursor Cursors { get; set; } = default!;
1212
public int Total { get; set; }
1313
}
1414

1515
public class CursorPaging<T, TNext> : IPaginatable<T, TNext>
1616
{
1717
public string Href { get; set; } = default!;
18-
public List<T> Items { get; set; } = default!;
18+
public List<T>? Items { get; set; } = default!;
1919
public int Limit { get; set; }
20-
public string Next { get; set; } = default!;
20+
public string? Next { get; set; } = default!;
2121
public Cursor Cursors { get; set; } = default!;
2222
public int Total { get; set; }
2323
}

SpotifyAPI.Web/Models/Response/FullPlaylist.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ namespace SpotifyAPI.Web
33
{
44
public class FullPlaylist
55
{
6-
public bool Collaborative { get; set; }
7-
public Dictionary<string, string> ExternalUrls { get; set; } = default!;
8-
public string Href { get; set; } = default!;
9-
public string Id { get; set; } = default!;
10-
public List<Image> Images { get; set; } = default!;
11-
public string Name { get; set; } = default!;
12-
public PublicUser Owner { get; set; } = default!;
13-
public bool Public { get; set; }
14-
public string SnapshotId { get; set; } = default!;
6+
public bool? Collaborative { get; set; }
7+
public Dictionary<string, string>? ExternalUrls { get; set; } = default!;
8+
public string? Href { get; set; } = default!;
9+
public string? Id { get; set; } = default!;
10+
public List<Image>? Images { get; set; } = default!;
11+
public string? Name { get; set; } = default!;
12+
public PublicUser? Owner { get; set; } = default!;
13+
public bool? Public { get; set; }
14+
public string? SnapshotId { get; set; } = default!;
1515

1616
/// <summary>
1717
/// A list of PlaylistTracks, which items can be a FullTrack or FullEpisode
1818
/// </summary>
1919
/// <value></value>
20-
public Paging<PlaylistTrack<IPlayableItem>> Tracks { get; set; } = default!;
21-
public string Type { get; set; } = default!;
22-
public string Uri { get; set; } = default!;
20+
public Paging<PlaylistTrack<IPlayableItem>>? Tracks { get; set; } = default!;
21+
public string? Type { get; set; } = default!;
22+
public string? Uri { get; set; } = default!;
2323
}
2424
}
2525

SpotifyAPI.Web/Models/Response/Paging.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ namespace SpotifyAPI.Web
44
{
55
public class Paging<T> : IPaginatable<T>
66
{
7-
public string Href { get; set; } = default!;
8-
public List<T> Items { get; set; } = default!;
9-
public int Limit { get; set; }
10-
public string Next { get; set; } = default!;
11-
public int Offset { get; set; }
12-
public string Previous { get; set; } = default!;
13-
public int Total { get; set; }
7+
public string? Href { get; set; } = default!;
8+
public List<T>? Items { get; set; } = default!;
9+
public int? Limit { get; set; } = default!;
10+
public string? Next { get; set; } = default!;
11+
public int? Offset { get; set; } = default!;
12+
public string? Previous { get; set; } = default!;
13+
public int? Total { get; set; } = default!;
1414
}
1515

1616
public class Paging<T, TNext> : IPaginatable<T, TNext>
1717
{
18-
public string Href { get; set; } = default!;
19-
public List<T> Items { get; set; } = default!;
20-
public int Limit { get; set; }
21-
public string Next { get; set; } = default!;
22-
public int Offset { get; set; }
23-
public string Previous { get; set; } = default!;
24-
public int Total { get; set; }
18+
public string? Href { get; set; } = default!;
19+
public List<T>? Items { get; set; } = default!;
20+
public int? Limit { get; set; } = default!;
21+
public string? Next { get; set; } = default!;
22+
public int? Offset { get; set; } = default!;
23+
public string? Previous { get; set; } = default!;
24+
public int? Total { get; set; } = default!;
2525
}
2626
}
2727

0 commit comments

Comments
 (0)