Skip to content

Commit

Permalink
Update to FunctionalDdd 1.1.0-alpha.32
Browse files Browse the repository at this point in the history
Update to FunctionalDdd 1.1.0-alpha.32
  • Loading branch information
xavierjohn authored Nov 3, 2023
1 parent 9fd6fee commit c20f6c5
Show file tree
Hide file tree
Showing 43 changed files with 151 additions and 201 deletions.
1 change: 0 additions & 1 deletion Api/src/2022-12-21/Controllers/MenusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using Asp.Versioning;
using BuberDinner.Api._2022_12_21.Models.Menus;
using FunctionalDDD.Asp;
using Mapster;
using Mediator;
using Microsoft.AspNetCore.Mvc;
Expand Down
20 changes: 10 additions & 10 deletions Api/src/2022-12-21/Models/Menus/CreateMenuRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public record CreateMenuRequest(
List<MenuSectionRequest> Sections)
{
internal Result<CreateMenuCommand> ToCreateMenuCommand(string hostId) =>
NameClass.New(this.Name)
.Combine(DescriptionClass.New(this.Description))
NameClass.TryCreate(this.Name)
.Combine(DescriptionClass.TryCreate(this.Description))
.Combine(this.GetMenuSectionCommands())
.Combine(HostId.New(hostId))
.Bind(CreateMenuCommand.New);
.Combine(HostId.TryCreate(hostId))
.Bind(CreateMenuCommand.TryCreate);

private Result<IReadOnlyList<MenuSectionCommand>> GetMenuSectionCommands() =>
this.Sections
Expand All @@ -41,10 +41,10 @@ public record MenuSectionRequest(
List<MenuItemRequest> Items)
{
internal Result<MenuSectionCommand> ToMenuSectionCommand() =>
NameClass.New(this.Name)
.Combine(DescriptionClass.New(this.Description))
NameClass.TryCreate(this.Name)
.Combine(DescriptionClass.TryCreate(this.Description))
.Combine(this.GetMenuItemCommands())
.Bind(MenuSectionCommand.New);
.Bind(MenuSectionCommand.TryCreate);

private Result<IReadOnlyList<MenuItemCommand>> GetMenuItemCommands() =>
this.Items
Expand All @@ -62,7 +62,7 @@ public record MenuItemRequest(
string Description)
{
internal Result<MenuItemCommand> ToMenuItemCommand() =>
NameClass.New(this.Name)
.Combine(DescriptionClass.New(this.Description))
.Bind(MenuItemCommand.New);
NameClass.TryCreate(this.Name)
.Combine(DescriptionClass.TryCreate(this.Description))
.Bind(MenuItemCommand.TryCreate);
}
1 change: 0 additions & 1 deletion Api/src/Neutral/Controllers/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using Asp.Versioning;
using BuberDinner.Api.Neutral.Models.Authentication;
using FunctionalDDD.Asp;
using Mapster;
using Mediator;
using Microsoft.AspNetCore.Authorization;
Expand Down
6 changes: 3 additions & 3 deletions Api/src/Neutral/Models/Authentication/LoginRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public record LoginRequest(
string Password)
{
internal Result<LoginQuery> ToLoginQuery() =>
UserIdClass.New(UserId)
.Combine(PasswordClass.New(Password))
.Bind((userId, pwd) => LoginQuery.New(userId, pwd));
UserIdClass.TryCreate(UserId)
.Combine(PasswordClass.TryCreate(Password))
.Bind((userId, pwd) => LoginQuery.TryCreate(userId, pwd));
}
13 changes: 6 additions & 7 deletions Api/src/Neutral/Models/Authentication/RegisterRequest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace BuberDinner.Api.Neutral.Models.Authentication;

using BuberDinner.Application.Services.Authentication.Commands;
using FunctionalDDD.Domain;
using FirstNameClass = Domain.User.ValueObjects.FirstName;
using LastNameClass = Domain.User.ValueObjects.LastName;
using PasswordClass = Domain.User.ValueObjects.Password;
Expand All @@ -25,11 +24,11 @@ string Password
{

internal Result<RegisterCommand> ToRegisterCommand() =>
UserIdClass.New(UserId)
.Combine(FirstNameClass.New(FirstName))
.Combine(LastNameClass.New(LastName))
.Combine(EmailAddress.New(Email))
.Combine(PasswordClass.New(Password))
.Bind(RegisterCommand.New);
UserIdClass.TryCreate(UserId)
.Combine(FirstNameClass.TryCreate(FirstName))
.Combine(LastNameClass.TryCreate(LastName))
.Combine(EmailAddress.TryCreate(Email))
.Combine(PasswordClass.TryCreate(Password))
.Bind(RegisterCommand.TryCreate);
};

35 changes: 17 additions & 18 deletions Api/tests/2022-12-21/CreateMenuRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using BuberDinner.Application.Menus.Commands;
using BuberDinner.Domain.Common.ValueObjects;
using BuberDinner.Domain.Host.ValueObject;
using FunctionalDDD.Results.Errors;

public class CreateMenuRequestTests
{
Expand Down Expand Up @@ -161,46 +160,46 @@ public void Can_create_CreateMenuCommand()
// Assert
result.IsSuccess.Should().BeTrue();
CreateMenuCommand createMenuCommand = result.Value;
createMenuCommand.Name.Should().Be(Name.New(request.Name).Value);
createMenuCommand.Description.Should().Be(Description.New(request.Description).Value);
createMenuCommand.HostId.Should().Be(HostId.New(Guid.Parse(hostId)).Value);
createMenuCommand.Name.Should().Be(Name.TryCreate(request.Name).Value);
createMenuCommand.Description.Should().Be(Description.TryCreate(request.Description).Value);
createMenuCommand.HostId.Should().Be(HostId.TryCreate(Guid.Parse(hostId)).Value);
createMenuCommand.Sections.Count.Should().Be(2);

MenuSectionRequest section0Request = request.Sections[0];
MenuSectionCommand section0Command = createMenuCommand.Sections[0];
section0Command.Name.Should().Be(Name.New(section0Request.Name).Value);
section0Command.Description.Should().Be(Description.New(section0Request.Description).Value);
section0Command.Name.Should().Be(Name.TryCreate(section0Request.Name).Value);
section0Command.Description.Should().Be(Description.TryCreate(section0Request.Description).Value);
section0Command.Items.Count.Should().Be(3);

MenuSectionRequest section1Request = request.Sections[1];
MenuSectionCommand section1Command = createMenuCommand.Sections[1];
section1Command.Name.Should().Be(Name.New(section1Request.Name).Value);
section1Command.Description.Should().Be(Description.New(section1Request.Description).Value);
section1Command.Name.Should().Be(Name.TryCreate(section1Request.Name).Value);
section1Command.Description.Should().Be(Description.TryCreate(section1Request.Description).Value);
section1Command.Items.Count.Should().Be(2);

MenuItemRequest item0_0Request = section0Request.Items[0];
MenuItemCommand item0_0Command = section0Command.Items[0];
item0_0Command.Name.Should().Be(Name.New(item0_0Request.Name).Value);
item0_0Command.Description.Should().Be(Description.New(item0_0Request.Description).Value);
item0_0Command.Name.Should().Be(Name.TryCreate(item0_0Request.Name).Value);
item0_0Command.Description.Should().Be(Description.TryCreate(item0_0Request.Description).Value);

MenuItemRequest item0_1Request = section0Request.Items[1];
MenuItemCommand item0_1Command = section0Command.Items[1];
item0_1Command.Name.Should().Be(Name.New(item0_1Request.Name).Value);
item0_1Command.Description.Should().Be(Description.New(item0_1Request.Description).Value);
item0_1Command.Name.Should().Be(Name.TryCreate(item0_1Request.Name).Value);
item0_1Command.Description.Should().Be(Description.TryCreate(item0_1Request.Description).Value);

MenuItemRequest item0_2Request = section0Request.Items[2];
MenuItemCommand item0_2Command = section0Command.Items[2];
item0_2Command.Name.Should().Be(Name.New(item0_2Request.Name).Value);
item0_2Command.Description.Should().Be(Description.New(item0_2Request.Description).Value);
item0_2Command.Name.Should().Be(Name.TryCreate(item0_2Request.Name).Value);
item0_2Command.Description.Should().Be(Description.TryCreate(item0_2Request.Description).Value);

MenuItemRequest item1_0Request = section1Request.Items[0];
MenuItemCommand item1_0Command = section1Command.Items[0];
item1_0Command.Name.Should().Be(Name.New(item1_0Request.Name).Value);
item1_0Command.Description.Should().Be(Description.New(item1_0Request.Description).Value);
item1_0Command.Name.Should().Be(Name.TryCreate(item1_0Request.Name).Value);
item1_0Command.Description.Should().Be(Description.TryCreate(item1_0Request.Description).Value);

MenuItemRequest item1_1Request = section1Request.Items[1];
MenuItemCommand item1_1Command = section1Command.Items[1];
item1_1Command.Name.Should().Be(Name.New(item1_1Request.Name).Value);
item1_1Command.Description.Should().Be(Description.New(item1_1Request.Description).Value);
item1_1Command.Name.Should().Be(Name.TryCreate(item1_1Request.Name).Value);
item1_1Command.Description.Should().Be(Description.TryCreate(item1_1Request.Description).Value);
}
}
5 changes: 2 additions & 3 deletions Api/tests/Neutral/LoginRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using BuberDinner.Api.Neutral.Models.Authentication;
using BuberDinner.Domain.User.ValueObjects;
using FunctionalDDD.Results.Errors;

public class LoginRequestTests
{
Expand Down Expand Up @@ -37,7 +36,7 @@ public void Can_create_LoginQuery()
// Assert
result.IsSuccess.Should().BeTrue();
var registerCommand = result.Value;
registerCommand.UserId.Should().Be(UserId.New("xavierjohn2023").Value);
registerCommand.Password.Should().Be(Password.New("password").Value);
registerCommand.UserId.Should().Be(UserId.TryCreate("xavierjohn2023").Value);
registerCommand.Password.Should().Be(Password.TryCreate("password").Value);
}
}
12 changes: 5 additions & 7 deletions Api/tests/Neutral/RegisterRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

using BuberDinner.Api.Neutral.Models.Authentication;
using BuberDinner.Domain.User.ValueObjects;
using FunctionalDDD.Domain;
using FunctionalDDD.Results.Errors;

public class RegisterRequestTests
{
Expand Down Expand Up @@ -64,10 +62,10 @@ public void Can_create_RegisterCommand()
// Assert
result.IsSuccess.Should().BeTrue();
var registerCommand = result.Value;
registerCommand.UserId.Should().Be(UserId.New("id").Value);
registerCommand.FirstName.Should().Be(FirstName.New("Xavier").Value);
registerCommand.LastName.Should().Be(LastName.New("John").Value);
registerCommand.Email.Should().Be(EmailAddress.New("xavier@somewhere.com").Value);
registerCommand.Password.Should().Be(Password.New("password").Value);
registerCommand.UserId.Should().Be(UserId.TryCreate("id").Value);
registerCommand.FirstName.Should().Be(FirstName.TryCreate("Xavier").Value);
registerCommand.LastName.Should().Be(LastName.TryCreate("John").Value);
registerCommand.Email.Should().Be(EmailAddress.TryCreate("xavier@somewhere.com").Value);
registerCommand.Password.Should().Be(Password.TryCreate("password").Value);
}
}
2 changes: 0 additions & 2 deletions Application/src/Abstractions/Persistence/IRepository{T}.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace BuberDinner.Application.Abstractions.Persistence;

using FunctionalDDD;

public interface IRepository<T> where T : class
{
IEnumerable<T> GetAll(CancellationToken cancellationToken);
Expand Down
3 changes: 1 addition & 2 deletions Application/src/Authentication/Commands/RegisterCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

using BuberDinner.Application.Services.Authentication.Common;
using BuberDinner.Domain.User.ValueObjects;
using FunctionalDDD.Domain;
using Mediator;

public class RegisterCommand
: IRequest<Result<AuthenticationResult>>
{
public static Result<RegisterCommand> New(UserId id, FirstName firstName, LastName lastName, EmailAddress email, Password password) =>
public static Result<RegisterCommand> TryCreate(UserId id, FirstName firstName, LastName lastName, EmailAddress email, Password password) =>
new RegisterCommand(id, firstName, lastName, email, password);

public UserId UserId { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ValueTask<Result<AuthenticationResult>> Handle(RegisterCommand request, C
});

private async ValueTask<Result<User>> CreateUser(RegisterCommand command, CancellationToken cancellationToken) =>
await User.New(command.UserId, command.FirstName, command.LastName, command.Email, command.Password)
await User.TryCreate(command.UserId, command.FirstName, command.LastName, command.Email, command.Password)
.TapAsync(user => _userRepository.Add(user, cancellationToken));

private async ValueTask<Result<string>> ValidateUserDoesNotExist(UserId id, CancellationToken cancellationToken)
Expand Down
2 changes: 1 addition & 1 deletion Application/src/Authentication/Queries/LoginQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ private LoginQuery(UserId userId, Password password)
public UserId UserId { get; }
public Password Password { get; }

public static Result<LoginQuery> New(UserId userId, Password password) =>
public static Result<LoginQuery> TryCreate(UserId userId, Password password) =>
new LoginQuery(userId, password);
}
6 changes: 3 additions & 3 deletions Application/src/Menus/Commands/CreateMenuCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class CreateMenuCommand : IRequest<Result<Menu>>
{
public static Result<CreateMenuCommand> New(
public static Result<CreateMenuCommand> TryCreate(
Name name,
Description description,
IReadOnlyList<MenuSectionCommand> sections,
Expand All @@ -34,7 +34,7 @@ private CreateMenuCommand(

public class MenuSectionCommand
{
public static Result<MenuSectionCommand> New(
public static Result<MenuSectionCommand> TryCreate(
Name name,
Description description,
IReadOnlyList<MenuItemCommand> items) =>
Expand All @@ -54,7 +54,7 @@ private MenuSectionCommand(Name name, Description description, IReadOnlyList<Men

public class MenuItemCommand
{
public static Result<MenuItemCommand> New(
public static Result<MenuItemCommand> TryCreate(
Name name,
Description description) =>
new MenuItemCommand(name, description);
Expand Down
6 changes: 3 additions & 3 deletions Application/src/Menus/Commands/CreateMenuCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public ValueTask<Result<Menu>> Handle(CreateMenuCommand request, CancellationTok
CreateMenu(request, cancellationToken);

private async ValueTask<Result<Menu>> CreateMenu(CreateMenuCommand request, CancellationToken cancellationToken) =>
await Menu.New(request.Name, request.Description, CreateMenuSections(request.Sections), request.HostId)
await Menu.TryCreate(request.Name, request.Description, CreateMenuSections(request.Sections), request.HostId)
.TapAsync(menu => _menuRepository.Add(menu, cancellationToken));

private static IReadOnlyList<MenuSection> CreateMenuSections(IReadOnlyList<MenuSectionCommand> commands) =>
commands
.Select(msc => MenuSection.New(msc.Name, msc.Description, CreateMenuItems(msc.Items)).Value)
.Select(msc => MenuSection.TryCreate(msc.Name, msc.Description, CreateMenuItems(msc.Items)).Value)
.ToList();

private static IReadOnlyList<MenuItem> CreateMenuItems(IReadOnlyList<MenuItemCommand> commands) =>
commands
.Select(mic => MenuItem.New(mic.Name, mic.Description).Value)
.Select(mic => MenuItem.TryCreate(mic.Name, mic.Description).Value)
.ToList();
}
13 changes: 6 additions & 7 deletions Application/tests/Authentication/AuthenticationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Threading.Tasks;
using BuberDinner.Application.Services.Authentication.Commands;
using BuberDinner.Domain.User.ValueObjects;
using FunctionalDDD.Domain;
using Mediator;

public class AuthenticationTests
Expand All @@ -20,12 +19,12 @@ public AuthenticationTests(ISender sender)
public async Task Can_Register_new_User()
{
// Arrange
var userId = UserId.New("xavierjohn2023").Value;
var firstName = FirstName.New("Xavier").Value;
var lastName = LastName.New("John").Value;
var email = EmailAddress.New("xavier@somewhere.com").Value;
var password = Password.New("SuperStrongPassword").Value;
var command = RegisterCommand.New(userId, firstName, lastName, email, password).Value;
var userId = UserId.TryCreate("xavierjohn2023").Value;
var firstName = FirstName.TryCreate("Xavier").Value;
var lastName = LastName.TryCreate("John").Value;
var email = EmailAddress.TryCreate("xavier@somewhere.com").Value;
var password = Password.TryCreate("SuperStrongPassword").Value;
var command = RegisterCommand.TryCreate(userId, firstName, lastName, email, password).Value;

// Act
Result<Services.Authentication.Common.AuthenticationResult> result = await _sender.Send(command);
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ItemGroup>
<InternalsVisibleTo Include="$(MSBuildProjectName).Tests" />
<PackageReference Include="Nerdbank.GitVersioning" PrivateAssets="all" />
<Using Include="FunctionalDDD.Results" />
<Using Include="FunctionalDdd" />
</ItemGroup>

<!-- Test projects. -->
Expand Down
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project>
<PropertyGroup>
<FunctionalDDDVersion>1.1.0-alpha.28</FunctionalDDDVersion>
<FunctionalDddVersion>1.1.0-alpha.32</FunctionalDddVersion>
</PropertyGroup>
<!-- Runtime -->
<ItemGroup>
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.1.0" />
<PackageVersion Include="Azure.Identity" Version="1.10.3" />
<PackageVersion Include="FluentValidation" Version="11.3.0" />
<PackageVersion Include="FunctionalDDD.Asp" Version="$(FunctionalDDDVersion)" />
<PackageVersion Include="FunctionalDDD.CommonValueObjectGenerator" Version="$(FunctionalDDDVersion)" />
<PackageVersion Include="FunctionalDDD.CommonValueObjects" Version="$(FunctionalDDDVersion)" />
<PackageVersion Include="FunctionalDDD.DomainDrivenDesign" Version="$(FunctionalDDDVersion)" />
<PackageVersion Include="FunctionalDDD.FluentValidation" Version="$(FunctionalDDDVersion)" />
<PackageVersion Include="FunctionalDDD.RailwayOrientedProgramming" Version="$(FunctionalDDDVersion)" />
<PackageVersion Include="FunctionalDdd.Asp" Version="$(FunctionalDddVersion)" />
<PackageVersion Include="FunctionalDdd.CommonValueObjectGenerator" Version="$(FunctionalDddVersion)" />
<PackageVersion Include="FunctionalDdd.CommonValueObjects" Version="$(FunctionalDddVersion)" />
<PackageVersion Include="FunctionalDdd.DomainDrivenDesign" Version="$(FunctionalDddVersion)" />
<PackageVersion Include="FunctionalDdd.FluentValidation" Version="$(FunctionalDddVersion)" />
<PackageVersion Include="FunctionalDdd.RailwayOrientedProgramming" Version="$(FunctionalDddVersion)" />
<PackageVersion Include="Mapster" Version="7.4.0" />
<PackageVersion Include="Mapster.DependencyInjection" Version="1.0.1" />
<PackageVersion Include="Mediator.Abstractions" Version="2.1.7" />
Expand Down
2 changes: 0 additions & 2 deletions Domain/src/Common/Errors/Errors.Authentication.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace BuberDinner.Domain.Errors;

using FunctionalDDD.Results.Errors;

public partial class Errors
{
public static class Authentication
Expand Down
2 changes: 0 additions & 2 deletions Domain/src/Common/Errors/Errors.User.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace BuberDinner.Domain.Errors;

using FunctionalDDD.Results.Errors;

public partial class Errors
{
public static class User
Expand Down
2 changes: 0 additions & 2 deletions Domain/src/Common/ValueObjects/Description.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace BuberDinner.Domain.Common.ValueObjects;

using FunctionalDDD.Domain;

public partial class Description : RequiredString
{
}
2 changes: 0 additions & 2 deletions Domain/src/Common/ValueObjects/Name.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace BuberDinner.Domain.Common.ValueObjects;

using FunctionalDDD.Domain;

public partial class Name : RequiredString
{
}
2 changes: 0 additions & 2 deletions Domain/src/Dinner/ValueObjects/DinnerId.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace BuberDinner.Domain.Dinner.ValueObject;

using FunctionalDDD.Domain;

public partial class DinnerId : RequiredGuid
{
}
Loading

0 comments on commit c20f6c5

Please sign in to comment.