Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/rm other projects #5

Merged
merged 9 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions Appointer.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0822B695-D2DF-4E72-BCAD-DD767655E9C4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{5E191623-BFC0-4FEC-93A9-047999771EFE}"
Expand All @@ -9,35 +12,25 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{A5781BA3-7
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{DC36BD6E-301B-4C03-970E-6869B7907B0F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web.Api", "src\Web.Api\Web.Api.csproj", "{F7E76506-B0E8-4277-9EF1-958FA786F3D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure.IntegrationTests", "tests\Infrastructure.IntegrationTests\Infrastructure.IntegrationTests.csproj", "{9514D439-B4C7-42F2-B9B9-7373C1BAAE0E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.Api", "src\Web.Api\Web.Api.csproj", "{F7E76506-B0E8-4277-9EF1-958FA786F3D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.Api.IntegrationTests", "tests\Web.Api.IntegrationTests\Web.Api.IntegrationTests.csproj", "{1F302DCD-2100-42CA-850A-570C30230FDF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "src\Domain\Domain.csproj", "{E9158132-1CA0-4B10-B1FB-ACA60605246B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web.Api.IntegrationTests", "tests\Web.Api.IntegrationTests\Web.Api.IntegrationTests.csproj", "{1F302DCD-2100-42CA-850A-570C30230FDF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{4A648E15-FEF1-47BB-99FC-26CEE2516ACB}"
ProjectSection(SolutionItems) = preProject
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.Api.UnitTests", "tests\Web.Api.UnitTests\Web.Api.UnitTests.csproj", "{CBDC7AB2-99B8-4D88-BF1A-B416E2C004FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.Api.ArchitectureTests", "tests\Web.Api.ArchitectureTests\Web.Api.ArchitectureTests.csproj", "{8C310E57-8D96-4B6A-B13A-B3AACC62F220}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DC36BD6E-301B-4C03-970E-6869B7907B0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC36BD6E-301B-4C03-970E-6869B7907B0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC36BD6E-301B-4C03-970E-6869B7907B0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC36BD6E-301B-4C03-970E-6869B7907B0F}.Release|Any CPU.Build.0 = Release|Any CPU
{9514D439-B4C7-42F2-B9B9-7373C1BAAE0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9514D439-B4C7-42F2-B9B9-7373C1BAAE0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9514D439-B4C7-42F2-B9B9-7373C1BAAE0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9514D439-B4C7-42F2-B9B9-7373C1BAAE0E}.Release|Any CPU.Build.0 = Release|Any CPU
{F7E76506-B0E8-4277-9EF1-958FA786F3D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7E76506-B0E8-4277-9EF1-958FA786F3D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7E76506-B0E8-4277-9EF1-958FA786F3D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -46,16 +39,25 @@ Global
{1F302DCD-2100-42CA-850A-570C30230FDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F302DCD-2100-42CA-850A-570C30230FDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F302DCD-2100-42CA-850A-570C30230FDF}.Release|Any CPU.Build.0 = Release|Any CPU
{E9158132-1CA0-4B10-B1FB-ACA60605246B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9158132-1CA0-4B10-B1FB-ACA60605246B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9158132-1CA0-4B10-B1FB-ACA60605246B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9158132-1CA0-4B10-B1FB-ACA60605246B}.Release|Any CPU.Build.0 = Release|Any CPU
{CBDC7AB2-99B8-4D88-BF1A-B416E2C004FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBDC7AB2-99B8-4D88-BF1A-B416E2C004FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBDC7AB2-99B8-4D88-BF1A-B416E2C004FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBDC7AB2-99B8-4D88-BF1A-B416E2C004FA}.Release|Any CPU.Build.0 = Release|Any CPU
{8C310E57-8D96-4B6A-B13A-B3AACC62F220}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C310E57-8D96-4B6A-B13A-B3AACC62F220}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C310E57-8D96-4B6A-B13A-B3AACC62F220}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C310E57-8D96-4B6A-B13A-B3AACC62F220}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DC36BD6E-301B-4C03-970E-6869B7907B0F} = {0822B695-D2DF-4E72-BCAD-DD767655E9C4}
{9514D439-B4C7-42F2-B9B9-7373C1BAAE0E} = {5E191623-BFC0-4FEC-93A9-047999771EFE}
{F7E76506-B0E8-4277-9EF1-958FA786F3D5} = {0822B695-D2DF-4E72-BCAD-DD767655E9C4}
{1F302DCD-2100-42CA-850A-570C30230FDF} = {5E191623-BFC0-4FEC-93A9-047999771EFE}
{E9158132-1CA0-4B10-B1FB-ACA60605246B} = {0822B695-D2DF-4E72-BCAD-DD767655E9C4}
{CBDC7AB2-99B8-4D88-BF1A-B416E2C004FA} = {5E191623-BFC0-4FEC-93A9-047999771EFE}
{8C310E57-8D96-4B6A-B13A-B3AACC62F220} = {5E191623-BFC0-4FEC-93A9-047999771EFE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C31453C5-23E9-43FB-A7A8-D30FBE018ACC}
EndGlobalSection
EndGlobal
3 changes: 0 additions & 3 deletions src/Domain/Accounts/UserAccount.cs

This file was deleted.

9 changes: 0 additions & 9 deletions src/Domain/Domain.csproj

This file was deleted.

20 changes: 0 additions & 20 deletions src/Infrastructure/Infrastructure.csproj

This file was deleted.

28 changes: 28 additions & 0 deletions src/Web.Api/Common/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Web.Api.Common;

public abstract class Entity
{
private readonly List<IDomainEvent> _domainEvents = new();

protected Entity(Guid id)
{
Id = id;
}
protected Entity()
{
}

public Guid Id { get; set; }
public List<IDomainEvent> DomainEvents => _domainEvents.ToList();

public void ClearDomainEvents()
{
_domainEvents.Clear();
}

protected void RaiseDomainEvent(IDomainEvent domainEvent)
{
_domainEvents.Add(domainEvent);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Web.Api.Shared;
namespace Web.Api.Common;

public record Error(string Code, string Message)
{
Expand Down
7 changes: 7 additions & 0 deletions src/Web.Api/Common/IDomainEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using MediatR;

namespace Web.Api.Common;

public interface IDomainEvent : INotification
{
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Web.Api.Shared;
namespace Web.Api.Common;

public class Result
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Web.Api.Shared;
namespace Web.Api.Common;

public class Result<TValue> : Result
{
Expand Down
34 changes: 34 additions & 0 deletions src/Web.Api/Domain/Accounts/UserAccount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Web.Api.Common;
using Web.Api.Domain.Calendars;

namespace Web.Api.Domain.Accounts;

public sealed class UserAccount : Entity
{
private UserAccount(Guid id, string fullName, bool isActive, bool isDeleted)
{
Id = id;
FullName = fullName;
IsActive = isActive;
IsDeleted = isDeleted;
}

private UserAccount()

Check warning on line 16 in src/Web.Api/Domain/Accounts/UserAccount.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'FullName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 16 in src/Web.Api/Domain/Accounts/UserAccount.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'FullName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
{
}

public Guid Id { get; private set; }

Check warning on line 20 in src/Web.Api/Domain/Accounts/UserAccount.cs

View workflow job for this annotation

GitHub Actions / build

'UserAccount.Id' hides inherited member 'Entity.Id'. Use the new keyword if hiding was intended.

Check warning on line 20 in src/Web.Api/Domain/Accounts/UserAccount.cs

View workflow job for this annotation

GitHub Actions / build

'UserAccount.Id' hides inherited member 'Entity.Id'. Use the new keyword if hiding was intended.
public string FullName { get; private set; }
public List<Calendar> Calendars { get; private set; } = new List<Calendar>();
public bool IsActive { get; private set; }
public bool IsDeleted { get; private set; }

public static UserAccount Create(string fullName)
{
var userAccount = new UserAccount(Guid.NewGuid(), fullName, true, false);

userAccount.RaiseDomainEvent(new UserAccountCreatedDomainEvent(userAccount.Id));

return userAccount;
}
}
5 changes: 5 additions & 0 deletions src/Web.Api/Domain/Accounts/UserAccountCreatedDomainEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Web.Api.Common;

namespace Web.Api.Domain.Accounts;

public sealed record UserAccountCreatedDomainEvent(Guid UserAccountId) : IDomainEvent;
31 changes: 31 additions & 0 deletions src/Web.Api/Domain/Calendars/Calendar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Web.Api.Common;
using Web.Api.Domain.Accounts;

namespace Web.Api.Domain.Calendars;

public sealed class Calendar : Entity
{
private Calendar(Guid id, string name)
{
Id = id;
Name = name;
}

private Calendar()

Check warning on line 14 in src/Web.Api/Domain/Calendars/Calendar.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in src/Web.Api/Domain/Calendars/Calendar.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
{
}

public Guid Id { get; private set; }

Check warning on line 18 in src/Web.Api/Domain/Calendars/Calendar.cs

View workflow job for this annotation

GitHub Actions / build

'Calendar.Id' hides inherited member 'Entity.Id'. Use the new keyword if hiding was intended.

Check warning on line 18 in src/Web.Api/Domain/Calendars/Calendar.cs

View workflow job for this annotation

GitHub Actions / build

'Calendar.Id' hides inherited member 'Entity.Id'. Use the new keyword if hiding was intended.
public string Name { get; private set; }
public Guid UserAccountId { get; private set; }
public UserAccount UserAccount { get; private set; } = null!;

public static Calendar Create(string fullName)
{
var calendar = new Calendar(Guid.NewGuid(), fullName);

// userAccount.RaiseDomainEvent(new UserAccountCreatedDomainEvent(userAccount.Id));

return calendar;
}
}
71 changes: 45 additions & 26 deletions src/Web.Api/Features/Accounts/CreateAccount.cs
Original file line number Diff line number Diff line change
@@ -1,51 +1,70 @@
using Carter;
using Domain.Accounts;
using Infrastructure.DbContext;
using FluentValidation;
using Mapster;
using MediatR;
using Web.Api.Shared;
using Web.Api.Common;
using Web.Api.Domain.Accounts;
using Web.Api.Infrastructure.Database;

public static class CreateAccount
namespace Web.Api.Features.Accounts;

public class CreateAccountEndpoint : ICarterModule
{
public class Command : IRequest<Result<CreateAccountResponse>>
public void AddRoutes(IEndpointRouteBuilder app)
{
public string FullName { get; set; } = string.Empty;
app.MapPost("api/accounts", async (CreateAccount.Command request, ISender sender, CancellationToken cancellationToken) =>
{
var result = await sender.Send(request, cancellationToken);

if (result.IsFailure)
{
return Results.BadRequest(result.Error);
}

return Results.Ok(result.Value);
});
}
}

public static class CreateAccount
{
public record Command(string FullName) : IRequest<Result<CreateAccountResponse>>;

public record CreateAccountResponse(Guid Id, string FullName);

internal sealed class Handler : IRequestHandler<Command, Result<CreateAccountResponse>>
public class Validator : AbstractValidator<Command>
{
public Validator()
{
RuleFor(c => c.FullName).NotEmpty();
}
}

public sealed class Handler : IRequestHandler<Command, Result<CreateAccountResponse>>
{
private readonly AppointerDbContext _dbContext;
private readonly IValidator<Command> _validator;

public Handler(AppointerDbContext dbContext)
public Handler(AppointerDbContext dbContext, IValidator<Command> validator)
{
_dbContext = dbContext;
_validator = validator;
}

public async Task<Result<CreateAccountResponse>> Handle(Command request, CancellationToken cancellationToken)
{
var userAccount = new UserAccount(Guid.NewGuid(), request.FullName);
var validationResult = await _validator.ValidateAsync(request, cancellationToken);
if (!validationResult.IsValid)
{
return Result.Failure<CreateAccountResponse>(new Error(
"CreateAccount.Validation",
validationResult.ToString()));
}

var userAccount = UserAccount.Create(request.FullName);
await _dbContext.UserAccounts.AddAsync(userAccount, cancellationToken);
await _dbContext.SaveChangesAsync(cancellationToken);
return new CreateAccountResponse(userAccount.Id, userAccount.FullName);
}
}
}

public class CreateAccountEndpoint : ICarterModule
{
public void AddRoutes(IEndpointRouteBuilder app)
{
app.MapPost("api/accounts", async (CreateAccount.Command request, ISender sender, CancellationToken cancellationToken) =>
{
var command = request.Adapt<CreateAccount.Command>();
var result = await sender.Send(command, cancellationToken);

if (result.IsFailure)
return Results.BadRequest(result.Error);

return Results.Ok(result.Value);
});
}
}
Loading
Loading