Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
Binary file removed .idea/.DS_Store
Binary file not shown.
37 changes: 33 additions & 4 deletions Controller/ArtistController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,49 @@ namespace HollyJukeBox.Controller;
public class ArtistController(IMediator mediator) : ControllerBase
{

[HttpGet]
public async Task<IActionResult> Get([FromQuery] string? id, [FromQuery] string? name)
[HttpGet("id")]
public async Task<IActionResult> GetById([FromQuery] string? id)
{
if (!string.IsNullOrWhiteSpace(id))
{
var result = await mediator.Send(new ArtistQuery.GetById(id));
return result is null ? NotFound() : Ok(result);
}

return BadRequest("Provide either id for the artist");
}

[HttpGet("name")]
public async Task<IActionResult> GetByName([FromQuery] string? name)
{
if (!string.IsNullOrWhiteSpace(name))
{
var result = await mediator.Send(new ArtistQuery.GetByName(name));
return result is null ? NotFound() : Ok(result);
}
return BadRequest("Provide either id or name for the artist");
return BadRequest("Provide either name for the artist");
}

[HttpGet("wikidata")]
public async Task<IActionResult> GetWikidataById([FromQuery] string? id)
{
if (!string.IsNullOrWhiteSpace(id))
{
var result = await mediator.Send(new ArtistQuery.GetWikiData(id));
return result is null ? NotFound() : Ok(result);
}

return BadRequest("Provide id for the wikidata");
}

[HttpGet("summery")]
public async Task<IActionResult> GetWikiDataSummery([FromQuery] string? enwikiTitle)
{
if (!string.IsNullOrWhiteSpace(enwikiTitle))
{
var result = await mediator.Send(new ArtistQuery.GetWikipediaSummary(enwikiTitle));
return result is null ? NotFound() : Ok(result);
}

return BadRequest("Provide id for the wikidata");
}
}
9 changes: 8 additions & 1 deletion Endpoints/ArtistEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

public class ArtistEndPoint(IOptions<ApiSettings> options, HttpClient client) : IArtistEndPoint
{
public async Task<ArtistDto> GetById(string id) => await client.GetFromJsonAsync<ArtistDto>(

Check warning on line 9 in Endpoints/ArtistEndPoint.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
options.Value.MusicBrainzUrl + $"artist/{id}?inc=release-groups&fmt=json");
options.Value.MusicBrainzUrl + $"artist/{id}?inc=release-groups+url-rels&fmt=json");

public async Task<ArtistsDto> GetByName(string name) => await client.GetFromJsonAsync<ArtistsDto>(

Check warning on line 12 in Endpoints/ArtistEndPoint.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
options.Value.MusicBrainzUrl + $"artist?query={name}&fmt=json");

public async Task<WikiDataDto> GetWikiData(string id) => await client.GetFromJsonAsync<WikiDataDto>(

Check warning on line 15 in Endpoints/ArtistEndPoint.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
options.Value.WikiDataUrl + $"?action=wbgetentities&ids={id}&format=json&props=sitelinks");

public async Task<WikipediaSummaryDto> GetWikipediaSummary(string artist) => await client.GetFromJsonAsync<WikipediaSummaryDto>(
options.Value.WikipediaSummery + $"{artist}");
}
2 changes: 2 additions & 0 deletions Endpoints/IArtistEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public interface IArtistEndPoint
{
public Task<ArtistDto> GetById(string id);
public Task<ArtistsDto> GetByName(string name);
public Task<WikiDataDto> GetWikiData(string id);
public Task<WikipediaSummaryDto> GetWikipediaSummary(string enwikiTitle);
}
12 changes: 9 additions & 3 deletions Handler/ArtistHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ namespace HollyJukeBox.Handler;

public class ArtistHandler(IArtistEndPoint artistEndPoint) :
IRequestHandler<ArtistQuery.GetById, ArtistDto>,
IRequestHandler<ArtistQuery.GetByName, ArtistDto>
IRequestHandler<ArtistQuery.GetByName, ArtistDto>,
IRequestHandler<ArtistQuery.GetWikiData, WikiDataDto>,
IRequestHandler<ArtistQuery.GetWikipediaSummary, WikipediaSummaryDto>
{
public async Task<ArtistDto> Handle(ArtistQuery.GetById query, CancellationToken cancellationToken)
=> await artistEndPoint.GetById(query.Id);

public async Task<ArtistDto> Handle(ArtistQuery.GetByName query, CancellationToken cancellationToken)
{
{
var result = await artistEndPoint.GetByName(query.Name);
var artist = result.Artists.First(x => string.Equals(x.Name, query.Name, StringComparison.OrdinalIgnoreCase));
artist = await artistEndPoint.GetById(artist.Id);
return artist;
}


public async Task<WikiDataDto> Handle(ArtistQuery.GetWikiData request, CancellationToken cancellationToken)
=> await artistEndPoint.GetWikiData(request.id);
public async Task<WikipediaSummaryDto> Handle(ArtistQuery.GetWikipediaSummary request, CancellationToken cancellationToken)
=> await artistEndPoint.GetWikipediaSummary(request.enwikiTitle);
}
1 change: 1 addition & 0 deletions Models/ApiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

public class ApiSettings
{
public string MusicBrainzUrl { get; set; }

Check warning on line 5 in Models/ApiSettings.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'MusicBrainzUrl' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 5 in Models/ApiSettings.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'MusicBrainzUrl' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string CoverArtArchiveUrl { get; set; }

Check warning on line 6 in Models/ApiSettings.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'CoverArtArchiveUrl' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in Models/ApiSettings.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'CoverArtArchiveUrl' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string WikiDataUrl { get; set; }

Check warning on line 7 in Models/ApiSettings.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'WikiDataUrl' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in Models/ApiSettings.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'WikiDataUrl' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string WikipediaSummery { get; set; }

Check warning on line 8 in Models/ApiSettings.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'WikipediaSummery' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 8 in Models/ApiSettings.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'WikipediaSummery' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
7 changes: 6 additions & 1 deletion Models/ArtistDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
public class ArtistDto
{
[JsonPropertyName("id")]
public string Id { get; set; }

Check warning on line 8 in Models/ArtistDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[JsonPropertyName("name")]
public string Name { get; set; }

Check warning on line 10 in Models/ArtistDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonPropertyName("release-groups")]
public List<ReleasesGroups> ReleasesGroups { get; set; }

Check warning on line 13 in Models/ArtistDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ReleasesGroups' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[JsonPropertyName("relations")]
public List<Relations> Relations { get; set; }
}

public record ReleasesGroups(
[property: JsonPropertyName("id")] string Id,
[property: JsonPropertyName("title")] string Title,
[property: JsonPropertyName("first-release-date")] string FirstReleaseDate
);
);

public record Relations(string type, Url url);
public record Url(string id, string resource);
21 changes: 21 additions & 0 deletions Models/WikiDataDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text.Json.Serialization;

namespace HollyJukeBox.Models;

public class WikiDataDto
{
[JsonPropertyName("entities")]
public Dictionary<string, Entity> Entities { get; set; }

Check warning on line 8 in Models/WikiDataDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Entities' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 8 in Models/WikiDataDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Entities' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
public record Entity(
[property: JsonPropertyName("id")] string Id,
[property: JsonPropertyName("sitelinks")] Dictionary<string, SiteLink> Sitelinks
);
public record SiteLink(
[property: JsonPropertyName("site")] string site,
[property: JsonPropertyName("title")] string title
);

public record Enwiki(
[property: JsonPropertyName("site")] string enwiki
);
9 changes: 9 additions & 0 deletions Models/WikipediaSummaryDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;

namespace HollyJukeBox.Models;

public class WikipediaSummaryDto
{
[JsonPropertyName("extract")]
public string Extract { get; set; }

Check warning on line 8 in Models/WikipediaSummaryDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Extract' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 8 in Models/WikipediaSummaryDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Extract' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
2 changes: 2 additions & 0 deletions Querys/ArtistQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public class ArtistQuery : IRequest
{
public record GetById(string Id) : IRequest<ArtistDto>;
public record GetByName(string Name) : IRequest<ArtistDto>;
public record GetWikiData(string id) : IRequest<WikiDataDto>;
public record GetWikipediaSummary(string enwikiTitle) : IRequest<WikipediaSummaryDto>;
}
3 changes: 2 additions & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"ApiSettings": {
"MusicBrainzUrl": "https://musicbrainz.org/ws/2/",
"CoverArtArchiveUrl": "http://coverartarchive.org/",
"WikiDataUrl" : "https://www.wikidata.org/w/api.php"
"WikiDataUrl" : "https://www.wikidata.org/w/api.php",
"WikipediaSummery" : "https://en.wikipedia.org/api/rest_v1/page/summary/"
},
"AllowedHosts": "*"
}
Binary file removed bin/.DS_Store
Binary file not shown.
Binary file removed obj/.DS_Store
Binary file not shown.
Loading