Skip to content

Commit

Permalink
Removed obsolete Microsoft.AspNetCore.Http.Abstractions (#85)
Browse files Browse the repository at this point in the history
Microsoft.AspNetCore.Http.Abstractions has been marked as obsolete.
dotnet/announcements#217

It appears that the only usage of the package was to provide HTTP status codes. This change replaces those usages with the System.Net.HttpStatusCode enum instead.
  • Loading branch information
Keboo authored Aug 30, 2024
1 parent 019ab77 commit a0b8141
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics.CodeAnalysis;
using System.Net;

namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore;

Expand Down Expand Up @@ -109,7 +109,7 @@ internal async Task WrapExceptionAsync(string id, Func<Task> action, Cancellatio
}
catch (DbUpdateConcurrencyException ex)
{
throw new HttpException(StatusCodes.Status409Conflict, ex.Message, ex) { Payload = await GetEntityAsync(id, cancellationToken).ConfigureAwait(false) };
throw new HttpException((int)HttpStatusCode.Conflict, ex.Message, ex) { Payload = await GetEntityAsync(id, cancellationToken).ConfigureAwait(false) };
}
catch (DbUpdateException ex)
{
Expand All @@ -136,7 +136,7 @@ await WrapExceptionAsync(entity.Id, async () =>
// We do not use Any() here because it is not supported by all providers (e.g. Cosmos)
if (DataSet.Count(x => x.Id == entity.Id) > 0)
{
throw new HttpException(StatusCodes.Status409Conflict) { Payload = await GetEntityAsync(entity.Id, cancellationToken).ConfigureAwait(false) };
throw new HttpException((int)HttpStatusCode.Conflict) { Payload = await GetEntityAsync(entity.Id, cancellationToken).ConfigureAwait(false) };
}

UpdateManagedProperties(entity);
Expand All @@ -150,17 +150,17 @@ public virtual async ValueTask DeleteAsync(string id, byte[]? version = null, Ca
{
if (string.IsNullOrEmpty(id))
{
throw new HttpException(StatusCodes.Status400BadRequest, "ID is required");
throw new HttpException((int)HttpStatusCode.BadRequest, "ID is required");
}

await WrapExceptionAsync(id, async () =>
{
TEntity storedEntity = await DataSet.FindAsync(new object[] { id }, cancellationToken).ConfigureAwait(false)
?? throw new HttpException(StatusCodes.Status404NotFound);
TEntity storedEntity = await DataSet.FindAsync([id], cancellationToken).ConfigureAwait(false)
?? throw new HttpException((int)HttpStatusCode.NotFound);

if (version?.Length > 0 && !storedEntity.Version.SequenceEqual(version))
{
throw new HttpException(StatusCodes.Status412PreconditionFailed) { Payload = await GetEntityAsync(id, cancellationToken).ConfigureAwait(false) };
throw new HttpException((int)HttpStatusCode.PreconditionFailed) { Payload = await GetEntityAsync(id, cancellationToken).ConfigureAwait(false) };
}

_ = DataSet.Remove(storedEntity);
Expand All @@ -173,11 +173,11 @@ public virtual async ValueTask<TEntity> ReadAsync(string id, CancellationToken c
{
if (string.IsNullOrEmpty(id))
{
throw new HttpException(StatusCodes.Status400BadRequest, "ID is required");
throw new HttpException((int)HttpStatusCode.BadRequest, "ID is required");
}

TEntity entity = await DataSet.AsNoTracking().SingleOrDefaultAsync(x => x.Id == id, cancellationToken).ConfigureAwait(false)
?? throw new HttpException(StatusCodes.Status404NotFound);
?? throw new HttpException((int)HttpStatusCode.NotFound);

return entity;
}
Expand All @@ -187,17 +187,17 @@ public virtual async ValueTask ReplaceAsync(TEntity entity, byte[]? version = nu
{
if (string.IsNullOrEmpty(entity.Id))
{
throw new HttpException(StatusCodes.Status400BadRequest, "ID is required");
throw new HttpException((int)HttpStatusCode.BadRequest, "ID is required");
}

await WrapExceptionAsync(entity.Id, async () =>
{
TEntity storedEntity = await DataSet.FindAsync(new object[] { entity.Id }, cancellationToken).ConfigureAwait(false)
?? throw new HttpException(StatusCodes.Status404NotFound);
?? throw new HttpException((int)HttpStatusCode.NotFound);

if (version?.Length > 0 && !storedEntity.Version.SequenceEqual(version))
{
throw new HttpException(StatusCodes.Status412PreconditionFailed) { Payload = await GetEntityAsync(entity.Id, cancellationToken).ConfigureAwait(false) };
throw new HttpException((int)HttpStatusCode.PreconditionFailed) { Payload = await GetEntityAsync(entity.Id, cancellationToken).ConfigureAwait(false) };
}

UpdateManagedProperties(entity);
Expand Down

0 comments on commit a0b8141

Please sign in to comment.