Skip to content

Commit f75d75c

Browse files
committed
support day and month parameters on /today routes
1 parent 97a67da commit f75d75c

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

RelistenApi/Controllers/ShowsController.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ SourceService sourceService
3131

3232
[HttpGet("v2/shows/today")]
3333
[ProducesResponseType(typeof(IEnumerable<ShowWithArtist>), 200)]
34-
public async Task<IActionResult> Today()
34+
public async Task<IActionResult> Today([FromQuery] int? month = null, [FromQuery] int? day = null)
3535
{
36-
return JsonSuccess(await _showService.ShowsForCriteriaWithArtists(@"
37-
EXTRACT(month from s.date) = EXTRACT(month from NOW())
38-
AND EXTRACT(day from s.date) = EXTRACT(day from NOW())
39-
", new { }));
36+
return JsonSuccess(await _showService.ShowsForCriteriaWithArtists(@$"
37+
EXTRACT(month from s.date) = {(month != null ? "@month" : "EXTRACT(month from NOW())")}
38+
AND EXTRACT(day from s.date) = {(day != null ? "@day" : "EXTRACT(day from NOW())")}
39+
", new { month, day }));
4040
}
4141

4242
[HttpGet("v2/shows/on-date")]
@@ -46,7 +46,7 @@ public async Task<IActionResult> OnDayInHistory([FromQuery] int month, [FromQuer
4646
return JsonSuccess(await _showService.ShowsForCriteriaWithArtists(@"
4747
EXTRACT(month from s.date) = @month
4848
AND EXTRACT(day from s.date) = @day
49-
", new {month, day}));
49+
", new { month, day }));
5050
}
5151

5252
[HttpGet("v2/shows/recently-performed")]
@@ -70,13 +70,14 @@ public async Task<IActionResult> RecentlyUpdated([FromQuery] string[] artistIds
7070
[HttpGet("v2/artists/{artistIdOrSlug}/shows/today")]
7171
[ProducesResponseType(typeof(IEnumerable<ShowWithArtist>), 200)]
7272
[ProducesResponseType(typeof(ResponseEnvelope<bool>), 404)]
73-
public async Task<IActionResult> TodayArtist([FromRoute] string artistIdOrSlug)
73+
public async Task<IActionResult> TodayArtist([FromRoute] string artistIdOrSlug, [FromQuery] int? month = null,
74+
[FromQuery] int? day = null)
7475
{
75-
return await ApiRequest(artistIdOrSlug, art => _showService.ShowsForCriteriaWithArtists(@"
76+
return await ApiRequest(artistIdOrSlug, art => _showService.ShowsForCriteriaWithArtists(@$"
7677
s.artist_id = @artistId
77-
AND EXTRACT(month from s.date) = EXTRACT(month from NOW())
78-
AND EXTRACT(day from s.date) = EXTRACT(day from NOW())
79-
", new {artistId = art.id}));
78+
AND EXTRACT(month from s.date) = {(month != null ? "@month" : "EXTRACT(month from NOW())")}
79+
AND EXTRACT(day from s.date) = {(day != null ? "@day" : "EXTRACT(day from NOW())")}
80+
", new { artistId = art.id, month, day }));
8081
}
8182

8283
[HttpGet("v2/artists/{artistIdOrSlug}/shows/recently-performed")]
@@ -86,7 +87,7 @@ public async Task<IActionResult> ArtistRecentlyPerformed([FromRoute] string arti
8687
[FromQuery] int? shows = null, [FromQuery] int? days = null)
8788
{
8889
return await ApiRequest(artistIdOrSlug,
89-
art => _showService.RecentlyPerformed(new[] {art}, shows, days));
90+
art => _showService.RecentlyPerformed([art], shows, days));
9091
}
9192

9293
[HttpGet("v2/artists/{artistIdOrSlug}/shows/recently-updated")]
@@ -96,7 +97,7 @@ public async Task<IActionResult> ArtistRecentlyUpdated([FromRoute] string artist
9697
[FromQuery] int? shows = null, [FromQuery] int? days = null)
9798
{
9899
return await ApiRequest(artistIdOrSlug,
99-
art => _showService.RecentlyUpdated(new[] {art}, shows, days));
100+
art => _showService.RecentlyUpdated(new[] { art }, shows, days));
100101
}
101102

102103
[HttpGet("v2/artists/{artistIdOrSlug}/shows/on-date")]
@@ -108,7 +109,7 @@ public async Task<IActionResult> ArtistOnDayInHistory([FromRoute] string artistI
108109
s.artist_id = @artistId
109110
AND EXTRACT(month from s.date) = @month
110111
AND EXTRACT(day from s.date) = @day
111-
", new {artistId = art.id, month, day}));
112+
", new { artistId = art.id, month, day }));
112113
}
113114

114115
[HttpGet("v2/artists/{artistIdOrSlug}/shows/top")]
@@ -118,7 +119,7 @@ public async Task<IActionResult> TopByArtist([FromRoute] string artistIdOrSlug,
118119
{
119120
return await ApiRequest(artistIdOrSlug, art => _showService.ShowsForCriteria(art, @"
120121
s.artist_id = @artistId
121-
", new {artistId = art.id}, limit, "cnt.max_avg_rating_weighted DESC"));
122+
", new { artistId = art.id }, limit, "cnt.max_avg_rating_weighted DESC"));
122123
}
123124

124125
[HttpGet("v2/artists/{artistIdOrSlug}/shows/random")]

0 commit comments

Comments
 (0)