Skip to content

Commit

Permalink
fixing code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JackLewis-digirati committed Oct 16, 2024
1 parent 0f290ce commit 36d0f2a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public async Task CreateCollection_ReturnsError_WhenIsStorageCollectionFalseAndU

// Assert
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
error!.Detail.Should().Be("Error attempting to validate collection is IIIF");
error!.Detail.Should().Be("An error occurred while attempting to validate the collection as IIIF");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static ModifyEntityResult<TCollection, ModifyCollectionType> CannotValida
where TCollection : class
{
return ModifyEntityResult<TCollection, ModifyCollectionType>.Failure(
"Error attempting to validate collection is IIIF", ModifyCollectionType.CannotValidateIIIF,
WriteResult.BadRequest);
"An error occurred while attempting to validate the collection as IIIF",
ModifyCollectionType.CannotValidateIIIF, WriteResult.BadRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task<ModifyEntityResult<PresentationCollection, ModifyCollectionTyp
}
catch (Exception ex)
{
logger.LogError(ex, "Error attempting to validate collection is IIIF");
logger.LogError(ex, "An error occurred while attempting to validate the collection as IIIF");
return ErrorHelper.CannotValidateIIIF<PresentationCollection>();
}
}
Expand All @@ -114,7 +114,7 @@ await dbContext.TrySaveCollection<PresentationCollection>(request.CustomerId, lo
return saveErrors;
}

await UploadToS3IfRequiredAsync(request, collection.Id, convertedIIIFCollection!, cancellationToken);
await UploadToS3IfRequiredAsync(request.Collection, collection, convertedIIIFCollection!, cancellationToken);

if (collection.Parent != null)
{
Expand All @@ -130,22 +130,22 @@ private static string ConvertToIIIFCollection(CreateCollection request, Collecti
{
var collectionAsIIIF = request.RawRequestBody.FromJson<IIIF.Presentation.V3.Collection>();
var convertedIIIFCollection = collectionAsIIIF.AsJson();
var thumbnails = collectionAsIIIF.Thumbnail?.Where(c => c is Image).Select(c => (Image)c).ToList();
var thumbnails = collectionAsIIIF.Thumbnail?.OfType<Image>().ToList();
if (thumbnails != null)
{
collection.Thumbnail = thumbnails.GetThumbnailPath();
}
return convertedIIIFCollection;
}

private async Task UploadToS3IfRequiredAsync(CreateCollection request,
string id, string convertedIIIFCollection, CancellationToken cancellationToken)
private async Task UploadToS3IfRequiredAsync(UpsertFlatCollection request,
Collection collection, string convertedIIIFCollection, CancellationToken cancellationToken)
{
if (!request.Collection.Behavior.IsStorageCollection())
if (!request.Behavior.IsStorageCollection())
{
await bucketWriter.WriteToBucket(
new ObjectInBucket(settings.AWS.S3.StorageBucket,
$"{request.CustomerId}/collections/{id}"),
collection.GetCollectionBucketKey()),
convertedIIIFCollection, "application/json", cancellationToken);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<CollectionWithItems> Handle(GetHierarchicalCollection request,
if (!collection.IsStorageCollection)
{
var objectFromS3 = await bucketReader.GetObjectFromBucket(new ObjectInBucket(settings.S3.StorageBucket,
$"{request.CustomerId}/collections/{collection.Id}"), cancellationToken);
collection.GetCollectionBucketKey()), cancellationToken);

if (!objectFromS3.Stream.IsNull())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ await dbContext.TrySaveCollection<Collection>(request.CustomerId, logger,

await bucketWriter.WriteToBucket(
new ObjectInBucket(settings.AWS.S3.StorageBucket,
$"{request.CustomerId}/collections/{collection.Id}"),
collection.GetCollectionBucketKey()),
collectionFromBody.AsJson(), "application/json", cancellationToken);

if (collection.Parent != null)
Expand Down Expand Up @@ -120,7 +120,7 @@ private static DatabaseCollection.Collection CreateDatabaseCollection(PostHierar
}
catch (Exception ex)
{
logger.LogError(ex, "Error attempting to validate collection is IIIF");
logger.LogError(ex, "An error occurred while attempting to validate the collection as IIIF");
}

return collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public async Task<IActionResult> Post(int customerId, [FromServices] UpsertFlatC

if (collection == null)
{
return this.PresentationProblem("could not deserialize collection", null, (int)HttpStatusCode.BadRequest,
return this.PresentationProblem("Could not deserialize collection", null, (int)HttpStatusCode.BadRequest,
"Deserialization Error");
}

Expand Down
3 changes: 3 additions & 0 deletions src/IIIFPresentation/API/Helpers/CollectionHelperX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public static Uri GenerateFlatCollectionViewLast(this Collection collection, Url
new(
$"{collection.GenerateFlatCollectionId(urlRoots)}?page={lastPage}&pageSize={pageSize}{orderQueryParam}");

public static string GetCollectionBucketKey(this Collection collection) =>
$"{collection.CustomerId}/collections/{collection.Id}";

public static string GenerateFullPath(this Collection collection, string itemSlug) =>
$"{(collection.Parent != null ? $"{collection.Slug}/" : string.Empty)}{itemSlug}";

Expand Down

0 comments on commit 36d0f2a

Please sign in to comment.