Skip to content

Commit

Permalink
fix: fix ReSharper warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
VMelnalksnis committed Sep 16, 2024
1 parent 5c8ea9f commit a0810b5
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ public Task AddLinkToTransactionAsync(Guid transactionId, Guid linkId)
public Task RemoveLinkFromTransactionAsync(Guid transactionId, Guid linkId)
{
var relation = _transactionLinks.Single(kvp => kvp.Key == transactionId && kvp.Value == linkId);

// Performance is not an issue here
// ReSharper disable once UsageOfDefaultStructEquality
_transactionLinks.Remove(relation);
return Task.CompletedTask;
}
Expand Down
5 changes: 4 additions & 1 deletion source/Gnomeshade.Data/Identity/ApplicationUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// See LICENSE.txt file in the project root for full license information.

using System;
using System.Diagnostics.CodeAnalysis;

using Microsoft.AspNetCore.Identity;

namespace Gnomeshade.Data.Identity;

/// <summary>Application identity user.</summary>
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
public sealed class ApplicationUser : IdentityUser<Guid>
{
/// <summary>Initializes a new instance of the <see cref="ApplicationUser"/> class.</summary>
Expand All @@ -19,13 +21,14 @@ public ApplicationUser()
}

/// <summary>Initializes a new instance of the <see cref="ApplicationUser"/> class.</summary>
/// <param name="userName">The user name.</param>
/// <param name="userName">The username.</param>
public ApplicationUser(string userName)
: this()
{
UserName = userName;
}

/// <summary>Gets or sets the full name for this user.</summary>
// ReSharper disable once EntityFramework.ModelValidation.UnlimitedStringLength
public string FullName { get; set; } = null!;
}
6 changes: 0 additions & 6 deletions source/Gnomeshade.Data/Identity/IdentityContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ protected IdentityContext(ILoggerFactory loggerFactory)
_loggerFactory = loggerFactory;
}

/// <inheritdoc />
protected sealed override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
}

/// <inheritdoc />
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@
namespace Gnomeshade.WebApi.OpenApi;

/// <summary>A filter that specifies that the action returns <see cref="Status404NotFound"/> with <see cref="ProblemDetails"/>.</summary>
internal sealed class ProducesStatus404NotFoundAttribute : ProducesResponseTypeAttribute<ProblemDetails>
{
public ProducesStatus404NotFoundAttribute()
: base(Status404NotFound)
{
}
}
internal sealed class ProducesStatus404NotFoundAttribute()
: ProducesResponseTypeAttribute<ProblemDetails>(Status404NotFound);
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@
namespace Gnomeshade.WebApi.OpenApi;

/// <summary>A filter that specifies that the action returns <see cref="Status409Conflict"/> with <see cref="ProblemDetails"/>.</summary>
internal sealed class ProducesStatus409ConflictAttribute : ProducesResponseTypeAttribute<ProblemDetails>
{
public ProducesStatus409ConflictAttribute()
: base(Status409Conflict)
{
}
}
internal sealed class ProducesStatus409ConflictAttribute()
: ProducesResponseTypeAttribute<ProblemDetails>(Status409Conflict);
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ void IOperationFilter.Apply(OpenApiOperation operation, OperationFilterContext c
.MethodInfo
.DeclaringType?
.GetCustomAttributes(true)
.OfType<ApiControllerAttribute>();
.OfType<ApiControllerAttribute>()
.ToArray();

if (apiControllerAttributes is null ||
!apiControllerAttributes.Any() ||
(!operation.Parameters.Any() && !(operation.RequestBody?.Required ?? false)))
if (apiControllerAttributes is null or [] ||
(operation.Parameters is [] && operation.RequestBody?.Required is not true))
{
return;
}
Expand All @@ -48,7 +48,7 @@ void IOperationFilter.Apply(OpenApiOperation operation, OperationFilterContext c
Content = new Dictionary<string, OpenApiMediaType>
{
{
"application/problem+json", new OpenApiMediaType
"application/problem+json", new()
{
Schema = context.SchemaRepository.Schemas[nameof(ValidationProblemDetails)],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ public override Task<ActionResult> Post([FromBody] CategoryCreation category) =>
public override Task<ActionResult> Put(Guid id, [FromBody] CategoryCreation category) =>
base.Put(id, category);

/// <inheritdoc cref="IProductClient.DeleteCategoryAsync"/>
/// <response code="204">The category was deleted successfully.</response>
// ReSharper disable once RedundantOverriddenMember

/// <inheritdoc cref="IProductClient.DeleteCategoryAsync"/>
/// <response code="204">Category was deleted successfully.</response>
/// <response code="404">Category with the specified id does not exist.</response>
/// <response code="409">Category cannot be deleted because some other entity is still referencing it.</response>
public override Task<ActionResult> Delete(Guid id) =>
base.Delete(id);

Expand Down
16 changes: 5 additions & 11 deletions source/Gnomeshade.WebApi/V1/Controllers/LinksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,9 @@
namespace Gnomeshade.WebApi.V1.Controllers;

/// <summary>CRUD operations on link entity.</summary>
public sealed class LinksController : CreatableBase<LinkRepository, LinkEntity, Link, LinkCreation>
public sealed class LinksController(Mapper mapper, LinkRepository repository, DbConnection dbConnection)
: CreatableBase<LinkRepository, LinkEntity, Link, LinkCreation>(mapper, repository, dbConnection)
{
/// <summary>Initializes a new instance of the <see cref="LinksController"/> class.</summary>
/// <param name="mapper">Repository entity and API model mapper.</param>
/// <param name="repository">The repository for performing CRUD operations on <see cref="LinkEntity"/>.</param>
/// <param name="dbConnection">Database connection for transaction management.</param>
public LinksController(Mapper mapper, LinkRepository repository, DbConnection dbConnection)
: base(mapper, repository, dbConnection)
{
}

/// <inheritdoc cref="IGnomeshadeClient.GetLinksAsync"/>
/// <response code="200">Successfully got all links.</response>
[ProducesResponseType<List<Link>>(Status200OK)]
Expand All @@ -51,10 +43,12 @@ public override Task<ActionResult<Link>> Get(Guid id, CancellationToken cancella
public override Task<ActionResult> Put(Guid id, LinkCreation link) =>
base.Put(id, link);

// ReSharper disable once RedundantOverriddenMember

/// <inheritdoc cref="IGnomeshadeClient.DeleteLinkAsync"/>
/// <response code="204">Link was successfully deleted.</response>
/// <response code="404">Link with the specified id does not exist.</response>
// ReSharper disable once RedundantOverriddenMember
/// <response code="409">Link cannot be deleted because some other entity is still referencing it.</response>
public override Task<ActionResult> Delete(Guid id) =>
base.Delete(id);

Expand Down
21 changes: 5 additions & 16 deletions source/Gnomeshade.WebApi/V1/Controllers/LoansController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,9 @@ namespace Gnomeshade.WebApi.V1.Controllers;

/// <summary>CRUD operations on loan entity.</summary>
[Obsolete]
public sealed class LoansController : TransactionItemController<LoanRepository, LoanEntity, Loan, LoanCreation>
public sealed class LoansController(Mapper mapper, LoanRepository repository, DbConnection dbConnection, TransactionRepository transactionRepository)
: TransactionItemController<LoanRepository, LoanEntity, Loan, LoanCreation>(mapper, repository, dbConnection, transactionRepository)
{
/// <summary>Initializes a new instance of the <see cref="LoansController"/> class.</summary>
/// <param name="mapper">Repository entity and API model mapper.</param>
/// <param name="repository">The repository for performing CRUD operations on <see cref="LoanEntity"/>.</param>
/// <param name="dbConnection">Database connection for transaction management.</param>
/// <param name="transactionRepository">Transaction repository for validation of transactions.</param>
public LoansController(
Mapper mapper,
LoanRepository repository,
DbConnection dbConnection,
TransactionRepository transactionRepository)
: base(mapper, repository, dbConnection, transactionRepository)
{
}

/// <summary>Gets the specified loan.</summary>
/// <param name="id">The id of the loan to get.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
Expand Down Expand Up @@ -66,12 +53,14 @@ public override Task<List<Loan>> Get(CancellationToken cancellationToken) =>
public override Task<ActionResult> Put(Guid id, [FromBody] LoanCreation loan) =>
base.Put(id, loan);

// ReSharper disable once RedundantOverriddenMember

/// <summary>Deletes the specified loan.</summary>
/// <param name="id">The id of the loan to delete.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
/// <response code="204">Loan was successfully deleted.</response>
/// <response code="404">Loan with the specified id does not exist.</response>
// ReSharper disable once RedundantOverriddenMember
/// <response code="409">Loan cannot be deleted because some other entity is still referencing it.</response>
public override Task<ActionResult> Delete(Guid id) =>
base.Delete(id);
}
24 changes: 8 additions & 16 deletions source/Gnomeshade.WebApi/V1/Controllers/OwnersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,9 @@
namespace Gnomeshade.WebApi.V1.Controllers;

/// <summary>CRUD operations on <see cref="Owner"/>.</summary>
public sealed class OwnersController : CreatableBase<OwnerRepository, OwnerEntity, Owner, OwnerCreation>
public sealed class OwnersController(Mapper mapper, OwnerRepository repository, DbConnection dbConnection)
: CreatableBase<OwnerRepository, OwnerEntity, Owner, OwnerCreation>(mapper, repository, dbConnection)
{
private readonly OwnerRepository _repository;

/// <summary>Initializes a new instance of the <see cref="OwnersController"/> class.</summary>
/// <param name="mapper">Repository entity and API model mapper.</param>
/// <param name="repository">The repository for performing CRUD operations on <see cref="OwnerEntity"/>.</param>
/// <param name="dbConnection">Database connection for transaction management.</param>
public OwnersController(Mapper mapper, OwnerRepository repository, DbConnection dbConnection)
: base(mapper, repository, dbConnection)
{
_repository = repository;
}

/// <inheritdoc cref="IOwnerClient.GetOwnersAsync"/>
/// <response code="200">Successfully got the owners.</response>
[ProducesResponseType<List<Owner>>(Status200OK)]
Expand All @@ -49,9 +38,12 @@ public override Task<List<Owner>> Get(CancellationToken cancellationToken) =>
public override Task<ActionResult> Put(Guid id, OwnerCreation owner) =>
base.Put(id, owner);

/// <inheritdoc cref="IOwnerClient.DeleteOwnerAsync"/>
/// <response code="204">The owner was deleted successfully.</response>
// ReSharper disable once RedundantOverriddenMember

/// <inheritdoc cref="IOwnerClient.DeleteOwnerAsync"/>
/// <response code="204">Owner was deleted successfully.</response>
/// <response code="404">Owner with the specified id does not exist.</response>
/// <response code="409">Owner cannot be deleted because some other entity is still referencing it.</response>
public override Task<ActionResult> Delete(Guid id) =>
base.Delete(id);

Expand All @@ -71,7 +63,7 @@ protected override async Task<ActionResult> CreateNewAsync(Guid id, OwnerCreatio
CreatedByUserId = ApplicationUser.Id,
};

await _repository.AddAsync(owner);
await Repository.AddAsync(owner);
return CreatedAtAction(nameof(Get), new { id }, id);
}
}
24 changes: 8 additions & 16 deletions source/Gnomeshade.WebApi/V1/Controllers/OwnershipsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,9 @@
namespace Gnomeshade.WebApi.V1.Controllers;

/// <summary>Resource access management.</summary>
public sealed class OwnershipsController : CreatableBase<OwnershipRepository, OwnershipEntity, Ownership, OwnershipCreation>
public sealed class OwnershipsController(Mapper mapper, OwnershipRepository repository, DbConnection dbConnection)
: CreatableBase<OwnershipRepository, OwnershipEntity, Ownership, OwnershipCreation>(mapper, repository, dbConnection)
{
private readonly OwnershipRepository _repository;

/// <summary>Initializes a new instance of the <see cref="OwnershipsController"/> class.</summary>
/// <param name="mapper">Repository entity and API model mapper.</param>
/// <param name="repository">The repository for performing CRUD operations on <see cref="OwnershipEntity"/>.</param>
/// <param name="dbConnection">Database connection for transaction management.</param>
public OwnershipsController(Mapper mapper, OwnershipRepository repository, DbConnection dbConnection)
: base(mapper, repository, dbConnection)
{
_repository = repository;
}

/// <inheritdoc cref="IOwnerClient.GetOwnershipsAsync"/>
/// <response code="200">Successfully got all ownerships.</response>
[ProducesResponseType<List<Ownership>>(Status200OK)]
Expand All @@ -48,9 +37,12 @@ public override Task<List<Ownership>> Get(CancellationToken cancellationToken) =
public override Task<ActionResult> Put(Guid id, OwnershipCreation ownership) =>
base.Put(id, ownership);

/// <inheritdoc cref="IOwnerClient.DeleteOwnershipAsync"/>
/// <response code="204">The ownership was deleted successfully.</response>
// ReSharper disable once RedundantOverriddenMember

/// <inheritdoc cref="IOwnerClient.DeleteOwnershipAsync"/>
/// <response code="204">Ownership was deleted successfully.</response>
/// <response code="404">Ownership with the specified id does not exist.</response>
/// <response code="409">Ownership cannot be deleted because some other entity is still referencing it.</response>
public override Task<ActionResult> Delete(Guid id) =>
base.Delete(id);

Expand All @@ -72,7 +64,7 @@ protected override async Task<ActionResult> UpdateExistingAsync(
protected override async Task<ActionResult> CreateNewAsync(Guid id, OwnershipCreation creation, UserEntity user)
{
var ownership = Mapper.Map<OwnershipEntity>(creation) with { Id = id };
await _repository.AddAsync(ownership);
await Repository.AddAsync(ownership);
return CreatedAtAction(nameof(Get), new { id }, id);
}
}
21 changes: 5 additions & 16 deletions source/Gnomeshade.WebApi/V1/Controllers/PurchasesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,9 @@
namespace Gnomeshade.WebApi.V1.Controllers;

/// <summary>CRUD operations on purchase entity.</summary>
public sealed class PurchasesController : TransactionItemController<PurchaseRepository, PurchaseEntity, Purchase, PurchaseCreation>
public sealed class PurchasesController(Mapper mapper, PurchaseRepository repository, DbConnection dbConnection, TransactionRepository transactionRepository)
: TransactionItemController<PurchaseRepository, PurchaseEntity, Purchase, PurchaseCreation>(mapper, repository, dbConnection, transactionRepository)
{
/// <summary>Initializes a new instance of the <see cref="PurchasesController"/> class.</summary>
/// <param name="mapper">Repository entity and API model mapper.</param>
/// <param name="repository">The repository for performing CRUD operations on <see cref="PurchaseEntity"/>.</param>
/// <param name="dbConnection">Database connection for transaction management.</param>
/// <param name="transactionRepository">Transaction repository for validation of transactions.</param>
public PurchasesController(
Mapper mapper,
PurchaseRepository repository,
DbConnection dbConnection,
TransactionRepository transactionRepository)
: base(mapper, repository, dbConnection, transactionRepository)
{
}

/// <inheritdoc cref="ITransactionClient.GetPurchaseAsync"/>
/// <response code="200">Successfully got the purchase.</response>
/// <response code="404">Purchase with the specified id does not exist.</response>
Expand All @@ -58,10 +45,12 @@ public override Task<List<Purchase>> Get(CancellationToken cancellationToken) =>
public override Task<ActionResult> Put(Guid id, [FromBody] PurchaseCreation product) =>
base.Put(id, product);

// ReSharper disable once RedundantOverriddenMember

/// <inheritdoc cref="ITransactionClient.DeletePurchaseAsync"/>
/// <response code="204">Purchase was successfully deleted.</response>
/// <response code="404">Purchase with the specified id does not exist.</response>
// ReSharper disable once RedundantOverriddenMember
/// <response code="409">Purchase cannot be deleted because some other entity is still referencing it.</response>
public override Task<ActionResult> Delete(Guid id) =>
base.Delete(id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ public override Task<ActionResult> Post([FromBody] TransactionCreation transacti
public override Task<ActionResult> Put(Guid id, [FromBody] TransactionCreation transaction) =>
base.Put(id, transaction);

// ReSharper disable once RedundantOverriddenMember

/// <inheritdoc cref="ITransactionClient.DeleteTransactionAsync"/>
/// <response code="204">Transaction was successfully deleted.</response>
/// <response code="404">Transaction with the specified id does not exist.</response>
// ReSharper disable once RedundantOverriddenMember
/// <response code="409">Transaction cannot be deleted because some other entity is still referencing it.</response>
public override Task<ActionResult> Delete(Guid id) =>
base.Delete(id);

Expand Down
21 changes: 5 additions & 16 deletions source/Gnomeshade.WebApi/V1/Controllers/TransfersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,9 @@
namespace Gnomeshade.WebApi.V1.Controllers;

/// <summary>CRUD operations on transfer entity.</summary>
public sealed class TransfersController : TransactionItemController<TransferRepository, TransferEntity, Transfer, TransferCreation>
public sealed class TransfersController(Mapper mapper, TransferRepository repository, DbConnection dbConnection, TransactionRepository transactionRepository)
: TransactionItemController<TransferRepository, TransferEntity, Transfer, TransferCreation>(mapper, repository, dbConnection, transactionRepository)
{
/// <summary>Initializes a new instance of the <see cref="TransfersController"/> class.</summary>
/// <param name="mapper">Repository entity and API model mapper.</param>
/// <param name="repository">The repository for performing CRUD operations on <see cref="TransferEntity"/>.</param>
/// <param name="dbConnection">Database connection for transaction management.</param>
/// <param name="transactionRepository">Transaction repository for validation of transactions.</param>
public TransfersController(
Mapper mapper,
TransferRepository repository,
DbConnection dbConnection,
TransactionRepository transactionRepository)
: base(mapper, repository, dbConnection, transactionRepository)
{
}

/// <inheritdoc cref="ITransactionClient.GetTransferAsync"/>
/// <response code="200">Successfully got the transfer.</response>
/// <response code="404">Transfer with the specified id does not exist.</response>
Expand All @@ -58,10 +45,12 @@ public override Task<List<Transfer>> Get(CancellationToken cancellationToken) =>
public override Task<ActionResult> Put(Guid id, [FromBody] TransferCreation product) =>
base.Put(id, product);

// ReSharper disable once RedundantOverriddenMember

/// <inheritdoc cref="ITransactionClient.DeleteTransferAsync"/>
/// <response code="204">Transfer was successfully deleted.</response>
/// <response code="404">Transfer with the specified id does not exist.</response>
// ReSharper disable once RedundantOverriddenMember
/// <response code="409">Transfer cannot be deleted because some other entity is still referencing it.</response>
public override Task<ActionResult> Delete(Guid id) =>
base.Delete(id);
}
Loading

0 comments on commit a0810b5

Please sign in to comment.