public async Task <Document> GetTrackResource(int resourceId) { var trackResource = await _mediator.Send(new GetTrackResourceCommand(resourceId)); var currentRequestUri = _httpContextAccessor.HttpContext.GetCurrentRequestUri(); using var chinookDocumentContext = new ChinookJsonApiDocumentContext(currentRequestUri); var document = chinookDocumentContext .NewDocument(currentRequestUri) .SetJsonApiVersion(JsonApiVersion.Version10) .Links() .AddSelfLink() .AddUpLink() .LinksEnd() .Resource(trackResource) .Relationships() .AddRelationship(AlbumResourceKeyWords.ToOneRelationshipKey, new[] { Keywords.Related }) .AddRelationship(GenreResourceKeyWords.ToOneRelationshipKey, new[] { Keywords.Related }) .AddRelationship(MediaTypeResourceKeyWords.ToOneRelationshipKey, new[] { Keywords.Related }) .AddRelationship(InvoiceItemResourceKeyWords.ToManyRelationShipKey, new[] { Keywords.Related }) .AddRelationship(PlaylistTrackResourceKeyWords.ToManyRelationShipKey, new[] { Keywords.Related }) .RelationshipsEnd() .Links() .AddSelfLink() .LinksEnd() .ResourceEnd() .WriteDocument(); _logger.LogInformation("Request for {URL} generated JSON:API document {doc}", currentRequestUri, document); return(document); }
public async Task <Document> GetMediaTypeResourceCollection() { var mediaTypeResourceCollection = await _mediator.Send(new GetMediaTypeResourceCollectionCommand()); var currentRequestUri = _httpContextAccessor.HttpContext.GetCurrentRequestUri(); using var chinookDocumentContext = new ChinookJsonApiDocumentContext(currentRequestUri); var document = chinookDocumentContext .NewDocument(currentRequestUri) .SetJsonApiVersion(JsonApiVersion.Version10) .Links() .AddSelfLink() .AddUpLink() .LinksEnd() .ResourceCollection(mediaTypeResourceCollection) .Relationships() .AddRelationship(TrackResourceKeyWords.ToManyRelationShipKey, new[] { Keywords.Related }) .RelationshipsEnd() .Links() .AddSelfLink() .LinksEnd() .ResourceCollectionEnd() .WriteDocument(); _logger.LogInformation("Request for {URL} generated JSON:API document {doc}", currentRequestUri, document); return(document); }
public Task <Document> GetHomeDocument() { var homeResource = new Home { Message = "Chinook Sample JSON:API Project" }; var currentRequestUri = _httpContextAccessor.HttpContext.GetCurrentRequestUri(); var scheme = currentRequestUri.Scheme; var host = currentRequestUri.Host; var port = currentRequestUri.Port; var urlBuilderConfiguration = new UrlBuilderConfiguration(scheme, host, port); var customersResourceCollectionLink = CreateCustomerResourceCollectionLink(urlBuilderConfiguration); var albumResourceCollectionLink = CreateAlbumResourceCollectionLink(urlBuilderConfiguration); var artistResourceCollectionLink = CreateArtistResourceCollectionLink(urlBuilderConfiguration); var employeeResourceCollectionLink = CreateEmployeeResourceCollectionLink(urlBuilderConfiguration); var genreResourceCollectionLink = CreateGenreResourceCollectionLink(urlBuilderConfiguration); var invoiceResourceCollectionLink = CreateInvoiceResourceCollectionLink(urlBuilderConfiguration); var invoiceItemResourceCollectionLink = CreateInvoiceItemResourceCollectionLink(urlBuilderConfiguration); var mediaTypeResourceCollectionLink = CreateMediaTypeResourceCollectionLink(urlBuilderConfiguration); var playlistResourceCollectionLink = CreatePlaylistResourceCollectionLink(urlBuilderConfiguration); var trackResourceCollectionLink = CreateTrackResourceCollectionLink(urlBuilderConfiguration); using var chinookDocumentContext = new ChinookJsonApiDocumentContext(currentRequestUri); var document = chinookDocumentContext .NewDocument(currentRequestUri) .SetJsonApiVersion(JsonApiVersion.Version10) .Links() .AddSelfLink() .LinksEnd() .Resource(homeResource) .Links() .AddLink(CustomerResourceKeyWords.Self, customersResourceCollectionLink) .AddLink(AlbumResourceKeyWords.Self, albumResourceCollectionLink) .AddLink(ArtistResourceKeyWords.Self, artistResourceCollectionLink) .AddLink(EmployeeResourceKeyWords.Self, employeeResourceCollectionLink) .AddLink(GenreResourceKeyWords.Self, genreResourceCollectionLink) .AddLink(InvoiceResourceKeyWords.Self, invoiceResourceCollectionLink) .AddLink(InvoiceItemResourceKeyWords.Self, invoiceItemResourceCollectionLink) .AddLink(MediaTypeResourceKeyWords.Self, mediaTypeResourceCollectionLink) .AddLink(PlaylistResourceKeyWords.Self, playlistResourceCollectionLink) .AddLink(TrackResourceKeyWords.Self, trackResourceCollectionLink) .LinksEnd() .ResourceEnd() .WriteDocument(); _logger.LogInformation("Request for {URL} generated JSON:API document {doc}", currentRequestUri, document); return(Task.FromResult(document)); }
public async Task <Document> GetTrackResourceToAlbumResource(int resourceId) { var albumResource = await _mediator.Send(new GetTackResourceToAlbumResourceCommand(resourceId)); var currentRequestUri = _httpContextAccessor.HttpContext.GetCurrentRequestUri(); using var chinookDocumentContext = new ChinookJsonApiDocumentContext(currentRequestUri); var document = chinookDocumentContext .NewDocument(currentRequestUri) .SetJsonApiVersion(JsonApiVersion.Version10) .Links() .AddSelfLink() .AddUpLink() .LinksEnd() .Resource(albumResource) .Links() .AddSelfLink() .LinksEnd() .ResourceEnd() .WriteDocument(); _logger.LogInformation("Request for {URL} generated JSON:API document {doc}", currentRequestUri, document); return(document); }
public async Task <Document> GetEmployeeResourceCollection() { var employeeResourceCollection = await _mediator.Send(new GetEmployeeResourceCollectionCommand()); var currentRequestUri = _httpContextAccessor.HttpContext.GetCurrentRequestUri(); using var chinookDocumentContext = new ChinookJsonApiDocumentContext(currentRequestUri); var document = chinookDocumentContext .NewDocument(currentRequestUri) .SetJsonApiVersion(JsonApiVersion.Version10) .Links() .AddSelfLink() .AddUpLink() .LinksEnd() .ResourceCollection(employeeResourceCollection) .Links() .AddSelfLink() .LinksEnd() .ResourceCollectionEnd() .WriteDocument(); _logger.LogInformation("Request for {URL} generated JSON:API document {doc}", currentRequestUri, document); return(document); }