Skip to content

Commit

Permalink
Refactoring (#47)
Browse files Browse the repository at this point in the history
* upgrade packages
* change requests to record type
* fix to use docker image of specific version of postgres (16.2)
* additional refactoring (fix types, naming, unnecessary code ...)
  • Loading branch information
skrasekmichael authored Apr 25, 2024
1 parent 3fbb533 commit 20f1b07
Show file tree
Hide file tree
Showing 40 changed files with 80 additions and 86 deletions.
60 changes: 30 additions & 30 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@
<CentralPackageVersionOverrideEnabled>false</CentralPackageVersionOverrideEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Asp.Versioning.Http" Version="8.0.0" />
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.0.0" />
<PackageVersion Include="Bogus" Version="35.4.0" />
<PackageVersion Include="Asp.Versioning.Http" Version="8.1.0" />
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
<PackageVersion Include="Bogus" Version="35.5.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.30.0" />
<PackageVersion Include="FluentAssertions.Web" Version="1.2.5" />
<PackageVersion Include="FluentValidation" Version="11.9.0" />
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
<PackageVersion Include="MailKit" Version="4.4.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.31.0" />
<PackageVersion Include="FluentAssertions.Web" Version="1.3.0" />
<PackageVersion Include="FluentValidation" Version="11.9.1" />
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.1" />
<PackageVersion Include="MailKit" Version="4.5.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Identity.Stores" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Identity.Stores" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="7.4.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="7.5.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="MediatR" Version="12.2.0" />
<PackageVersion Include="NetArchTest.Rules" Version="1.3.2" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageVersion Include="Quartz" Version="3.8.1" />
<PackageVersion Include="Quartz.Extensions.Hosting" Version="3.8.1" />
<PackageVersion Include="Respawn" Version="6.2.1" />
<PackageVersion Include="Riok.Mapperly" Version="3.3.0" />
<PackageVersion Include="Skrasek.RailwayResult" Version="1.0.2" />
<PackageVersion Include="Skrasek.RailwayResult.Errors" Version="1.0.2" />
<PackageVersion Include="Skrasek.RailwayResult.FunctionalExtensions" Version="1.0.2" />
<PackageVersion Include="Riok.Mapperly" Version="3.5.1" />
<PackageVersion Include="Skrasek.RailwayResult" Version="1.1.0" />
<PackageVersion Include="Skrasek.RailwayResult.Errors" Version="1.1.0" />
<PackageVersion Include="Skrasek.RailwayResult.FunctionalExtensions" Version="1.1.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.4.0" />
<PackageVersion Include="Testcontainers" Version="3.7.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="3.7.0" />
<PackageVersion Include="xunit" Version="2.6.6" />
<PackageVersion Include="xunit.extensibility.core" Version="2.6.6" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageVersion Include="Testcontainers" Version="3.8.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="3.8.0" />
<PackageVersion Include="xunit" Version="2.7.1" />
<PackageVersion Include="xunit.extensibility.core" Version="2.7.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.8" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion scripts/rundb.ps1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker run --name ca-postgres -e POSTGRES_PASSWORD=devpass -p 5432:5432 -d postgres
docker run --name ca-postgres -e POSTGRES_PASSWORD=devpass -p 5432:5432 -d postgres:16.2
4 changes: 2 additions & 2 deletions src/TeamUp.Api/Endpoints/Events/CreateEventEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public async Task<IResult> CreateEventAsync(
ReplyClosingTimeBeforeMeetTime: request.ReplyClosingTimeBeforeMeetTime
);

var response = await sender.Send(command, ct);
return response.Match(eventId => TypedResults.Created(
var result = await sender.Send(command, ct);
return result.ToResponse(eventId => TypedResults.Created(
linkGenerator.GetPathByName(httpContext, nameof(GetEventEndpoint), new { teamId, eventId = eventId.Value }),
eventId
));
Expand Down
5 changes: 3 additions & 2 deletions src/TeamUp.Api/Endpoints/Events/GetEventEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public async Task<IResult> GetEventAsync(
TeamId.FromGuid(teamId),
EventId.FromGuid(eventId)
);
var response = await sender.Send(query, ct);
return response.Match(TypedResults.Ok);

var result = await sender.Send(query, ct);
return result.ToResponse(TypedResults.Ok);
}
}
5 changes: 3 additions & 2 deletions src/TeamUp.Api/Endpoints/Events/GetEventsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public async Task<IResult> GetEventsAsync(
TeamId.FromGuid(teamId),
fromUtc
);
var response = await sender.Send(query, ct);
return response.Match(TypedResults.Ok);

var result = await sender.Send(query, ct);
return result.ToResponse(TypedResults.Ok);
}
}
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/Events/RemoveEventEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private async Task<IResult> RemoveEventAsync(
{
var command = new RemoveEventCommand(httpContext.GetCurrentUserId(), TeamId.FromGuid(teamId), EventId.FromGuid(eventId));
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}

}
4 changes: 2 additions & 2 deletions src/TeamUp.Api/Endpoints/Events/UpsertEventReplyEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task<IResult> UpsertEventReplyAsync(
Message: request.Message
);

var response = await sender.Send(command, ct);
return response.Match(TypedResults.Ok);
var result = await sender.Send(command, ct);
return result.ToResponse(TypedResults.Ok);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ private async Task<IResult> AcceptInvitationAsync(
{
var command = new AcceptInvitationCommand(httpContext.GetCurrentUserId(), InvitationId.FromGuid(invitationId));
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ private async Task<IResult> GetTeamInvitationsAsync(
{
var query = new GetMyInvitationsQuery(httpContext.GetCurrentUserId());
var result = await sender.Send(query, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ private async Task<IResult> GetTeamInvitationsAsync(
{
var query = new GetTeamInvitationsQuery(httpContext.GetCurrentUserId(), TeamId.FromGuid(teamId));
var result = await sender.Send(query, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/Invitations/InviteUserEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private async Task<IResult> InviteUserAsync(
var command = new InviteUserCommand(httpContext.GetCurrentUserId(), request.TeamId, request.Email);

var result = await sender.Send(command, ct);
return result.Match(invitationId => TypedResults.Created(
return result.ToResponse(invitationId => TypedResults.Created(
uri: linkGenerator.GetPathByName(httpContext, nameof(GetTeamInvitationsEndpoint), request.TeamId.Value),
value: invitationId
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ private async Task<IResult> RemoveInvitationAsync(
{
var command = new RemoveInvitationCommand(httpContext.GetCurrentUserId(), InvitationId.FromGuid(invitationId));
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/Teams/ChangeNicknameEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ private async Task<IResult> ChangeNicknameAsync(
request.Nickname
);
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/Teams/ChangeOwnerShipEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ private async Task<IResult> ChangeOwnerShipAsync(
TeamMemberId.FromGuid(teamMemberId)
);
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/Teams/CreateEventTypeEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private async Task<IResult> CreateEventTypeAsync(
);

var result = await sender.Send(command, ct);
return result.Match(eventTypeId => TypedResults.Created(
return result.ToResponse(eventTypeId => TypedResults.Created(
uri: linkGenerator.GetPathByName(httpContext, nameof(GetTeamEndpoint), teamId),
value: eventTypeId
));
Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/Teams/CreateTeamEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private async Task<IResult> CreateTeamAsync(
{
var command = new CreateTeamCommand(httpContext.GetCurrentUserId(), request.Name);
var result = await sender.Send(command, ct);
return result.Match(teamId => TypedResults.Created(
return result.ToResponse(teamId => TypedResults.Created(
uri: linkGenerator.GetPathByName(httpContext, nameof(GetTeamEndpoint), teamId.Value),
value: teamId
));
Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/Teams/DeleteTeamEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ private async Task<IResult> DeleteTeamAsync(
{
var command = new DeleteTeamCommand(httpContext.GetCurrentUserId(), TeamId.FromGuid(teamId));
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/Teams/GetTeamEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ private async Task<IResult> GetTeamAsync(
{
var query = new GetTeamQuery(httpContext.GetCurrentUserId(), TeamId.FromGuid(teamId));
var result = await sender.Send(query, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/Teams/RemoveTeamMemberEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ private async Task<IResult> RemoveTeamMemberAsync(
TeamMemberId.FromGuid(teamMemberId)
);
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ private async Task<IResult> UpdateTeamRoleAsync(
request.Role
);
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/Teams/UpdateTeamNameEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ private async Task<IResult> UpdateTeamNameAsync(
request.Name
);
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ private async Task<IResult> ActivateAccountAsync(
{
var command = new ActivateAccountCommand(UserId.FromGuid(userId));
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ private async Task<IResult> DeleteUserAsync(
{
var command = new DeleteAccountCommand(httpContext.GetCurrentUserId(), password);
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ private async Task<IResult> GetAccountDetailsAsync(
{
var query = new GetAccountDetailsQuery(httpContext.GetCurrentUserId());
var result = await sender.Send(query, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
2 changes: 1 addition & 1 deletion src/TeamUp.Api/Endpoints/UserAccess/LoginUserEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ private async Task<IResult> LoginAsync(
{
var command = mapper.ToCommand(request);
var result = await sender.Send(command, ct);
return result.Match(TypedResults.Ok);
return result.ToResponse(TypedResults.Ok);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private async Task<IResult> RegisterUserAsync(
{
var command = mapper.ToCommand(request);
var result = await sender.Send(command, ct);
return result.Match(userId => TypedResults.Created(
return result.ToResponse(userId => TypedResults.Created(
uri: linkGenerator.GetPathByName(httpContext, nameof(GetMyAccountDetailsEndpoint)),
value: userId
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
using RailwayResult;
using RailwayResult.Errors;

using IResult = Microsoft.AspNetCore.Http.IResult;

namespace TeamUp.Api.Extensions;

public static class ResultExtensions
public static class ResultToResponseExtensions
{
public static IResult Match<TOut>(this Result<TOut> result, Func<TOut, IResult> success)
public static IResult ToResponse<TOut>(this Result<TOut> result, Func<TOut, IResult> success)
{
if (result.IsSuccess)
return success(result.Value!);

return result.Error.ToResponse();
}

public static IResult Match(this Result result, Func<IResult> success)
public static IResult ToResponse(this Result result, Func<IResult> success)
{
if (result.IsSuccess)
return success();
Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Contracts/Events/CreateEventRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace TeamUp.Contracts.Events;

public sealed class CreateEventRequest : IRequestBody
public sealed record CreateEventRequest : IRequestBody
{
public required EventTypeId EventTypeId { get; init; }

Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Contracts/Events/UpsertEventReplyRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace TeamUp.Contracts.Events;

public sealed class UpsertEventReplyRequest : IRequestBody
public sealed record UpsertEventReplyRequest : IRequestBody
{
public required ReplyType ReplyType { get; init; }

Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Contracts/Invitations/InviteUserRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace TeamUp.Contracts.Invitations;

public sealed class InviteUserRequest : IRequestBody
public sealed record InviteUserRequest : IRequestBody
{
public required TeamId TeamId { get; init; }

Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Contracts/Teams/ChangeNicknameRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace TeamUp.Contracts.Teams;

public sealed class ChangeNicknameRequest : IRequestBody
public sealed record ChangeNicknameRequest : IRequestBody
{
[DataType(DataType.Text)]
public required string Nickname { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Contracts/Teams/CreateTeamRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace TeamUp.Contracts.Teams;

public sealed class CreateTeamRequest : IRequestBody
public sealed record CreateTeamRequest : IRequestBody
{
[DataType(DataType.Text)]
public required string Name { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Contracts/Teams/UpdateTeamNameRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace TeamUp.Contracts.Teams;

public sealed class UpdateTeamNameRequest : IRequestBody
public sealed record UpdateTeamNameRequest : IRequestBody
{
[DataType(DataType.Text)]
public required string Name { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Contracts/Teams/UpdateTeamRoleRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace TeamUp.Contracts.Teams;

public sealed class UpdateTeamRoleRequest : IRequestBody
public sealed record UpdateTeamRoleRequest : IRequestBody
{
public required TeamRole Role { get; init; }

Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Contracts/Teams/UpsertEventTypeRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace TeamUp.Contracts.Teams;

public sealed class UpsertEventTypeRequest : IRequestBody
public sealed record UpsertEventTypeRequest : IRequestBody
{
[DataType(DataType.Text)]
public required string Name { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion src/TeamUp.Contracts/Users/LoginRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace TeamUp.Contracts.Users;

public sealed class LoginRequest : IRequestBody
public sealed record LoginRequest : IRequestBody
{
[DataType(DataType.EmailAddress)]
public required string Email { get; init; }
Expand Down
Loading

0 comments on commit 20f1b07

Please sign in to comment.