diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 9fe1057..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.idea/.DS_Store b/.idea/.DS_Store deleted file mode 100644 index 378b2ee..0000000 Binary files a/.idea/.DS_Store and /dev/null differ diff --git a/Controller/ArtistController.cs b/Controller/ArtistController.cs index 963ffaa..28e7db7 100644 --- a/Controller/ArtistController.cs +++ b/Controller/ArtistController.cs @@ -12,20 +12,49 @@ namespace HollyJukeBox.Controller; public class ArtistController(IMediator mediator) : ControllerBase { - [HttpGet] - public async Task Get([FromQuery] string? id, [FromQuery] string? name) + [HttpGet("id")] + public async Task 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 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 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 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"); } } \ No newline at end of file diff --git a/Endpoints/ArtistEndPoint.cs b/Endpoints/ArtistEndPoint.cs index 9e27b37..00e3da6 100644 --- a/Endpoints/ArtistEndPoint.cs +++ b/Endpoints/ArtistEndPoint.cs @@ -7,7 +7,14 @@ namespace HollyJukeBox.Endpoints; public class ArtistEndPoint(IOptions options, HttpClient client) : IArtistEndPoint { public async Task GetById(string id) => await client.GetFromJsonAsync( - 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 GetByName(string name) => await client.GetFromJsonAsync( options.Value.MusicBrainzUrl + $"artist?query={name}&fmt=json"); + + public async Task GetWikiData(string id) => await client.GetFromJsonAsync( + options.Value.WikiDataUrl + $"?action=wbgetentities&ids={id}&format=json&props=sitelinks"); + + public async Task GetWikipediaSummary(string artist) => await client.GetFromJsonAsync( + options.Value.WikipediaSummery + $"{artist}"); } \ No newline at end of file diff --git a/Endpoints/IArtistEndPoint.cs b/Endpoints/IArtistEndPoint.cs index fd8283e..7d3e1bb 100644 --- a/Endpoints/IArtistEndPoint.cs +++ b/Endpoints/IArtistEndPoint.cs @@ -6,4 +6,6 @@ public interface IArtistEndPoint { public Task GetById(string id); public Task GetByName(string name); + public Task GetWikiData(string id); + public Task GetWikipediaSummary(string enwikiTitle); } \ No newline at end of file diff --git a/Handler/ArtistHandler.cs b/Handler/ArtistHandler.cs index 3797b90..3018e61 100644 --- a/Handler/ArtistHandler.cs +++ b/Handler/ArtistHandler.cs @@ -7,17 +7,23 @@ namespace HollyJukeBox.Handler; public class ArtistHandler(IArtistEndPoint artistEndPoint) : IRequestHandler, - IRequestHandler + IRequestHandler, + IRequestHandler, + IRequestHandler { public async Task Handle(ArtistQuery.GetById query, CancellationToken cancellationToken) => await artistEndPoint.GetById(query.Id); public async Task 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 Handle(ArtistQuery.GetWikiData request, CancellationToken cancellationToken) + => await artistEndPoint.GetWikiData(request.id); + public async Task Handle(ArtistQuery.GetWikipediaSummary request, CancellationToken cancellationToken) + => await artistEndPoint.GetWikipediaSummary(request.enwikiTitle); } \ No newline at end of file diff --git a/Models/ApiSettings.cs b/Models/ApiSettings.cs index 4a40992..712dc05 100644 --- a/Models/ApiSettings.cs +++ b/Models/ApiSettings.cs @@ -5,4 +5,5 @@ public class ApiSettings public string MusicBrainzUrl { get; set; } public string CoverArtArchiveUrl { get; set; } public string WikiDataUrl { get; set; } + public string WikipediaSummery { get; set; } } \ No newline at end of file diff --git a/Models/ArtistDto.cs b/Models/ArtistDto.cs index 1958edf..ff6ba09 100644 --- a/Models/ArtistDto.cs +++ b/Models/ArtistDto.cs @@ -11,10 +11,15 @@ public class ArtistDto [JsonPropertyName("release-groups")] public List ReleasesGroups { get; set; } + [JsonPropertyName("relations")] + public List Relations { get; set; } } public record ReleasesGroups( [property: JsonPropertyName("id")] string Id, [property: JsonPropertyName("title")] string Title, [property: JsonPropertyName("first-release-date")] string FirstReleaseDate -); \ No newline at end of file +); + +public record Relations(string type, Url url); +public record Url(string id, string resource); \ No newline at end of file diff --git a/Models/WikiDataDto.cs b/Models/WikiDataDto.cs new file mode 100644 index 0000000..c1bfbc5 --- /dev/null +++ b/Models/WikiDataDto.cs @@ -0,0 +1,21 @@ +using System.Text.Json.Serialization; + +namespace HollyJukeBox.Models; + +public class WikiDataDto +{ + [JsonPropertyName("entities")] + public Dictionary Entities { get; set; } +} +public record Entity( + [property: JsonPropertyName("id")] string Id, + [property: JsonPropertyName("sitelinks")] Dictionary Sitelinks +); +public record SiteLink( + [property: JsonPropertyName("site")] string site, + [property: JsonPropertyName("title")] string title +); + +public record Enwiki( + [property: JsonPropertyName("site")] string enwiki +); \ No newline at end of file diff --git a/Models/WikipediaSummaryDto.cs b/Models/WikipediaSummaryDto.cs new file mode 100644 index 0000000..4c715f7 --- /dev/null +++ b/Models/WikipediaSummaryDto.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace HollyJukeBox.Models; + +public class WikipediaSummaryDto +{ + [JsonPropertyName("extract")] + public string Extract { get; set; } +} \ No newline at end of file diff --git a/Querys/ArtistQuery.cs b/Querys/ArtistQuery.cs index 9109648..1de5680 100644 --- a/Querys/ArtistQuery.cs +++ b/Querys/ArtistQuery.cs @@ -7,4 +7,6 @@ public class ArtistQuery : IRequest { public record GetById(string Id) : IRequest; public record GetByName(string Name) : IRequest; + public record GetWikiData(string id) : IRequest; + public record GetWikipediaSummary(string enwikiTitle) : IRequest; } \ No newline at end of file diff --git a/appsettings.json b/appsettings.json index ff0c4ef..0bde613 100644 --- a/appsettings.json +++ b/appsettings.json @@ -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": "*" } diff --git a/bin/.DS_Store b/bin/.DS_Store deleted file mode 100644 index 450547d..0000000 Binary files a/bin/.DS_Store and /dev/null differ diff --git a/obj/.DS_Store b/obj/.DS_Store deleted file mode 100644 index 25a115b..0000000 Binary files a/obj/.DS_Store and /dev/null differ