Skip to content

Commit

Permalink
Add mediatr request for getting delivery channel policy collections, …
Browse files Browse the repository at this point in the history
…remove redundant exception definition from DeliveryChannelPolicyDataValidator
  • Loading branch information
griffri committed Feb 23, 2024
1 parent a426582 commit b0e9ef6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,13 @@ public class DeliveryChannelPoliciesController : HydraController
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> GetDeliveryChannelPolicyCollections(
[FromRoute] int customerId)
[FromRoute] int customerId,
CancellationToken cancellationToken)
{
var baseUrl = Request.GetDisplayUrl(Request.Path);

var hydraPolicyCollections = new List<HydraNestedCollection<DeliveryChannelPolicy>>()
{
new(baseUrl, AssetDeliveryChannels.Image)
{
Title = "Policies for IIIF Image service delivery",
},
new(baseUrl, AssetDeliveryChannels.Thumbnails)
{
Title = "Policies for thumbnails as IIIF Image Services",
},
new(baseUrl, AssetDeliveryChannels.Timebased)
{
Title = "Policies for Audio and Video delivery",
},
new(baseUrl, AssetDeliveryChannels.File)
{
Title = "Policies for File delivery",
}
};

var result = new HydraCollection<HydraNestedCollection<DeliveryChannelPolicy>>()
{
WithContext = true,
Members = hydraPolicyCollections.ToArray(),
TotalItems = hydraPolicyCollections.Count,
Id = Request.GetJsonLdId()
};
var request = new GetDeliveryChannelPolicyCollections(customerId, Request.GetDisplayUrl(Request.Path), Request.GetJsonLdId());
var result = await Mediator.Send(request, cancellationToken);

return new OkObjectResult(result);
return Ok(result);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using DLCS.Model.Assets;
using DLCS.Model.Policies;
using DLCS.Repository;
using Hydra.Collections;
using MediatR;

namespace API.Features.DeliveryChannels.Requests;

public class GetDeliveryChannelPolicyCollections: IRequest<HydraCollection<HydraNestedCollection<DeliveryChannelPolicy>>>
{
public int CustomerId { get; }
public string BaseUrl { get; }
public string JsonLdId { get; }

public GetDeliveryChannelPolicyCollections(int customerId, string baseUrl, string jsonLdId)
{
CustomerId = customerId;
BaseUrl = baseUrl;
JsonLdId = jsonLdId;
}
}

public class GetDeliveryChannelPolicyCollectionsHandler : IRequestHandler<GetDeliveryChannelPolicyCollections, HydraCollection<HydraNestedCollection<DeliveryChannelPolicy>>>
{
private readonly DlcsContext dbContext;

public GetDeliveryChannelPolicyCollectionsHandler(DlcsContext dbContext)
{
this.dbContext = dbContext;
}

public async Task<HydraCollection<HydraNestedCollection<DeliveryChannelPolicy>>> Handle(GetDeliveryChannelPolicyCollections request, CancellationToken cancellationToken)
{
var policyCollections = new HydraNestedCollection<DeliveryChannelPolicy>[]
{
new(request.BaseUrl, AssetDeliveryChannels.Image)
{
Title = "Policies for IIIF Image service delivery",
},
new(request.BaseUrl, AssetDeliveryChannels.Thumbnails)
{
Title = "Policies for thumbnails as IIIF Image Services",
},
new(request.BaseUrl, AssetDeliveryChannels.Timebased)
{
Title = "Policies for Audio and Video delivery",
},
new(request.BaseUrl, AssetDeliveryChannels.File)
{
Title = "Policies for File delivery",
}
};

return new HydraCollection<HydraNestedCollection<DeliveryChannelPolicy>>()
{
WithContext = true,
Members = policyCollections,
TotalItems = policyCollections.Length,
Id = request.JsonLdId,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public bool Validate(string policyDataJson, string channel)
{
policyData = JsonSerializer.Deserialize<string[]>(policyDataJson);
}
catch(JsonException ex)
catch(JsonException)
{
return null;
}
Expand Down

0 comments on commit b0e9ef6

Please sign in to comment.